0
trigger SendEmailOnDeleteCampaignMember on CampaignMember (after delete) {

    CampaignMember cmp = trigger.old[0];
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    email.setToAddresses(new String[] {cmp.Email,cmp.CampaignId.OwnerId.email});
    email.setSubject('Deleted campaign member Alert');
    email.setPlainTextBody('This message is to alert you that the campaign member named ' + cmp.LastName + ' has been deleted.');
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});   
}

I'm getting error like ownerid does not exist. Help me with this thanks in advance.

3
  • email.setToAddresses(new String[] {cmp.Email,cmp.CampaignId.OwnerId.email}); instead of CampaignId.OwnerId.email use Campaign.Owner.email
    – RCS
    Jun 4, 2018 at 12:12
  • Hi @Tushar I tried using Campaign.Owner.email but I'm getting null value instead of email address
    – user55164
    Jun 4, 2018 at 12:25
  • @user55164 Read the Note section in my answer. Jun 4, 2018 at 12:41

2 Answers 2

1

There are syntax error in your code. Instead of this cmp.CampaignId.OwnerId.email you need to do this cmp.Campaign.Owner.email to get the owner email address. You can also use cmp.Campaign.OwnerId to send the email address. As it will be counted internal email and not be counted towards limits.

Note: As you are in trigger so you can't access parent field directly. You need to first query the fields and then you can use them.

0
-1

As per the above mentioned comment try to change the CampaignId.OwnerId.email to Campaign.Owner.email

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .