Filtering Data with S4S

There are several ways to filter the results from Salesforce.


Composite filters allow you to programmatically create a DataSource that is converted into a SOQL query with OR operators in the where clause:

var dataSource = new GenericSalesforceEntityDataSource("Attach__c", GetSalesforceSession);
var orFilter = new LogicalDisjunctionFilter();
orFilter.AddDataSourceFilter("Contact__c", ComparisonOperator.Equals, profile.ContactId);
orFilter.AddDataSourceFilter(ApexLog.Fields.Location, ComparisonOperator.Equals, "SystemLog");
// The two filters above will be combined with a logical OR
dataSource.AddDataSourceFilter(orFilter);
var attachments = dataSource.GetQueryResultsAsEntities();


Alternatively directly add a SOQL where clause to the DataSource:

var dataSource = new GenericSalesforceEntityDataSource("Attach__c", GetSalesforceSession);
dataSource.SoqlFilter = string.Format("Contact__c = '{0}' OR Location = 'SystemLog'", profile.ContactId);
var attachments = dataSource.GetQueryResultsAsEntities();


Alternatively build your own SOQL string and run that directly:

var dataSource = new GenericSalesforceEntityDataSource("Attach__c", GetSalesforceSession);
var queryResult = dataSource.RunSoqlQuery(new SoqlQuery(string.Format("Select Id from Attach__c where Contact__c = '{0}' OR Location = 'SystemLog'", profile.ContactId)));
var attachments = dataSource.EntitysFromQueryResult<GenericSalesforceEntity>(queryResult);

For more information see Searching Salesforce Records