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
Vijaya AmarnathVijaya Amarnath 

How to query Id of a Custom LookUp or Master-Detail Filed

HI,
I want to query Id of a Custom LookUp or Master-Detail Filed. Example: "Opportunity" is the Parent object for "Project" object, and Opportunity__c is the field API in Project object now I want to query the Id of "Opportunity__c" field in "Project" object. How can I achive this. Can any body help on this. Thanks in Advance...
Deepak Kumar ShyoranDeepak Kumar Shyoran
You will get the Id of opportunity by relationship from child to parent as below code will help you in you scenario.

[Select id,Opportunity__r.Id from Project__c]

Please mark it as best solution to your problem if it does solve your problem.
Vijaya AmarnathVijaya Amarnath
@Deepak
   Thank you for ur Reply, but here I want that "Opportunity__c" Field Id not the record Id. Suppose in the Project fields if I click on "Opportunity__c" field "https://ap1.salesforce.com/00N9000000Anshl?setupid=CustomObjects" this will Come here I want to get "00N9000000Anshl" this Id in Apex.