I am new to SF and am hoping someone can help me. I have a formulae field that is being updated within a workflow rule.

The field basically does the following concatination:

a + contactid + _b + accountid.

The problem I have is that the contact id is always empty and the account number is always a constant value (1234).

So anytime I create a new contact the resulting value is always a_b1234.

The contact field is defined as unique and case insensitive. The result is that the first contact gets created with with value a-b1234, but every subsequent contact I am trying to create is rejected as a duplicate.

Is there a random contact id I can generate and use in formula field? Something like: field value = a + (generate random number) + _b + Account id

I am not looking for programmatic solution to generate the id.

Thanks in advance.

  • Welcome Spiderman, is the contactid you reference a custom field on your part? It should be possible to refer to the record's own ID and it will always be unique. If not that, then how about an autonumber field on the Contact that you use in the formula?
    – nbrown
    Commented Oct 22, 2019 at 12:51
  • Thanks @nbrown: Its a custom field. Cant change the field type now as it is already in the prod environment and im not sure what consequences it will have.
    – Spiderman
    Commented Oct 22, 2019 at 13:00
  • I have this formula that generates . random number String.valueOf(Math.random()).substring(2, 8). I am trying to use this in a workflow formula field to update a field value that is type text(255). This does not work and gives me a syntax error. How can I use a random 6 digit number/text that I can use in formula field type text? Any help highly appreciated. Thanks
    – Spiderman
    Commented Oct 22, 2019 at 17:36
  • 1
    You can't generate random numbers in formulas. You'd need to do this in a trigger.
    – sfdcfox
    Commented Oct 22, 2019 at 18:07
  • If changing field types is a concern, could you add a new autonumber field to the Contact and use it within your formula? I'm thinking a + newField + _b + accountId, if your only goal is to introduce a unique component to the formula that would accomplish it. Not sure if adding new fields to the object is a concern or not.
    – nbrown
    Commented Oct 23, 2019 at 12:01

1 Answer 1


Since all I wanted to generate was a unique value in a workflow field update, I used text(now()) to generate one. Served the purpose.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .