You need to sign in to do that
Don't have an account?
vishnu sundar
Get Top Record in Self Relationship
I have custom object called RoleLevel__c . Supervisor__c is self lookup in RoleLevel__c. My requirement is to get the Top record in RoleLevel__c. for Example,
I am having records as below R1->R2->R3->R4->R5->R6->R7->R7->R8->R9->R10->R11
R11(record) have Supervisor__c lookup to R10(record), R10(record) have Supervisor__c lookup to R9(record) like wise it goes
we have another field names TopRole__C which would be updated by before trigger based on the Supervisor__c it gets the next record until Supervisor__c become null ... currently we are achieving this functionality by SOQL inside while loop to get toprecord . Any possibility to get the Top record without multiple SOQL ?
Iterating something like Supervisor__r.Supervisor__r.Supervisor__r.id did not work after 5 levels. R1 , R2 names are used for example .
I am having records as below R1->R2->R3->R4->R5->R6->R7->R7->R8->R9->R10->R11
R11(record) have Supervisor__c lookup to R10(record), R10(record) have Supervisor__c lookup to R9(record) like wise it goes
we have another field names TopRole__C which would be updated by before trigger based on the Supervisor__c it gets the next record until Supervisor__c become null ... currently we are achieving this functionality by SOQL inside while loop to get toprecord . Any possibility to get the Top record without multiple SOQL ?
Iterating something like Supervisor__r.Supervisor__r.Supervisor__r.id did not work after 5 levels. R1 , R2 names are used for example .
This is the same query as posted in https://salesforce.stackexchange.com/questions/304748/get-top-record-in-self-relationship
Have you been able to try the approach mentioned in the above post. If so, please mark this answer as best so that others facing the same issue will find this information useful.
Thank you