Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the SalesForce record id in a custom field

Tags:

salesforce

I wanted to add a simple read-only URL-field to 'opportunities' in SalesForce that contains a link to an external webpage with the 15-char record id (used in the salesforce urls) attached to it . To do this I wen to /ui/setup/Setup?setupid=Opportunity --> fields and created a new field under 'Opportunity Custom Fields & Relationships'.

I chose a field with data type 'URL' and added a default value. I thought
"http://example.com/?sfid="&id would do the trick, but this returns

Error: Field id may not be used in this type of formula

This is a vague error. Is my syntax of a default value wrong, or am i using the 'id' parameter in a wrong way? And what is the right way to do this?

I'm new to SalesForce, as you probably already have guessed.

like image 546
jan Avatar asked Jan 31 '14 13:01

jan


People also ask

What is 15 digit record ID in Salesforce?

15 character ID is a case-sensitive version which is referenced in the Salesforce user interface. You can use this ID while performing data operations through the user interface. 18 character ID is the case-insensitive version which is referenced through the APIs.

What is ID and record ID in Salesforce?

Each record in the Salesforce.com system has a unique ID field assigned to it which is known as Record ID. It is system generated and cannot be edited or deleted. It is generated every time a new record is inserted into the application.


1 Answers

As the other answer stated - Id will be known only after insert meaning the "default value" trick won't work for you.

You have some other options though:

  1. Workflow rule that would be populating the URL field after save.
  2. Formula field of type text that uses HYPERLINK function

    HYPERLINK("http://example.com/?sfid=" & Id , "See " & Name & " in ext. system")
    
  3. Custom link (similar to custom buttons, they appear on the bottom of the page layout. Search them in online help)

The difference between 2 and 3 is quite minor. Custom links can appear only on the record's detail view while formula fields & other urls are well... fields - so they can be used in reports, listviews etc.

You'd have to decide which version suits you best.

like image 108
eyescream Avatar answered Nov 15 '22 07:11

eyescream