+ Start a Discussion

Getting ID of contact by email?



I'm farily new to the API. I am successfully inserting data into our tables, but one of the tables requires a contact, so I'm wondering how I get the ID of the contact by a provided email address?



SforceService.Storage_Work_Order__c soh = new SforceService.Storage_Work_Order__c();

soh.Order_Date__c = new DateTime(2011, 9, 12);

soh.Order_Date__c = DateTime.Today;


// Get ID of requesting customer by provided email address.


soh.Requesting_Customer__r.Id = ????



I assume I'd need to build a contact object based on the result of the email address search and pass that object to the customer_r.id field. Does anyone have an example?









Assuming your contact records have unique email addresses, you might try something like the following:


'using a binding to SforceService called "binding"

string queryString = "select Id from Contact where Email = '" + yourEmailParam + "'";
QueryResult qr = binding.query(queryString);

string contactId = '';

if(qr.size > 0)
    Contact c = (Contact)qr.records[0];
    contactId = c.Id;

soh.Requesting_Customer__c = contactId;