You need to sign in to do that
Don't have an account?
SFDC Coder 8
Issue in Trigger while updating
Hi All,
I have two custom objects (Obj1__c & Obj2__c). I have account name as common in two objects.
I have three fields in Obj1 and Obj2.
When ever I am updating fileds in Obj1, I want to copy same information in Obj2 also.
I have written a trigger but its not copying fileds.
Here is my code
Please help where it is going wrong.
Thanks in Advance
I have two custom objects (Obj1__c & Obj2__c). I have account name as common in two objects.
I have three fields in Obj1 and Obj2.
When ever I am updating fileds in Obj1, I want to copy same information in Obj2 also.
I have written a trigger but its not copying fileds.
Here is my code
trigger updateFilds on Obj1__c (after update,before insert) { List<Id> accountIds = new List<Id>(); for(Obj1__c acc: trigger.new){ accountIds.add(acc.AccId__c); } List<Obj2__c> obj2Lst= [Select Id,F1__c ,F2__c ,F3__c,Account_Name__C FROM Obj2__c where Account_Name__C IN:accountIds]; if(Trigger.isUpdate ){ for(Obj1__c new2: trigger.new){ if(!obj2Lst.isEmpty()){ new2.F1__c = obj2Lst[0].F1__c ; new2.F2__c = obj2Lst[0].F2__c ; new2.F3__c = obj2Lst[0].F3__c ; } } } }
Please help where it is going wrong.
Thanks in Advance
where you can update obj 2 in your code after set value
try below code thanks
let me inform if it helps you
All Answers
where you can update obj 2 in your code after set value
try below code thanks
let me inform if it helps you
The solution you have inlined will work but the logic is not bulkified. I have modified your solution a bit.