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
Sushil DholaniSushil Dholani 

How to update data from object which is not directly connected to where it needs to be updated

Hello Salesforce Ohana,
Opportunity is connected with Custom Object A and Custom B.
Custom Object A and Custom Object B are only related by Opportunity (Lookup).

There is one more Custom object C.
Custom Object C is only connected to Custom object B not directly connected with Opportunity or Custom object A.

What I am trying to achieve to is When Custom Object c records are created then one of its fields I need to pass to Custom object A record.

Suppose 3 Custom object C records created so there will be already Custom object A 3 records available where I need to pass value from Custom object C.

It doesn't matter Custom Object C 1st number record data gets attached to Custom object A 3rd number but opportunity needs to be the same as values are unique.

 

Any suggestions or guidance will be helpful.

Thanks in advance
User-added image

Santosh Kumar 348Santosh Kumar 348
Your requirement as per data model doen't sound in sync so I would suggest to evaluate your requirement related to object C and make necessary changes to data model. As through your description it;s not clear why you are using custon object c.
Possible solution to achieve what your requirement:
  • You can have a relationship betwenn object A and object C.
  • You can use Soql to get data from object A. Being third level child of Opportunity. You can query the Opportunity related to Object C record. Create a Map with OppId and object C record using above query.
  • Use another query to get records from object A where parent is opportunity. create another map for OppId and List of object A records.
  • Using both the map you can get the matching records now.
Please mark this as best answer if this helps.

Regards,
Santosh Kumar