Search for Lead by Last Name

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

GenericMongoService service = new GenericMongoService(Lead.SFType);

EntityBase matchingLead = service.GetSingleByFieldEquals(Lead.Fields.LastName.Name, "Smith");

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;
}