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
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
Hi, Thanks for posting a your nice information of the article. For more information please visit.
ReplyDeleteSALES FORCE CRM Training Institutes in Ameerpet
Thanks for Nice and Informative Post on.salesforce training
ReplyDelete