function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Priyanka PundirPriyanka Pundir 

Using trigger, how to update record from one related list to other when both the related list point to same object.

The scenario is, I have one object called equipment whose child object is A(related list), and their is another object called Outage under which I can see the related list of object A but it is renamed as B.
Outage and Equipment share a lookup relation.

the requirement is to update the records on B when any record on related list A, is updated ,and when the equipment record is open.
I am new to Apex, please help.
sandeep sankhlasandeep sankhla
Hi Priyanka,

As per my understanding it is somthing like..

  A-->   Outage --  Equipment   <-- B

So in this case if we update the B then we can get Equipment Id and then we can get Outage also..From outage we can update it's related A..

But what if there are more than 1 A related to outage in this , do we need to update all A or specific one based on some creteria...or there will be only 1 A related to Outage..

Same Applies with B ..if there are more than one B then which B should be realted to which A..

Plese confirm the above points so I can help you out...

Thanks,
Sandeep
Priyanka PundirPriyanka Pundir
Hi Sandeep,

Thanks for the response.
Basically, When an outage is created and if there are 5 records in A which is under equipment, then those 5 records should get created under Outage in B. This functionality is implemented already.
Now, on update, if any record in A under Equipment gets updated i want that same record to get updated on B under Outage. The update should be one directional i.e from A of Equipment to B of Outage. I am not sure how to do that because A and B are same, it just that A is renamed to B under Outage( A and B are related lists). Hope it helped.

Thanks,
Priyanka
 
sandeep sankhlasandeep sankhla
Hi Priyanka,

You can create a field on B object which will simply store the ID of A when we crete the B record..this field will be hidden from page ..you can simply use this field to related which A record is related to which B record..

Please implement this and let me know if it works for you..
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 
 
Priyanka PundirPriyanka Pundir
Thanks for the quick reply.
As I said, B is not a separate object. It is A. It's just that while creating the related list of A under Outages, we renamed the list to B. So I am not sure the solution would work. Or let me know if I am wrong
sandeep sankhlasandeep sankhla
Hi Priyanka,

The solution will surely work...Because you will identifybased on outage..
when you update the A then you will find the equipment and its realted outage..then you will do query on all B records related to outage where that id field will be same of A' id field and you will get the record and then you can update that...

Also you can use recursion handler to avoid recursion..

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 
Priyanka PundirPriyanka Pundir
I am still confused. B object does not exist, how will I create a field on B.
sandeep sankhlasandeep sankhla
Hi priyanka,

I am referring B means same A object only...

see in this way

sandeep sankhla
Hi Priyanka,

The solution will surely work...Because you will identifybased on outage..
when you update the A then you will find the equipment and its realted outage..then you will do query on all A records related to outage where that id field will be same of A' id field(related to equipment) and you will get the record and then you can update that...

Also you can use recursion handler to avoid recursion..


P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer