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 '18 at 12:12
  • Hi @Tushar I tried using Campaign.Owner.email but I'm getting null value instead of email address – user55164 Jun 4 '18 at 12:25
  • @user55164 Read the Note section in my answer. – Tushar Sharma Jun 4 '18 at 12:41
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

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.