Simply Say NO to Arduous-Coded ID


Final Up to date on October 19, 2022 by Rakesh Gupta

Huge Thought or Enduring Query:

  • How will you keep away from laborious coding of ID in Salesforce Move? 

Aims:

This weblog submit will assist us to know the next

  • Perceive how one can use customized Labels to keep away from laborious code of ID within the Move
  • Perceive how one can use Customized Settings to keep away from laborious code of ID within the Move
  • Perceive how one can use Customized Metadata Varieties to keep away from laborious code of ID within the Move

Donna Serdula is working as a System administrator at Gurukul On Cloud (GoC). She has acquired a requirement from the administration at any time when an account is created for Trade Not For Revenue, auto-create a case and assigns it to Nonprofit Consultants queue to confirm the group’s nonprofit standing. 

Automation Champion Method (I-do):

Sure, it’s generally a good suggestion to hard-code values (for instance, whereas studying Apex or Salesforce Move or laborious code Pie worth i.e. 3.14), however there’s no easy rule as to when; it relies upon utterly on context. When you’re laborious coding the worth of the earth’s gravitational fixed, nobody’s going to care. When you laborious code the file ID (Queue, Group or Salesforce file Id, and so on.), you’re in for bother. 

Time and time once more, I see Apex code or Flows that comprise hard-coded Ids, whether or not it’s the Description discipline, a consumer ID, or perhaps a group ID, and so on. The issue with laborious coding IDs is that any modifications have to be made to the Move itself, check once more, after which deploy to manufacturing org.

The file IDs can change, for instance between a sandbox and a manufacturing atmosphere. It may be doable {that a} queue (Nonprofit Consultants) has a unique ID in a sandbox and a manufacturing org. 

Now you may refer the Nonprofit Consultants queue id whereas making a case via Salesforce Move.

The issue with this strategy (Arduous-coding queue ID) is, In case you are growing within the Sandbox, the IDs of the newly created Queue will change while you get to Manufacturing, and it’s important to do the rework. 

–> As per Salesforce greatest observe, everybody will counsel you don’t Hardcode IDs, Query for themIt’s at all times good to comply with Salesforce greatest practices the place doable. 

So What Subsequent? Learn how to Keep away from Arduous coding of IDs in Flows? 

Among the methods to keep away from hard-coding are as follows

  1. Customized Label: – Customized labels are customized textual content values that may be accessed from Apex courses, Visualforce pages, Flows, or Lightning parts. Whereas deploying a customized label, its information additionally will get deployed. To keep away from sudden habits be sure that to replace the customized label worth post-deployment.   
  2. Customized Setting: – Customized Settings are variables that you simply use in your code however set and modify outdoors of your code. Customized settings are cached. It’s particularly helpful to retailer data that will likely be typically accessed from Apex code or Move as it can carry out higher than a customized object. It doesn’t depend in opposition to SOQL limits when fetched. The customized setting doesn’t deliver information over while you deploy them.
  3. Customized Metadata Kind: – Customized Metadata Varieties are just like Customized Settings. Whereas deploying a customized metadata kind, its information additionally will get deployed. 

Earlier than discussing the answer, let me present you a diagram of a Course of Move at a excessive stage. Please spend a couple of minutes going via the next Move diagram and understanding it. Let’s start constructing this automation course of.

Guided Apply (We-do):

There are 2 steps to unravel Donna’s enterprise requirement utilizing After-Save File-Triggered Move. We should:

  1. Create a Nonprofit Consultants Queue
  2. Salesforce Move Steps:
    1. Outline Move properties
    2. System to find out whether or not the file is created or up to date
    3. Add a call factor to verify account business
    4. Add a get file factor to search out queue Id
    5. Add a call factor to verify the queue discovered or not
    6. Add a create data factor to create a brand new case

Step 1: Making a Queue Nonprofit Consultants

  1. Click on Setup.
  2. Within the Consumer Interface, kind Queues.
  3. Click on on the New button.
  4. Enter Label the Queue Identify will auto-populate. 
  5. Click on Save.

Step 2.1: Outline Move Properties

  1. Click on Setup.
  2. Within the Fast Discover field, kind Flows.
  3. Choose Flows, then click on on the New Move.
  4. Choose the File-Triggered Move choice, click on on Create and configure the stream as follows:
    1. Object: Account
    2. Set off the Move When: A file is created or up to date
    3. Set Entry Standards
      1. Situation Necessities: None
    4. Optimize the Move For Motion and Associated Data
  5. Click on Accomplished.

Step 2.2: System to Decide Whether or not the Consumer is Created or Up to date

  1. Beneath Toolbox, choose Supervisor, then click on New Useful resource to find out whether or not the file is new or outdated.
  2. Enter the next data:
    1. Useful resource Kind: System
    2. API Identify: forB_IsNew
    3. Information Kind: Boolean
    4. System: IsNew()
  3. Click on Accomplished.

