We do activate and deactivate CRM record more often. Sometimes, we get the requirement to do the same in the plugin/workflow/some job.
Here is the code for activating and de-activating the CRM record.
{
SetStateRequest objSetStateRequest = new SetStateRequest();
objSetStateRequest.EntityMoniker = new EntityReference(entityName, entityId);
if (!active)
{
objSetStateRequest.State = new OptionSetValue(1);
objSetStateRequest.Status = new OptionSetValue(2);
}
else
{
objSetStateRequest.State = new OptionSetValue(0);
objSetStateRequest.Status = new OptionSetValue(1);
}
SetStateResponse objSetStateResponse = (SetStateResponse)objService.Execute(objSetStateRequest);
}
Hope this helps
—
Happy CRM’ing
Gopinath