0

I've seen that when a related list in a record's detail page surpasses 5 (or something) records, there is a link in the bottom that navigates to the full list of related records and nothing else.

In the instance I'm working on, I get this URL for such related list: <salesforce_url>/a0F?rlid=00N6100000HUcTH&id=a0BQ000000AwSvF

By dissecting that URL I've found that a0F is the prefix of the related object (child of the relationship). 00N6100000HUcTH is the id of the field definition in that object that relates it to its parent. And a0BQ000000AwSvF is the id of the parent itself: The record whose related list I wanna see.

How can I implement a link in a Visualforce page that gets me to this list in a way that works both in the sandbox and production? Do I have to build it manually or does Salesforce provide a shortcut? If I have to build it, does Schema.DescribeFieldResult have an Id field? Can't find documentation for that class.

1

Key prefix a0F can be achieved by this, replace OBJECT_API_NAME with your desired value.

OBJECT_API_NAME.sobjecttype.getDescribe().getKeyPrefix()

Following code will help you to getField() from relationship.

Schema.DescribeSobjectResult r = Account.SobjectType.getDescribe();
List<Schema.childRelationship> c = r.getChildRelationShips();

for(schema.childRelationship x:c){
    String name = ''+ x.getChildSObject();
    if(name.equals('Contact'))
    {   System.debug('getField=' + '' + x.getField());

    }

 }

And to get the Salesforce Id from field, refer this answer How to get the entity ID for a custom field in Apex?

Hopefully, this will help you to achieve your functionality.

| improve this answer | |
0

If you know the object name you can do it

Schema.DescribeSObjectResult r = CustomObject__c.sObjectType.getDescribe();
String keyPrefix = r.getKeyPrefix();
System.debug('Printing --'+keyPrefix );

Schema.DescribeFieldResult f = Schema.sObjectType.Custom_Object__c.fields.Custom_Field__c; System.debug(f.getRelationshipName());

and build your URL. Hope this helps.

| improve this answer | |
  • How do you get the Id of the field? Does Schema.DescribeFieldResult have a id field? You show getRelationshipName, is it the same? – Pedro Otero May 23 '17 at 21:01
  • On VF controller you should have that value. – Avijit Chakraborty May 23 '17 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.