You need to sign in to do that
Don't have an account?
Jagadeesh Adaveni
whenever i update record in Obj__A same record should update in objB__C
Hi All,
I am having 2 objects called ObjA__c and ObjB__c and fileds are same in both objects viz. name phone__c,email__c. So my requirement is whenever i inserted records on ObjA__C automatically same record should insert into ObjB__C for that code is
trigger AutoUpdate on MainDemo__c (Before insert, Before Update) {
List<Demo__C> dl = new List<Demo__C>();
List<Demo__C> dlu1 = new List<Demo__C>();
if(Trigger.isInsert){
for(MainDemo__C md:Trigger.new){
Demo__c d = new Demo__c();
d.name=md.name;
d.email__c=md.email__c;
d.phone__c=md.phone__c;
dl.add(d);
}
insert dl;
}
Now whenever i update record in Obj__A same record should update in objB__C but problem here is updated record is reinserting in objB__C how can i achieve this and also same for "Delete"
Thanks,
A.Jagadeesh
I am having 2 objects called ObjA__c and ObjB__c and fileds are same in both objects viz. name phone__c,email__c. So my requirement is whenever i inserted records on ObjA__C automatically same record should insert into ObjB__C for that code is
trigger AutoUpdate on MainDemo__c (Before insert, Before Update) {
List<Demo__C> dl = new List<Demo__C>();
List<Demo__C> dlu1 = new List<Demo__C>();
if(Trigger.isInsert){
for(MainDemo__C md:Trigger.new){
Demo__c d = new Demo__c();
d.name=md.name;
d.email__c=md.email__c;
d.phone__c=md.phone__c;
dl.add(d);
}
insert dl;
}
Now whenever i update record in Obj__A same record should update in objB__C but problem here is updated record is reinserting in objB__C how can i achieve this and also same for "Delete"
Thanks,
A.Jagadeesh
From there you could update or delete the demo record when the main demo record is updated or deleted.
If you go the external id route, then you could use an upsert instead of an insert to handle both inserts and updates in one swoop.
If you end up tying the demo record to the maindemo__c record using a master detail relationship, you would need to handle inserts and updates separately, but you shouldn't have to worry about deletes, because the child would be cascade deleted.
If you end up tying the demo record to the maindemo__c record with a lookup relationship, then you'll need to handle inserts, updates, and deletes separately.