
I have a requirement where I have to display "Contact Name" or "User Name" based on the Id given a particular field.
For example: Here my Input field is "CreatedBy__c" and my output field is "Contact_Name__c",
Contact Id is 0030l00000IcLXE (Draco) and user Id is 0050l000000Muxz(Ajay).
If CreatedBy__c = 0030l00000IcLXE then the Contact_Name__c = Draco like wise if CreatedBy__c = 0050l000000Muxzthen the Contact_Name__c = Ajay.
Can someone help me on this
4 respostas
It boils down on running a query on the correct object, according to the ID prefix (the first 3 characters in CreatedBy__c).
If you are able to write code, the best method of achieving this would be by using a trigger. Then you check the first three characters, query either Contact or User, and copy the name of that record into Contact_Name__c.
If you can't code, you're not completely out of luck:1. Create a formula field that checks whether this is a contact or user (let's called it CreatedByType__c):
CASE(LEFT(CreatedBy__c, 3),
"003", "Contact",
"005", "User",
"Unknown")
2. Create a Flow. In the flow, check the value of CreatedByType: if it's Contact, run a Lookup step on the contact object. If it's User, run a lookup step on the user object. Copy the record name into Contact_Name__c.
3. Create a process to execute the flow any time CreatedBy__c changes.