function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ExploreForceExploreForce 

Campaign Members and Account

Hi,
I have to fetch Account.Preferred_Greeting__pc for each CampaignMamber. Please can one suggest, how to get value from Account??
 
for(CampaignMember cm : campMembers)
        {
            list<Account> lstCon=[SELECT Id,Preferred_Greeting__pc FROM Account WHERE Id=:cm.Contact.Id];
            string html = emailHTML.replace('{!cwGreeting}', this.greeting+' '+lstCon[0].Preferred_Greeting__pc+',');
            }
ShashankShashank (Salesforce Developers) 
Is the account a person account here? If not, you should add the account Id in the WHERE clause and not the contact Id.