Step 2.3: Add a Choice Ingredient to Verify the Account Trade

We’ll use the Choice factor to verify whether or not the account business is Not For Revenue.

  1. On Move Designer, click on on the +icon and choose the Choice factor.
  2. Enter a reputation within the Label discipline; the API Identify will auto-populate.
  3. Beneath End result Particulars, enter the Label the API Identify will auto-populate.
  4. Situation Necessities to Execute End result: All Situations Are Met (AND)
    1. Row 1:
      1. Useful resource: {!$File.Trade}
      2. Operator:Equals
      3. Worth:Not For Revenue
    2. Click on Add Project
    3. Row 2:
      1. Useful resource: {!forB_IsNew}
      2. Operator: Equals
      3. Worth: {!$GlobalConstant.True}
  5. When to Execute End result: If the situation necessities are met.
  6. Click on Accomplished.

Step 2.4: Add a Get File Ingredient to Discover Queue Id For Nonprofit Consultants

The subsequent step is to search out the Nonprofit Consultants Queue.

  1. On Move Designer, under the Not For revenue node, click on on the +icon and choose the Get Data factor.
  2. Enter a reputation within the Label discipline; the API Identify will auto-populate.
  3. Choose the File Group object from the dropdown record.
  4. Choose All Situations Are Met (AND)
  5. Set Filter Situations
    1. Row 1:
      1. Area: Identify
      2. Operator: Equals
      3. Worth: Nonprofit Consultants
    2. Click on Add Situation
    3. Row 2:
      1. Area: Kind
      2. Operator: Equals
      3. Worth: Queue
  6. How Many Data to Retailer:
    1. Choose Solely the primary file
  7. Learn how to Retailer File Information:
    1. Select the choice to Mechanically retailer all fields
  8. Click on Accomplished.

Step 2.5: Add a Choice Ingredient to Verify the Queue from the File Variable

Now we’ll use the Choice factor to verify the File Variable from step 2.4 to search out if it returns the queue or not.

  1. On Move Designer, click on on the +icon and choose the Choice factor.
  2. Enter a reputation within the Label discipline; the API Identify will auto-populate.
  3. Beneath End result Particulars, enter the Label the API Identify will auto-populate.
  4. Situation Necessities to Execute End resultAll Situations Are Met (AND)
    1. Row 1:
      1. Useful resource: {!Get_Queue}
      2. Operator: Is Null 
      3. Worth: {!$GlobalConstant.False}
    2. Click on Accomplished.

Step 2.6: Create Data – Create a Case and Assign it to Nonprofit Queue

To create a case and assign it to Nonprofit Consultants queue, we’ll use Create Data factor. 

  1. On Move Designer, click on on the +icon and choose the Create Data factor.
  2. Enter a reputation within the Label discipline; the API Identify will auto-populate.
  3. Enter the next data:
    1. How Many Data to Create: One
    2. Learn how to Set the File Fields: Use separate sources, and literal values
    3. Object: Case
    4. Set Area Values for the Case
      1. Row 1:
        1. Area: Standing
        2. Worth: New
      2. Click on Add Area
      3. Row 2:
        1. Area: OwnerId
        2. Worth: {!Get_Queue.Id}
      4. Click on Add Area
      5. Row 3:
        1. Area: CurrencyIsoCode
        2. Worth: USD
      6. Click on Add Area
      7. Row 4:
        1. Area: Description
        2. Worth: Confirm Group’s Nonprofit Standing
      8. Click on Add Area
      9. Row 5:
        1. Area: AccountId
        2. Worth: {!$File.Id}
  4. Click on Save.


In the long run, Donna’s Move will appear to be the next screenshot:

As soon as all the things appears good, carry out the steps under: 

  1. Click on Save.
  2. Enter the Move Label the API Identify will auto-populate.
  3. Click on Present Superior.
  4. API Model for Working the Move: 56
  5. Interview Label: Don’t Arduous Code Id {!$Move.CurrentDateTime}
  6. Click on Save

Nearly there! As soon as all the things appears good, click on the Activate button.  

Proof of Idea

Now onwards, if a enterprise consumer creates an account with Trade Not For Revenue, the record-triggered stream will robotically create a brand new case. It’s time to check out the method.

  1. Navigate to the Account tab, and create a brand new account for Trade Not For Revenue, as proven within the following screenshot:New Not for Profit account
  2. As soon as accomplished, click on on the Save button. It’s going to open the account element web page and verify case associated record, as proven within the following screenshot:Proof of concept

Formative Evaluation:

I need to hear from you!

What’s one factor you discovered from this submit? How do you envision making use of this new information in the true world? Be happy to share within the feedback under.



Source link

Thanks for Reading

Enjoyed this post? Share it with your networks.

Leave a Feedback!