1

Is there a way to retrieve contact information (first name, last name) and campaign member status for all members of a campaign in one SOQL query? I know you can get just the contact information with:

select id, lastname, firstname, hci_id__c 
from Contact 
where id in (
  select contactid from campaignmember where contactid='833i0000000q023')

How would I pull the status out of the campaignmember to display it with the name? I know how to do this in SQL with a join. Would this be done with a relationship query?

1 Answer 1

3

Campaign Member has a lookup relationship to Contact, so you can read fields from the Contact.

list<CampaignMember> cms = [SELECT Status,  Contact.FirstName, 
                            Contact.LastName, Contact.hci_id__c 
                            FROM CampaignMember 
                            WHERE CampaignId = :campId];

The SOQL and SOSL reference is very good: http://www.salesforce.com/us/developer/docs/soql_sosl/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.