CRM 2011 CS: Make Record Inactivate using C#


//Inactive Recordes C#
public bool InactiveRecord ( string entity, Guid id )
{
try
{
SetStateRequest req = new SetStateRequest ( );

//the entity you want to change the state of
req.EntityMoniker = new EntityReference ( entity, id );

//what should the new state be
req.State = new OptionSetValue ( ( int ) AccountState.Inactive );

//Pick an option from the status reason picklist to specify reason for state change
req.Status = new OptionSetValue ( 2 );

this.Service.Execute ( req );

return true;
}
catch ( SoapException ex )
{
return false;
}
}

//Call
InactiveRecord ( "account",new Guid( "894CC46A-B0CB-4AB0-8BF6-200544E46A2D") ) ;