Sunday, September 24, 2023
HomeUncategorizedLaborious Delete Information Utilizing Salesforce Circulate

Laborious Delete Information Utilizing Salesforce Circulate


Final Up to date on Could 22, 2023 by Rakesh Gupta

Massive Thought or Enduring Query:

  • Learn how to exhausting delete data from Salesforce utilizing Circulate?


After studying this weblog, you’ll be capable of:

  • Perceive @InvocableMethod Annotation
  • Study database.emptyRecycleBin methodology
  • Configure Apex motion to exhausting delete data from Circulate
  • Configure Display screen Circulate with Report Delete component
  • And rather more

What’s Laborious Delete?

Laborious delete is completely deleting the desired data from the Recycle Bin. When information is tough deleted, it’s practically unattainable to recuperate. That is normally achieved by way of Database.EmptyRecycleBin strategies.

When emptying recycle bins, take into account the next guidelines and tips:

  • After data are deleted from the Recycle Bin utilizing this name, they are often queried utilizing queryAll() for a while. Sometimes this time is 24 hours, however could also be shorter or longer.
  • As soon as data are deleted utilizing Database.EmptyRecycleBin name, it can’t be undeleted.

Warren Mason is a System Administrator at Gurukul on Cloud (GoC). At GoC they’re utilizing Salesforce Circulate to streamline Gross sales Processes. Warren has a requirement to exhausting delete leads with no e mail. He’s constructing a Display screen Circulate:

  1. Discover out all leads with no e mail
  2. Laborious delete such leads

Automation Champion Strategy (I-do):

Whereas this may be solved utilizing varied automation instruments like Apex Set off and others, we are going to use Salesforce Circulate and name an Apex methodology. To name an Apex methodology, add the Motion component to your Salesforce Circulate and choose an Apex class with a @InvocableMethod Annotation.

On this article, we are going to use the decision EmptyRecycleBin database class. With Database.EmptyRecycleBin it’s attainable to exhausting delete the data from Salesforce. EmptyRecycleBin() methodology delete data from the recycle bin instantly. As of Summer season’23 launch, it’s not attainable to instantly entry EmptyRecycleBin methodology from Circulate, that’s why we’re utilizing the Invocable apex class.

Earlier than discussing the answer, let me present you a diagram of the method at a excessive degree. Please spend a couple of minutes going by way of the next Circulate diagram to know it.

Let’s start constructing this automation course of.

Guided Observe (We-do):

There are 2 steps to resolve Warren’s enterprise requirement utilizing Display screen Circulate. We should:

  1. Create Apex class and Take a look at class to completely deletes data from the Recycle Bin.
  2. Salesforce Circulate
    1. Outline circulate properties for display screen circulate
    2. Add a Get Information component to search out all leads with no e mail deal with
    3. Add a Resolution component to test the leads discovered or not (from step 2)
    4. Add Delete Information component to delete leads
    5. Add motion – name Empty RecycleBin Invocable Apex Class

Step 1: Create an Apex class and Take a look at class

Now, we have now to know a brand new Apex annotation i.e. @InvocableMethod. This annotation allow us to use an Apex methodology as being one thing that may be referred to as from Circulate and Apex. Invocable strategies are referred to as with REST API and used to invoke a single Apex methodology. Invocable strategies have dynamic enter and output values and help describe calls.

The InvocableVariable annotation identifies a category variable used as an enter or output parameter for an InvocableMethod methodology’s invocable motion. In the event you create your personal customized class to make use of because the enter or output to an invocable methodology, you possibly can annotate particular person class member variables to make them obtainable to the strategy.

The invocable variable annotation helps the modifiers proven on this instance.

@InvocableVariable(label="variableLabel" description='variableDescription' required=(true | false))

The EmptyRecycleBin class accommodates two variables, one for deleting a single report and one other for dealing with multi-record deletion. Be happy to move the worth to at least one or each variables as wanted. Create the next class in your group.

