Posts

Showing posts from February, 2024

Making an HTTP callout after rolling back DML Operations

You can now make an HTTP callout after rolling back DML operations by releasing savepoints with Database.releaseSavepoint. The introduction of the Database.releaseSavepoint method in Salesforce Apex is a significant development because traditionally, once you rolled back a transaction to a savepoint, you couldn't make any future DML operations or callouts in that transaction. This limitation poses a challenge in complex transactional scenarios where you may need to perform a callout after a conditional rollback. Here's an example of how Database.releaseSavepoint can be used: Savepoint sp = Database.setSavepoint(); try  {  // Perform DML operations  Account a = new Account(Name='Test');  insert a; // ... some logic that may fail } catch (Exception ex) {  // Exception handling if needed  Database.rollback(sp);  Database.releaseSavepoint(sp); // Also releases any savepoints created after 'sp' // Since savepoint is released, you can now make a callout Ht...

Randomly Generated Universally Unique Identifier (UUID)

Salesforce is a platform that keeps improving by introducing new features, and one such feature is the ability to generate UUIDs in Apex, which was introduced in the Spring 24 Release. With this new functionality, developers can create unique identifiers for records and objects within their Salesforce organization without needing external libraries or custom code. This feature allows developers to save time and effort while ensuring the uniqueness of identifiers UUID Class and Usage The UUID Class offers various methods to perform operations like generating a version 4 universally unique identifier (UUID), comparing UUIDs, and converting UUID instances to a string. The generation of UUID is done using a cryptographically strong pseudo-random number generator, and the UUID is represented as 32 hexadecimal values. Here's a brief overview of each method: equals(obj): Compares a UUID instance with the specified object. fromString(str): String representation of a UUID to a UUID instance...