+ Start a Discussion
CloudGeekCloudGeek 

How to access Person Account Email field from Opportunity in an Apex trigger

Hi,

I want to implement an email program to send an email to the customer , in my company customers are created as Person Accounts.

When I use the following code , I see the null in the result .. . please help.

I used the code below:

String customerEmailID = ' ' ;

for (Opportunity opp: Trigger.new)
{
       
Opportunity oldOpp = Trigger.oldMap.get(opp.ID);

customerEmailID = opp.account.PersonEmail;   // Here When I use this way - it's getting PersonAccount Email ID - it gives NULL
       
if(opp.Status__c == 'XXXXXX' && oldOpp.Status__c == 'YYYYYY' && customerEmailID != null )
{

helper.sendEmail(customerEmailID);

}

else
{
  helper.createTask(' No Email Sent - Customer Email ID Missing');
}

Can anyone help me get this done ?

Thanks in advance.
Ramu_SFDCRamu_SFDC
This should help https://developer.salesforce.com/forums?id=906F00000008wjlIAA