public class EmptyRecycleBin {
    @InvocableMethod(label="Empty RecycleBin" 
                     description='Completely delete the data from the Recycle Bin.'
                     class = 'Customized Apex Actions')
    public static void execute(Listing<Requests> requestList) {
        Listing<SObject> recordstoDelete = New Listing<SObject>();
        for (Requests req: requestList) {
            if(req.obj != null){
            if(req.listofSObjects != null){
    public class Requests{
        @InvocableVariable (description ='Settle for one report of an SObject kind.' required=false)
        public SObject obj;
        @InvocableVariable (description ='Settle for a number of data of an SObject kind.' required=false)
        public Listing<SObject> listofSObjects;

Copy code from GitHub or Set up utilizing this URL

Step 2.1: Outline Circulate Properties

  1. Click on Setup.
  2. Within the Fast Discover field, kind Flows.
  3. Choose Flows then click on on the New Circulate.
  4. Choose the Display screen Circulate choice and click on on Create and configure the circulate.
  5. It can open the circulate designer for you.

Step 2.2: Including a Get Information Parts to Discover Leads With out Electronic mail

The subsequent step is utilizing the Lead object to search out the leads with out e mail deal with.

  1. On Circulate Designer, click on on the +icon and choose the Get Information component.
  2. Enter a reputation within the Label area; the API Title will auto-populate.
  3. Choose the Lead object from the dropdown checklist.
  4. Choose All Circumstances Are Met (AND)
  5. Set Filter Circumstances
    1. Row 1:
      1. Discipline: Electronic mail
      2. Operator: Equals
      3. Worth: {!$GlobalConstant.EmptyString}
  6. How Many Information to Retailer:
    1. Choose All report
  7. Learn how to Retailer Report Information:
    1. Select the choice to Routinely retailer all fields

Step 2.3: Utilizing Resolution Aspect to Examine the Report Assortment Variable (from step 2)

Now we are going to use the Resolution component to test the Report Assortment Variable from step 2 to search out if it returns the lead or not.

  1. On Circulate Designer, click on on the +icon and choose the Resolution component.
  2. Enter a reputation within the Label area; the API Title will auto-populate.
  3. Below Final result Particulars, enter the Label the API Title will auto-populate.
  4. Situation Necessities to Execute Final resultAll Circumstances Are Met (AND)
    1. Row 1:
      1. Useful resource: {!Get_Leads}
      2. Operator: Is Null 
      3. Worth: {!$GlobalConstant.False}
    2. Click on Performed.

Step 2.4: Add Motion – Delete Information to Delete Leads

The subsequent step is to delete the leads we present in Step 2.2. For this, we are going to use the Delete Information component.

  1. On Circulate Designer, beneath the Sure node, click on on the +icon and choose the Delete Information component.
  2. Enter a reputation within the Label area; the API Title will auto-populate.
  3. For Learn how to Discover Information to Delete choose Use the IDs saved in a report variable or report assortment variable.
  4. Choose the {!Get_Leads} from the dropdown checklist.
  5. Click on Performed.

Step 2.5: Including an Motion to Name Invocable Apex Class

  1. On Circulate Designer, click on on the + icon and choose the Motion component.
  2. Choose the EmptyRecycleBin Invocable Apex class.
  3. Enter a reputation within the Label field- the API Title will auto-populate.
  4. Set Enter Values:
    1. Object for “listofSObjects” (Enter): Lead
    2. Object for “obj” (Enter): Lead
  5. Retailer Enter Values
    1. listofSObjects: {!Get_Leads}
  6. Click on Performed.

Ultimately, Warren’s Circulate will appear like the next screenshot:

As soon as every little thing seems good, Save the Circulate.

Proof of Idea

  1. I’ve created 201 leads with out an e mail deal with to check the above circulate.
  2. Now Run the Display screen Circulate and watch for the circulate to finish.
  3. Return to Recycle Bin to ensure that leads had been exhausting deleted.

Formative Evaluation:

I wish 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 actual world? Be happy to share within the feedback beneath.


Source link



Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments