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

Reg: Look up field names


I have 2 objects E__c, Company__c.

I created a lookup on E__c which is related to Company__c.

E__c contains the fields Name(Standard), CompanyName__c (Lookup & custom field).

When i try to print the field names of E__c, it gives field names like,


Actually i have 2 fields name, Companyname__c in E__c object.

But here it shows 5 field names including ownerid,createdbyid,modifiedbyid.

Is ownerid,createdbyid,modifiedbyid are belongs to either E__c (or) Company__c object.

please reply your answer.




Best Answer chosen by Admin (Salesforce Developers) 
Devendra NataniDevendra Natani

ownerid,createdbyid,modifiedid fields are standard fields of each object in salesforce. when we create an object these fields are created by default.

If you want to fetch custom fields please see the code below.


Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
Schema.SObjectType sObjectType = gd.get('objectname');
Schema.DescribeSObjectResult r = sObjectType.getDescribe();
Map<String,Schema.SObjectField> M = r.fields.getMap();
for(String fieldName : M.keyset())
    Schema.SObjectField field = M.get(fieldName.toLowerCase());   
    Schema.DescribeFieldResult fieldDesc = field.getDescribe();
    if (fieldDesc.isCustom || fieldDesc.isNameField)
         // to do 
         // add your logic here





Please let me know if there is any issue.