2

I have a custom metadata type that stores configuration information related to my Salesforce package. One piece of information I'd like to store is a link to a Salesforce user.

The field controls whether or not to fire an Apex trigger. If the Salesforce user who made the update is matches the specified Salesforce user in the metadata record, the trigger is skipped, otherwise it is fired.

enter image description here

Currently, I am storing the user's email. The limitation of this approach is that the email address is not guaranteed to match a Salesforce user at all. Is there a way of defining a field that can link to a specific Salesforce user from a custom metadata type?

2 Answers 2

1

User lookup is not yet supported in the salesforce custom metadata type!

Instead of using email you can use one of the below approaches

  1. Use username or userID. The caveat with this approach is the username and userID will change between the environments and you have to use a script to change metadata between orgs.

  2. The second approach is to define a custom field on the user object and assign a unique ID to all your users. This approach has a caveat to do some data updates in orgs.

Finally the other viable approach would be to use hierarchical custom settings that provides out of box capability to link to user.Big caveat with this approach is having to maintain this and you will need a data load to move from one system to another.

6
  • I don't see how approaches 1. username and 2. custom field are any better than using the email. 1. is potentially slightly worse than email, as you've pointed out because the user ID may change between orgs. 2. requires additional data setup and ongoing maintenance making it untenable.
    – Omair Inam
    Sep 2, 2020 at 13:20
  • Email IDs can change in future and then you have to build the list again! While userIDs generates by salesforce or a unique identifier won’t change. So an ID is always better than the emails Sep 2, 2020 at 13:22
  • Fair enough. In my particular scenario, the user email is intended to store the user email of a Salesforce user reserved exclusively for Salesforce REST API logins triggered by 3rd party integrations into Salesforce, so the email ID is guaranteed to never change..
    – Omair Inam
    Sep 2, 2020 at 13:39
  • Ok then makes sense to use email. What about custom settings of type hierarchical ? That seems to fit what you need if you just need one user emails there Sep 2, 2020 at 13:41
  • 1
    I quickly reviewed custom hierarchical settings. It looks like the intent of this was to customize settings on a per-user basis. I'm not quite sure whether the Apex API allows me to ask questions like customSettings.user <> user and how the configuration UI would differ. I'll need to play around with that to determine whether it's a better fit than regular custom settings.
    – Omair Inam
    Sep 2, 2020 at 13:45
0

For bypassing Trigger/Validation Rules/Process Builder,

Firstly we need to create the custom setting of the hierarchy type with the Bypass Trigger checkbox field. Below is the screenshot of the custom setting.

enter image description here

Create a record with the user to whom the trigger needs to be bypassed into the custom setting as shown in below screenshot.

enter image description here

Use below code into Triggers:

BypassSetting__c triggerSetting = BypassSetting__c.getInstance();
if(triggerSetting !=null && !triggerSetting.Bypass_Trigger__c){
    // Trigger Logic
}

Hope this will help you!

You must log in to answer this question.

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