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
SARANG DESHPANDESARANG DESHPANDE 

Retrieval of standard field using sobject

I want to retrive standard filed of an object aolng with nme of its parent object.

My code is:

Line_item__c li=[select invoice_statement__r.name, line_item_number from Line_item__c limit 1];
String name=li.invoice_statement__r.name;
System.debug('Ivoice statement name for line item : '+li.line_item_number+' is :'+name);

where line_item is child object and invoice_statement is parentobject. I am trying to retieve line_item_number  which is standard field of object line_item object.

Error given is:Line: 1, Column: 17
No such column 'line_item_number' on entity 'Line_Item__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

How can we retrive stamdard fields in this fashion? Or is there is some other way?
Best Answer chosen by SARANG DESHPANDE
ManojjenaManojjena
Hi ,
Here I want to tell some thing like Custom object always have default some standard fields while creating Object .Not like custom object don't have anhy standard fields .

To know more details which all standard fields are there in custom objects .

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/system_fields.htm#topic-title


Thanks
Manoj
 

All Answers

NagaNaga (Salesforce Developers) 
Hi Sarang,

You need getSobject() to traverse relationship "up" in a dynamic way.

sObject acc = [SELECT Owner.Profile.Name FROM Account LIMIT 1]; String profileName = (String) acc.getSobject('Owner').getSobject('Profile').get('Name'); System.debug(profileName);

Best Regards
Naga Kiran
William TranWilliam Tran
There's no such thing as a standard field on a custom objects.

ALL fields on custom objects are custom fields.

Try using line_item_number__c  

if that is still not right, then go to the fields area of the custom object and find the exact api name for custom line item number.

Thx
ManojjenaManojjena
Hi SARANG DESHPANDE,
What I understood from your code is
1.Line_item__c  is one object which is the child object API name .
2.invoice_statement__c is the parent object of Line_item__c.
3.line_item_number is the field of  Line_item__c object .
Need input If I am wrong .
I f I am right then  modify your code as below

Line_item__c lineItemList=[SELECT  invoice_statements__r.Name, line_item_number__c  FROM  Line_item__c ];
Inabove query you can add parent fields invoice_statements__r.Name  in place of Name you can replace any Fields(Standrad/custom) of invoice_statement .
Let me know if it helps .

 
SARANG DESHPANDESARANG DESHPANDE
Thanks for your replies. Got it cleared. :)
 
ManojjenaManojjena
Hi ,
Here I want to tell some thing like Custom object always have default some standard fields while creating Object .Not like custom object don't have anhy standard fields .

To know more details which all standard fields are there in custom objects .

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/system_fields.htm#topic-title


Thanks
Manoj
 
This was selected as the best answer