Searching for Leads by Company Name

This code block retrieves multipls Lead records from the M4S cache. If no records are found and M4S is configured to read from Salesforce, then Salesforce will be searched.

GenericMongoService service = new GenericMongoService(Lead.SFType);

List<EntityBase> matchingLeads = service.GetByFieldEquals(Lead.Fields.Company.Name, "FuseIT Ltd");

foreach (EntityBase matchingLead in matchingLeads)
{
    if (!string.IsNullOrEmpty(matchingLead.Id))
    {
        Lead lead = new Lead(matchingLead);
    }
    else
    {
        //Lead has been created in the cache but is not yet synchronized.
        Lead lead = new Lead();
        lead.Any = matchingLead.Any;
    }
}