Monday, 16 April 2018

Getting Reference FieldsI(Lookup or Master detail) through dynamic apex

Hi ,

We  had a scenario

If  we get a parameter "id" in the  url  then we should  be  able to find out    object reference is present in  the object which we are  trying  to insert then we have to make it  child record for  the object  related  to id.

For eg :

On my vf page i am trying  to insert  a contact and  i got  a parameter id related to Account

through the below code  i can find out  the  field which is  reference  to  Account  and  then fill that with parameter id to get contact inserted  under account.
The following code useful getting  reference fields  under  an object not  whole  example.

Eg: Code for  getting  reference

Map<String,Schema.SObjectField>  sobjecFieldMap = schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap();
for(String fieldName:sobjecFieldMap.keyset()){ 
    if(sobjecFieldMap.get(fieldName).getDescribe().getType()== Schema.DisplayType.REFERENCE){



  1. Thanks for sharing valuable information and it is useful for onlineitguru provides the best salesforce Online Training Bangalore

  2. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....

    Shriram Magizhchi
    Shriram Magizhchi Guduvancheri
    Shriram Magizhchi price
    Shriram Magizhchi Guduvancheri Chennai
    Shriram Magizhchi apartments
    Shriram Magizhchi flats
    Shriram Magizhchi review

  3. Hi, Thanks for posting a your nice information of the article. For more information please visit.
    SALES FORCE CRM Training Institutes in Ameerpet


Create Dynamic Picklists for Your Custom Components (design:component)

Hi, We can expose a component property as a picklist when the component is configured in the Lightning App Builder. The picklist’s value...