apex

image post

How to delay an execution in Salesforce Apex

Using Schedulable interface to delay an execution in Apex
Andrés Canavesi - Jun 10, 2022
In Java, we can use Thread.sleep(1000) to delay the execution by one second. In Apex is not that easy since Salesforce is a multi-tenant environment.

image post

MIXED_DML_OPERATION error and Apex unit tests (how to fix it)

This is a common error when we start to work with testing or manipulating some particular objects: setup and non-setup objects
Andrés Canavesi - Feb 09, 2022
One option is to use @future method but since that's for running in background, we cannot query that data in the next line due to it could be created or not.

image post

Call an Apex method from Process Builder

See how to configure a Flow with process builder to execute an Apex method in Salesforce
Andrés Canavesi - Nov 11, 2021
As a thumb of rule in Salesforce you should always try to create new business logic through point-and-click but sometimes our logic it's a bit special and we need some Apex code.

image post

Get Record Type id by name in Apex - Salesforce

SOQL query to get a record type by name to use it in Apex code
Andrés Canavesi - Nov 10, 2021
Based on this query we are going to build a method that gets the record type id by its name

image post

AppFlow Salesforce: how to sync up relationships

An elegant solution to sync up relationships from Salesforce to AppFlow
Andrés Canavesi - Nov 10, 2021
Only basic types such as strings or numbers can be passed through AppFlow which means that look-up fields will be ignored. There's a way you can do it with some work from using the Salesforce out-of-the-box Process Builder tool, a custom object and some lines of Apex code.

image post

How to generate a random string in Apex

A Apex method to get a random string given a length
Andrés Canavesi - Oct 13, 2021


image post

How to create files in Salesforce for testing purposes

ContentVersion and ContentDocumentLink creation from Apex
Andrés Canavesi - May 21, 2021
Fortunately, dealing with files in Salesforce in a unit text context, is pretty easy.

image post

Detect record changes in a Lightning Component

Listen to events when a record changes outside your Lightning component
Andrés Canavesi - Apr 16, 2021
Listening to changes in a Lightning Component from record changes

image post

Salesforce - Mock callouts in Apex

How to use mockups to tests callouts in Apex
Andrés Canavesi - Feb 19, 2021
Tests callouts in Apex

image post

How to send a message to AWS SQS queue from Salesforce Apex class

Surprisingly, making a callout to put a message in AWS SQS queue is tricky in Apex
Andrés Canavesi - Jan 31, 2021
How to post a message in an AWS SQS queue from an Apex class in Salesforce

image post

Salesforce client for an Apex RESTful web service

Expose a Rest service from an Apex class using RestResource annotation
Andrés Canavesi - Aug 29, 2020
An example about how to consume a Salesforce api rest

image post

How to convert sforce.apex.execute to Lightning

Use a Lightning Component to make your JavaScript buttons work when your move to Lightning Experience
Andrés Canavesi - Jun 18, 2020
Let’s see how to convert a Salesforce JavaScript button that uses sforce.apex.execute in to Lightning Experience. The good news is you will reuse this code and the approach for all your similar buttons.

image post

Migrate $User, $Profile, $Label and $Api to Lightning Components

Rollout to Lightning by migrating non-supported JavaScript buttons
Andrés Canavesi - Jun 18, 2020
We can’t use $User, $Profile, $Label and $Api in Lightning. We need to implement a server-side solution.