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){
       System.debug(sobjecFieldMap.get(fieldName).getDescribe().getReferenceTo());
    }
   
}


Output:
---------
Contact
Account
User




5 comments:

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

    ReplyDelete
  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

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

    ReplyDelete

Get Record Type Id from lightning component in standard new action override (getting any url parameter)

Hi , Here we have requirement to get record type id from lightning component when standard "New" action is overrided. To get...