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
DJ 367DJ 367 

How to query connected object

Hello All,

User-added image
I want to query a custom field from a custom object from Opportunity. there is no direct connection between opportunity and custom object however Custom object is connected with Account. Can someone please help me how to query to get the value of custom field from Opportuniy.

Gururaj BGururaj B
I dont thing there is a single query that is possilbe to join 3 objects. You can achieve with simple apex code as below:
list<opportunity> opp = [select accountid from opportunity where accountid in (select id from account) and id='xyz123456'];
list<id> Accid = new list<id>();
for(opportunity op:opp)
list<customObject> cust=[select id,testfield1__c from customObject where accountid in :accid];
Please mark as best answer if it helped you in any way

DJ 367DJ 367
Hi @Gururaj B

Thanks for reply . I want to achieve this on a custom JavaScript button in Opportunity. I dont think so list will work there. Can you please help me to achieve in javascript button.