Documentation

Looking for something in particular?

Apex Execute

This test step executes a Salesforce Apex code block as a Test Step for the defined Salesforce connection. This is useful for triggering a batch job to run immediately.

In Salesforce, Apex Execute is sometimes known as Anonymous Blocks. 

Locate the Apex Execute test step in the Test Palette and drag it into the test case:

Update the following parameters:

  • Connection Name: Choose the Salesforce connection for which the Apex code needs to be executed
  • Apex Code: Write or paste the Salesforce Apex Code block you wish to execute. Retain the syntax as per standard Salesforce Apex
  • Result Name: The string returned from Salesforce on running the Apex code
  • Result Scope: The scope of use of this output variable
  • Regular Expression: Filters the result string output based on this regular expression

Then save the Test case.

Apex Execute example

The test case in the screenshot above updates the title field on contacts in Salesforce by executing the Apex code block. Note the use of Regular Expression in the Results section to extract the result of the Apex query, which gives a Success on successfully updating the contacts. This, in turn, is asserted in Provar, and the test is failed if a Success is not received as output of the Apex code.

Sample Apex Code

List conlist = [Select Name from Contact where AccountId != null];
for(Contact con : conlist)\{
 con.title = ‘Dr’;
}
if (conlist.size()>0)\{
 update conlist;
system.debug(‘—-Success, ‘+conlist.size()+’ contact records updated—-‘);
}

Formatting

‘\’ should be added immediately before ‘{‘ whenever you run in Apex Execute, as demonstrated in lines 3 and 7 of the sample above. This is necessary because ‘{‘ in Provar is generally used to define variables.


Feedback

Was this article helpful for you?
Documentation library

Trying to raise a case with our support team?

We use cookies to better understand how our website is used so we can tailor content for you. For more information about the different cookies we use please take a look at our Privacy Policy.

Scroll to Top