You need to sign in to do that
Don't have an account?

trigger : object1 field value stored into object2
Hi,
i have create 2 object Test1 and Test2
Test1 fields : Id auto and name
Test2 fields : Id auto, Test1 Id, Test1Name and status Picklist (Yes,No)
- i want to write a triggen on Test1
- when i insert or update value in Test1 same value insert into Test2
- when i update a value in Test1 same value update on Test2.
i have create 2 object Test1 and Test2
Test1 fields : Id auto and name
Test2 fields : Id auto, Test1 Id, Test1Name and status Picklist (Yes,No)
- i want to write a triggen on Test1
- when i insert or update value in Test1 same value insert into Test2
- when i update a value in Test1 same value update on Test2.
This should helps : Maybe you'll have to deal with the fields name depending of yours.
Hope this helps,
Fred
I would do it that way :
Make the Test1Id__c field of Test2 object as external Id
then your trigger :
trigger Test1Trigger on Test1__c (after insert, after update){
List<Test2__c> test2List = new List<Test2__c>();
for(Test1__c myTest1 : trigger.new){
test2List.add(new Test2__c(IdAuto__c = mtTest1.IdAuto__c, Test1Id__c = myTest1.Id, Test1Name__c = myTest1.Name));
}
try {
upsert test2List Test1Id__c;
}
catch (DmlException e) {
System.debug(e.getMessage());
}
}
check this for upsert details
https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_dml_examples_upsert.htm
Jerome
Regards