+ Start a Discussion
Amit ChaudharyAmit Chaudhary 

Query retrieve related record on query editor but in Apex class it return Id Why ?

select name,Paper_Plan__r.name from Converted_Customer__c

this query print       paper_plan__r.name     value .

  but same query giving Id when i am writing in apex class . why   and how i can access related value in apex class .
Hargobind_SinghHargobind_Singh
This is a very common scenario, and usually works like a charm:

for(Converted_Customer__c cc : [select name,Paper_Plan__r.name from Converted_Customer__c]){
   
   System.debug(cc.Paper_Plan__r.name); 

}



However, do take care of the following:
  • Eclipse Schema tool shows ID only, if you are trying this query in Eclipse Schema Loader
  • Sometimes, when you create records without populating name, salesforce inserts the record ID in the name field. There is a chance that the Name field of object linking to Paper_Plan__c field has ID instead of actual name. So check the actual record as well.