5
votes

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.

2
Thanks for the answers. I also discovered salesforce.stackexchange.com where I will post my beginner-questions from now on.jan

2 Answers

4
votes

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.

3
votes

This is a great question. You're right, the error is very vague.

To begin with, read some of the documentation on default fields. Pay particular attention to the order of operations:

  1. The user chooses to create a new record.
  2. Default field value is executed.
  3. Salesforce displays the edit page with the default field value pre-populated.
  4. The user enters the fields for the new record.
  5. The user saves the new record.

Default field values are calculated before any other record data including the id are available. For this reason, they cannot be calculated based on other record fields. Especially the record id, which has not yet been assigned.

To get this functionality, you will need to create a workflow rule that fires on record creation and inserts the proper value into your field.

It would be nice if we could have formula URL fields, but we don't. EDIT: I am dumb and forgot about using HYPERLINK in text formula fields, as eyescream correctly points out.