Hi Guys, Not sure what I'm doing wrong here but it keeps on saying "Input string was not in a correct format."
Guid Owner = ((EntityReference)preImage["ownerid"]).Id;
Entity User = service.Retrieve("systemuser", Owner, new ColumnSet(true));
int Max = (entity.Attributes.Contains("new_maximum") && entity["new_maximum"] != null) ? (Int32)entity["new_maximum"] : 0;
int RecordCount = GetRecordCount(service,User);
if (Max < RecordCount)
{
throw new InvalidPluginExecutionException("You cannot assign more account to this user.");
}
private int GetRecordCount(IOrganizationService service, Entity User)
{
string XML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='lead'><attribute name='fullname' /><attribute name='companyname' /><attribute name='telephone1' /><attribute name='leadid' /><order attribute='fullname' descending='false' /><filter type='and'><condition attribute='ownerid' operator='eq' value='{}' /><condition attribute='new_stage' operator='in'><value>40001</value><value>40002</value></condition><condition attribute='statecode' operator='eq' value='0' /></filter></entity></fetch>";
EntityCollection records = service.RetrieveMultiple(new FetchExpression(string.Format(XML, User.ToString())));
return records.Entities.Count;
}
please suggest