Created a page for account and one for a contact, with a "Create new Relationship" button. You select with you want to relate with a contact or an account, and based on that it creates a URL for the type of relationship needed (contact-contact, contact-account, account-contact, account-account), and it pre-populates the name of the first object. The problem is, how can i create these URLs by using salesforce variables/methods instead of hardcoding it?

For example:

  • a0a - means new relationship. How can i not hardcoded a0a to the url?
  • e?retURL - means redirect the url to this Edit page. how can i not hard code that?
  • CF00No00000020GfN- translates to the name of the first contact when creating a new relationship
  • CF00No00000020GfM - translates to the name of the first account
  • %20 - whitespace
  • %26 - & character

I know what most of these mean, but i don't want to hardcode this values, i want to be able to access this values from a salesforce variable, method, or etc.

For example:

  • URL.getSalesforceBaseUrl().toExternalForm() results in login.salesforce.com

where can i access more of these?

Part of my code below:

public PageReference newRelationshipButtonClicked(){

    String urlToGoTo = URL.getSalesforceBaseUrl().toExternalForm()+'/a0a/';

        if(secondObjectIsAccount){ //both are accounts

            String accountName = myAccount.Name.replace(' ','%20');
            accountName = accountName.replace('&', '%26');
            urlToGoTo += 'e?retURL=%2Fa0a&RecordType=012o0000000Jz9n&ent=01Io0000000Y6H1&CF00No00000020GfM='+accountName;

            } else { //im account, person i wanna have a relation to is a contact

                 String accountName = myAccount.Name.replace(' ','%20');
                 accountName = accountName.replace('&', '%26');
                 urlToGoTo += 'e?retURL=%2Fa0a&RecordType=012o0000000Jz9m&ent=01Io0000000Y6H1&CF00No00000020GfM='+accountName;


        } else { //im a contact
            if(secondObjectIsAccount){ //im a contact, other is an account
                urlToGoTo += 'e?retURL=%2Fa0a&RecordType=012o0000000Jz9l&ent=01Io0000000Y6H1&CF00No00000020GfN='+myContact.FirstName+'%20'+myContact.LastName;
                } else{ //we are both contacts
                    urlToGoTo += 'e?retURL=%2F003o0000002ITxg&CF00No00000020GfN='+myContact.FirstName+'%20'+myContact.LastName;
            PageReference newRelationshipPage = new PageReference(urlToGoTo);
             return newRelationshipPage;

4 Answers 4


I think what you might be looking for is $Action.

In short, it can be used in a VF page like so:

<apex:outputLink value="{!URLFOR($Action.Account.New)}">
    Create New Account

This link shows you a complete list of what $Action can do: https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_action_valid_values.htm

This is a link to show you how you can accomplish some dynamic routing using $action: https://www.salesforce.com/us/developer/docs/pages/Content/pages_dynamic_vf_globals_action.htm

Best of luck!



URL Class is where you have more URL params: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_url.htm

Some of the other params you have here can be saved in a static resource/ custom label and can be accessed from there if you do not want to hardcore in the code.

  • I read over that link before, as you can see I use it to do this: URL.getSalesforceBaseUrl().toExternalForm() My question is, how do i get the URL/Id for a table/field. For example, i have an custom object called Relationship_Detail__c, and i can get an Id for an specific row/relationship using this id. But i want the id for the table. E.g, Account's super id is 001, and an specific account is something like: 001o0000003MZNl. How can i acces 001 without hardcoding it?
    – user10009
    Jun 19, 2014 at 21:49

With the advent of the Tooling API, the field Ids become available to your controller; prefixes of sobjects were always available with Describe calls

Apex wrapper to REST Tooling API is here: https://github.com/afawcett/apex-toolingapi

The solution is covered in depth here: http://andyinthecloud.com/2014/01/05/querying-custom-object-and-field-ids-via-tooling-api/


You can try 'Custom Label' in Salesforce. VF page: "{!$Label.LabelName} Apex class : System.Label.LabelName

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.