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
AJ5AJ5 

trigger to update primary email with alternative email upon bounced notfication

Hello!

I'm pretty new to salesforce and I’ve been tasked with finding a way to update the records in my Lead object based on bounce reason. Specifically, If I send out an email and the message bounces, I want to trigger a workflow process that automatically updates my primary email field with my alternative email field. Reason being, I can only send out mass emails to primary email addresses. I tried taking a simpler approach by taking email and updating it using ‘Bounced Reason = “” ‘, and It didn’t work. I’ve researched and have come to the conclusion that I will have to go DEV route and use a query to access leads with bounced emails then update them that way. What I wanted to do was have this set to TRIGGER, but not sure how to go querying for each record. Any help, guidance, and a little bit of mind mapping will go a long way.

Ex.
Email: lo2222lo@xa.com email bounced        Alt Email: lolo2222@xa.com
Trigger Auto Update
Email: lolo2222@xa.com                      Alt Email: lolo2222@xa.com
Ajay LAjay L
In order to see the leads which are bounced.

Please create formula field on Lead object, that will tell you if the email is bounced or not.

 User-added image

Based on this flag you can even write a Process builder flow or Workflow rule to update the email or any other field.

Let me know if this helps.

Regards,
Ajay
AJ5AJ5
@AjayL

So I was able to get a notification that my message had bounced and use that to create the work flow rule that evaluates when I made an edit. Is there a way for me to set the workflow rule to evaluate all the records within an object? Like If I have 10 records in leads, and all the emails bounced. Can I make an edit to record 1 that activates the workflow rule to evaluate all the other records in that lead? In turn updating all the primary email addresses?

Thank you!
Ajay LAjay L
As long as your flag is set to TRUE, then when you dummy update on that record, the workflow will fire automatically and updtes the email respectively. I am sure the flasg is set to TRUE on those records, as they must have the EmailBounceDate.
AJ5AJ5
So I have gotten it to auto update the email field. But it will only do it for that one record after I make an edit. I want it to happen for all the records withought having to go an edit each one to trigger the WFR. 
Ajay LAjay L
List<Lead> leadListToUpdate = new List<Lead>();
for(Lead leadRecord : [select Id,Is_Bounced__c From Lead Where Is_Bounced__c=TRUE]) {
	
    leadListToUpdate.add(leadRecord);
}
update leadListToUpdate;

Can you run this in your Developer Console Anonymous winodw. It will dummy update the record with are Bounced. There is no other way I believe.

Regards,
Ajay