You need to sign in to do that
Don't have an account?
Rajesh Singh 88
Update existing child records (Object A) from child records (Object B)
OrderItem is the parent to Object A and Object B.
I want to update Type__c on Object A (existing records) from Object B when the Object B records get inserted with the Type__c.
I think I can leverage the OrderItem lookup on both the child objects to have a condition something like
Trigger :- afterUpdate on Object B
If(objectA.OrderItem == objectB.OrderItem){
objectA.Type__c = objectB.Type__c
list.add(objectA);
}
update list;
As I am bit new to apex not sure how to go ahead. Need some help on this.
I want to update Type__c on Object A (existing records) from Object B when the Object B records get inserted with the Type__c.
I think I can leverage the OrderItem lookup on both the child objects to have a condition something like
Trigger :- afterUpdate on Object B
If(objectA.OrderItem == objectB.OrderItem){
objectA.Type__c = objectB.Type__c
list.add(objectA);
}
update list;
As I am bit new to apex not sure how to go ahead. Need some help on this.
You can take reference from the below code:-
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
All Answers
You can take reference from the below code:-
Please mark it as Best Answer if it helps you.
Thanks & Regards
Suraj Tripathi
As you mentioned OrderItem is Parent to ObjectA and ObjectB, which in Salesforce is termed as MasterDetail Relationship where OrderItem is Master and ObjectA and ObjectB are Details. Keeping this in perspective, it means there will be multiple ObjectA and ObjectB records with one OrderItem. So trying to understand what is the relationship between ObjectA and ObjectB based on the Type.
You said when ObjectB inserted, you want to update the Type__c to ObjectA Type__c, are you saying you are going to update to all the records in ObjectA for the OrderItem. What about vice versa, if you add ObjectA with a different Type__c then ObjectB?
I think the design need some clarity based on what you are looking and the code goes accordingly.
OrderItem is having lookup relationship with both ObjectA and ObjectB.
ObjectA is already in the database with the OrderItem lookup field populated so my requirement is when ObjectB will be inserted with the Type__c field populated the data just needs to be mapped on to Type__c field of ObjectB.
No not on all the records of Object A. It be only when (objectA.OrderItem == objectB.OrderItem)
Thanks,
Rajesh