Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Sample code snippet for retrieve Salesforce campaign members of multiple Salesforce campaigns via S4S.

CampaignMemberDataSource campaignMemberDataSource = new CampaignMemberDataSource(salesforceSession);

//Generate filter to omit deleted campaign members
campaignMemberDataSource.AddDataSourceFilter(CampaignMember.Fields.IsDeleted.Name,ComparisonOperator.Equals, false);

//Generate filter to get campaign members from comma separated campaignIds 
campaignMemberDataSource.AddDataSourceFilter(CampaignMember.Fields.CampaignId.Name, Operator.OperatorFor(ComparisonOperator.In), campaignIdString.Split(','));

//Narrow down the fields to retrieve from the query
string[] requiredFields = new List<string>(new[] { "Id", "ContactId", "LeadId", "CampaignId", "Campaign.Name", "Lead.Email", "Contact.Email", "Contact.FirstName", "Contact.LastName", "Lead.FirstName", "Lead.LastName" }); 

QueryResult result = campaignMemberDataSource.RunQuery(requiredFields);

List<CampaignMember> campaignMembers = campaignMemberDataSource.EntitysFromQueryResult<CampaignMember>(result, true);

SalesforceDataSource.EntitysFromQueryResult<T>(QueryResult queryResult) now takes an optional boolean parameter returnAll (defaults to false). When false, only the records in the current query result will be converted to entities. When true, all records in the query will be added to the list. This will automatically page through all the QueryResults.

There are other ‘EntitysFromQueryResult’ methods in S4S which can use to retrieve data with paging options as follows.

//Return dataset between startIndex and endIndex
public List<T> EntitysFromQueryResultPager<T>(QueryResultPager queryResultPager, int startIndex, int endIndex);

//Return dataset according to the pageIndex and pageSize
public List<T> EntitysFromQueryResultPaged<T>(QueryResult queryResult, int pageIndex, int pageSize);


  • No labels