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
BaLab2aBaLab2a 

How can I get the standard object field Name using Apex Class??

Hi all,

 i have used the following code to retrieve StandardObjectFields however  LookUp fields are missing.. advance thanx for your Suggestions,,

 

 

 

sObject s = new Lead();
Schema.DescribeSObjectResult r = Lead.sObjectType.getDescribe();
Map<String, Schema.SObjectField> M = Schema.SObjectType.Lead.fields.getMap();
LQResults = new List<LeadQueryResults>();
    for(Schema.SObjectField sf : M.values())
    {
    LeadQueryResults myobject = new LeadQueryResults();
    myobject.isChecked = false;
    myobject.Leadname = sf.getDescribe().Label;
    LQResults.Add(myobject);
    }
}

 

 

 

Thnx.

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

These fields aren't missing, they appear as Ids.  E.g. ConvertedAccount doesn't exist but ConvertedAccountId does.  ConvertedAccount is the relationship but that doesn't actually exist on the sobject if you look at your org via the soql explorer.

 

All Answers

bob_buzzardbob_buzzard

Can you expand on what you mean by lookup fields aren't present?

 

When I execute similar code I get lookup fields back for converted opportunity id, created by id etc.

BaLab2aBaLab2a

yes,Am also getting those fileds (converted opportunity id, created by id). but the Reqt is to get the complete list of Fields(Labels) of particular Object. Ex: For Lead Obj LookUp fields Like Campaign,LeadOwner,ConvertedAccount,ConvertedContact etc are MISSING..

bob_buzzardbob_buzzard

These fields aren't missing, they appear as Ids.  E.g. ConvertedAccount doesn't exist but ConvertedAccountId does.  ConvertedAccount is the relationship but that doesn't actually exist on the sobject if you look at your org via the soql explorer.

 

This was selected as the best answer