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
Vijay NagarathinamVijay Nagarathinam 

SOQL Query for GrandParent-Parent-Child Account

Hi frnds,

I have n  number of GrandParentAccount and their related Parent Accounts and their child accounts.

AccountName        parentAccountlookupfield    RecordType
GPACC - GP1          null                                     Test1
PACC - P1               GP1                                    Test1
CACC - C1               P1                                     anything

Based on Record type(if record type is same for both parent and grandparent) I need to change the child account's parent name as GranparentName.(For C1, i need to update parent account as GP1 instead of P1)
Yoganand GadekarYoganand Gadekar
You can use relationship query to fetch all the childs of parent record in s single query. Here is an article that you may want to refer: