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?
Targets:
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:
- Discover out all leads with no e mail
- 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:
- Create Apex class and Take a look at class to completely deletes data from the Recycle Bin.
- Salesforce Circulate
- Outline circulate properties for display screen circulate
- Add a Get Information component to search out all leads with no e mail deal with
- Add a Resolution component to test the leads discovered or not (from step 2)
- Add Delete Information component to delete leads
- 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.'
iconName="slds:normal:record_delete"
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){
recordstoDelete.add(req.obj);
}
if(req.listofSObjects != null){
recordstoDelete.addAll(req.listofSObjects);
}
}
if(recordstoDelete.measurement()>0){
Database.emptyRecycleBin(recordstoDelete);
}
}
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
- Click on Setup.
- Within the Fast Discover field, kind Flows.
- Choose Flows then click on on the New Circulate.
- Choose the Display screen Circulate choice and click on on Create and configure the circulate.
- 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.
- On Circulate Designer, click on on the +icon and choose the Get Information component.
- Enter a reputation within the Label area; the API Title will auto-populate.
- Choose the Lead object from the dropdown checklist.
- Choose All Circumstances Are Met (AND).
- Set Filter Circumstances
- Row 1:
- Discipline: Electronic mail
- Operator: Equals
- Worth: {!$GlobalConstant.EmptyString}
- Row 1:
- How Many Information to Retailer:
- Choose All report
- Learn how to Retailer Report Information:
- 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.
- On Circulate Designer, click on on the +icon and choose the Resolution component.
- Enter a reputation within the Label area; the API Title will auto-populate.
- Below Final result Particulars, enter the Label the API Title will auto-populate.
- Situation Necessities to Execute Final result: All Circumstances Are Met (AND)
- Row 1:
- Useful resource: {!Get_Leads}
- Operator: Is Null
- Worth: {!$GlobalConstant.False}
- Click on Performed.
- Row 1:
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.
- On Circulate Designer, beneath the Sure node, click on on the +icon and choose the Delete Information component.
- Enter a reputation within the Label area; the API Title will auto-populate.
- For Learn how to Discover Information to Delete choose Use the IDs saved in a report variable or report assortment variable.
- Choose the {!Get_Leads} from the dropdown checklist.
- Click on Performed.
Step 2.5: Including an Motion to Name Invocable Apex Class
- On Circulate Designer, click on on the + icon and choose the Motion component.
- Choose the EmptyRecycleBin Invocable Apex class.
- Enter a reputation within the Label field- the API Title will auto-populate.
- Set Enter Values:
- Object for “listofSObjects” (Enter): Lead
- Object for “obj” (Enter): Lead
- Object for “listofSObjects” (Enter): Lead
- Retailer Enter Values
- listofSObjects: {!Get_Leads}
- listofSObjects: {!Get_Leads}
- 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
- I’ve created 201 leads with out an e mail deal with to check the above circulate.
- Now Run the Display screen Circulate and watch for the circulate to finish.
- 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.