Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


Code Block
languagec#
			[TestMethod]
public void GetByCustomFieldAndMailingCountry()
{
    SalesforceSession salesforceSession = SessionTest.GetActiveSession();
    ContactDataSource contactDataSource = new ContactDataSource(salesforceSession);

    // this could be a customer field. Uses built in field for the test case.
    string customBooleanFieldName = "IsDeleted";
    string filterCountry = "USA";

    // these will be converted into query filters in Salesforce so that only the matching rows will be returned.
    // TODO: Change the false to true when using Find_a_person__c
    contactDataSource.AddDataSourceFilter(customBooleanFieldName, ComparisonOperator.Equals, false); 
    contactDataSource.AddDataSourceFilter(Contact.Fields.MailingCountry, ComparisonOperator.Equals, filterCountry);

	// specify the exact fields you need from the Contact here and they will be returned in the query. You may or may not need to return the field that you were filtering on.
     List<Contact> matchingContacts = contactDataSource.QueryEntities<Contact>(Contact.Fields.Id, Contact.Fields.MailingCountry, Contact.Fields.Account(Account.Fields.Id, Account.Fields.Name, Account.Fields.Website), new SObjectField() { Name = customBooleanFieldName });

	Assert.AreNotEqual(0, matchingContacts.Count);
    foreach (Contact contact in matchingContacts)
    {
    	// confirm that the customFieldName filter was applied
        Assert.IsFalse(contact.InternalFields.GetField<bool>(customBooleanFieldName));
    
		// confirm that the mailing country filter was applied
        Assert.AreEqual(filterCountry, contact.MailingCountry);

        Account accountForContact = contact.Account;
        Assert.IsNotNull(accountForContact);

        string accountName = accountForContact.Name;
        Assert.IsNotNull(accountName);
	}
}

For more information see Filtering Data with S4S