• Ryan Thomas
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
I am looking to perform a check for uniqueness on task records.  In my scenario, uniqueness is defined by a combination of:
  • User ID (CreatedBy)
  • Date (ActivityDate)
  • Task type (custom picklist)
For example:
User ID:       005U0000004qTC1
Date:           2015-08-08
Task Type:  Visit
Concatenated Text:  005U0000004qTC12015-08-08Visit

Since Salesforce doesn't offer uniqueness checks on formula fields, I cannot use a formula field even though it concatenates effectively.

What I'd like to do is create a JavaScript event (OnChange event of the task type or activity date) to populate a custom text field with a concatenation of those three values, so that upon saving of the record, the native uniqueness check on a text field can look for duplicates.

I'm not looking for someone to spoon feed me the code.  I just want to know if it's feasible.
I am looking to perform a check for uniqueness on task records.  In my scenario, uniqueness is defined by a combination of:
  • User ID (CreatedBy)
  • Date (ActivityDate)
  • Task type (custom picklist)
For example:
User ID:       005U0000004qTC1
Date:           2015-08-08
Task Type:  Visit
Concatenated Text:  005U0000004qTC12015-08-08Visit

Since Salesforce doesn't offer uniqueness checks on formula fields, I cannot use a formula field even though it concatenates effectively.

What I'd like to do is create a JavaScript event (OnChange event of the task type or activity date) to populate a custom text field with a concatenation of those three values, so that upon saving of the record, the native uniqueness check on a text field can look for duplicates.

I'm not looking for someone to spoon feed me the code.  I just want to know if it's feasible.

This seems like a silly question, but I have not been able to find the answer.  How do I get the username from the lastmodifiedbyid on custom objects?  I've queried the user object, but it does not understand the relationship with 'user'.

 

Simply put the following formula into a formula field of type "Text":

 

Id
& MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
    IF(FIND(MID(Id,1,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0)
    +IF(FIND(MID(Id,2,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0)
    +IF(FIND(MID(Id,3,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0)
    +IF(FIND(MID(Id,4,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0)
    +IF(FIND(MID(Id,5,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0)
    )+1,1)
& MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
    IF(FIND(MID(Id,6,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0)
    +IF(FIND(MID(Id,7,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0)
    +IF(FIND(MID(Id,8,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0)
    +IF(FIND(MID(Id,9,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0)
    +IF(FIND(MID(Id,10,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0)
    )+1,1)
& MID("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345",(
    IF(FIND(MID(Id,11,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,1,0)
    +IF(FIND(MID(Id,12,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,2,0)
    +IF(FIND(MID(Id,13,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,4,0)
    +IF(FIND(MID(Id,14,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,8,0)
    +IF(FIND(MID(Id,15,1), "ABCDEFGHIJKLMNOPQRSTUVWXYZ")>0,16,0)
    )+1,1)

 

This is an optimized version of the code example "BPS: 18 digit external ID within the UI" you can find on the Online Help, but unlike the example provided there, it is small enough to fit into a formula field. Also, this code doesn't contain the error found in the online help example, where the second character byte equivalent of the first 5-character chunk was "4" instead of "2". I'd be more than happy if someone could come up with an even shorter version of this formula...Still, I hope you can use this.

 

Cheers,

Erik Mittmeyer

Does anyone know how to get Web-to-Case to work with a lookup field?


Thanks,

Jon