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
Suhaas Kapardhi B SSuhaas Kapardhi B S 

Can you help me with the solution using a simple trigger? I have bulkyfied trigger

I have an account with associated opportunities. When I update an opportunity's email address, it will check the associated Account and retrieve the related opportunities to see if all of the opportunities email addresses are the same as the updated email address. If so, it will not update the email address on the opportunity record; otherwise, it will update the email address with the updated email address.
I have an account with associated opportunities. When I update an opportunity's email address, it will check the associated Account and retrieve the related opportunities to see if all of the opportunities email addresses are the same as the updated email address. If so, it will not update the email address on the opportunity record; otherwise, it will update the email address with the updated email address.


Thanks 
Suhaas

 
Best Answer chosen by Suhaas Kapardhi B S
AnkaiahAnkaiah (Salesforce Developers) 
Hi Suhaas,

Try with below code.
trigger insertcontactCases on Opportunity (after update) {
    
    List<Opportunity> opplistupdate=new List<Opportunity>();
	Map<Id,string> mapaccidwithemail = new map<Id,string>();

    for(Opportunity opp : Trigger.New) {	
	If(opp.AccountId=!Null & opp.email__c!=trigger.oldmap.get(opp.id).email__c){
	mapaccidwithemail.put(opp.AccountId,opp.email__c);
	}
}

for(opportunity opp: [select id,email__c,AccountId from opportunity where AccountId=:mapaccidwithemail.keyset() AND email__c!=:mapaccidwithemail.values()]){

if(mapaccidwithemail.containskey(opp.AccountId)){
opp.email__c = mapaccidwithemail.get(opp.AccountId);
opplistupdate.add(opp);
}
}
update opplistupdate;

}

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi Suhaas,

Try with below code.
trigger insertcontactCases on Opportunity (after update) {
    
    List<Opportunity> opplistupdate=new List<Opportunity>();
	Map<Id,string> mapaccidwithemail = new map<Id,string>();

    for(Opportunity opp : Trigger.New) {	
	If(opp.AccountId=!Null & opp.email__c!=trigger.oldmap.get(opp.id).email__c){
	mapaccidwithemail.put(opp.AccountId,opp.email__c);
	}
}

for(opportunity opp: [select id,email__c,AccountId from opportunity where AccountId=:mapaccidwithemail.keyset() AND email__c!=:mapaccidwithemail.values()]){

if(mapaccidwithemail.containskey(opp.AccountId)){
opp.email__c = mapaccidwithemail.get(opp.AccountId);
opplistupdate.add(opp);
}
}
update opplistupdate;

}

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​
This was selected as the best answer
Suhaas Kapardhi B SSuhaas Kapardhi B S
@Ankaiah Thanks it worked :)