You need to sign in to do that
Don't have an account?
MUSFAR KT 6
Write a trigger to update a field (city) in opportunity when same field(city) is updated in account
trigger Update_city_Acc on Account (after update) {
set<id> ids=new set<id>();
for(account a :trigger.new){
if(a.city__c!=trigger.oldmap.get(a.id).city__c){
ids.add(a.id);
}
}
List<opportunity>opp=[select id,City__c,Accountid from opportunity where accountid IN:ids];
for(opportunity op:opp){
op.City__c=trigger.newmap.get(op.accountid).city__c;
}
}
unit test time its not working.
set<id> ids=new set<id>();
for(account a :trigger.new){
if(a.city__c!=trigger.oldmap.get(a.id).city__c){
ids.add(a.id);
}
}
List<opportunity>opp=[select id,City__c,Accountid from opportunity where accountid IN:ids];
for(opportunity op:opp){
op.City__c=trigger.newmap.get(op.accountid).city__c;
}
}
unit test time its not working.
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas