Skip to content

Instantly share code, notes, and snippets.

@furkankaracan
Created January 3, 2023 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save furkankaracan/dd3f35964657514f8f2301d63ad6b28e to your computer and use it in GitHub Desktop.
Save furkankaracan/dd3f35964657514f8f2301d63ad6b28e to your computer and use it in GitHub Desktop.
private static List<Entity> GetAccounts()
{
string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
<entity name='account'>
<attribute name='accountnumber' />
<attribute name='accountid' />
<attribute name='modifiedon' />
<order attribute='modifiedon' descending='true' />
<order attribute='name' descending='false' />
</entity>
</fetch>";
return orgService.RetrieveAll(new FetchExpression(fetchXml));
}
public static List<Entity> RetrieveAll(this IOrganizationService service, FetchExpression query)
{
var conversionRequest = new FetchXmlToQueryExpressionRequest
{
FetchXml = query.Query
};
var conversionResponse =
(FetchXmlToQueryExpressionResponse)service.Execute(conversionRequest);
return RetrieveAll(service, conversionResponse.Query);
}
public static List<Entity> RetrieveAll(this IOrganizationService service, QueryExpression query)
{
var result = new List<Entity>();
var entities = service.RetrieveMultiple(query);
result.AddRange(entities.Entities);
var page = 2;
while (entities.MoreRecords)
{
query.PageInfo = new PagingInfo
{
PagingCookie = entities.PagingCookie,
PageNumber = page
};
entities = service.RetrieveMultiple(query);
result.AddRange(entities.Entities);
page++;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment