Posts

Showing posts from 2021

What is Transaction Finalizers ?

Transaction Finalizers in Salesforce Apex are a feature that provides developers with a mechanism to execute logic after a transaction is completed, regardless of whether it's successful or encounters unhandled exceptions. This is particularly useful in the context of Asynchronous Apex, such as future methods, batch jobs, and queueable Apex. You can specify a piece of Apex code to run after the asynchronous operation with transaction finalizers. This flexibility allows you to adapt to various scenarios, benefiting resource cleanup, logging, notifications, or other post-processing operations, giving you a sense of control over your code execution. To use a transaction finalizer, you need to implement the Database. Finalizer interface in your Apex class. The execute method in this interface is invoked after the transaction that the asynchronous code is part of either successfully commits or is rolled back due to an exception Transaction finalizers allow you to attach a post-action s...

Salesforce Platform Event

Image
Platform Events provide a way to deliver secure, scalable, and customizable event notifications within and outside of the Salesforce platform. Platform Events are based on the publish-subscribe model, allowing publishers to broadcast events and subscribers to receive and process those events in real time. Salesforce Event Bus Example: OrderPlaced Platform Event Let's assume you want to create a Platform Event called OrderPlaced__e to represent the event of a new order being placed in your Salesforce org. This event will contain information about the order, such as the order ID, customer name, and total amount. Define the Platform Event Schema: Go to Setup > Platform Events > New Platform Event. Define fields for the event, such as OrderID__c, CustomerName__c, and TotalAmount__c. Publish the Platform Event: You can publish a Platform Event using Apex, Process Builder, Flow, or other methods. Below is an example of publishing an event using Apex. // Publish OrderPlaced event Or...

Getting Started with Apex

Image
What is Apex ?  Apex, a strongly typed, object-oriented programming language, empowers developers to execute flow and transaction control statements on the Salesforce servers in conjunction with calls to the API. It's a proprietary language developed by Salesforce, specifically designed to enable the creation of robust business logic within the Salesforce platform. With its syntactical similarity to Java, Apex serves as the backend code that can manipulate data in Salesforce, execute complex validation rules, and automate intricate business processes. Critical features of Apex include: Integration with Salesforce Data : Apex allows you to write complex queries and transactions against the data stored in Salesforce. Transactional Control: Operations in Apex are transactional, meaning that all DML operations can be rolled back if any error occurs during the transaction process. Governor Limits: Salesforce imposes runtime limits, known as governor limits, to ensure that runaway Apex...

Lightning Components Performance Best Practices

Optimizing the performance of Lightning components is crucial for delivering fast and responsive user experiences in Salesforce applications.  Here are some best practices to improve the performance of Lightning components: Use minified versions of libraries and style sheets Use a content delivery network (CDN) Enable browser caching Use smaller image files CDN and Browser Caching wherever possible is a given.  Cloudflare CDN was used. Akamai is another common option. this is a must-have Custom Fonts (TTF files) were used from Google in the site implementation which was surprisingly taking a long time for browsers to download and use. So we moved to standard fonts which increased the score significantly. If you absolutely need to use Custom Fonts, then there are options in the community to preload this custom font as a static resource which loads faster compared to the Google Reference\ The CSS file was heavily optimized and instead of using images, we used CSS styles for some...

Use of Safe Navigation Operator

Safe Navigation Operator Instead of using explicit, sequential checks for null references, use the safe navigation operator (?.). This new operator short-circuits expressions that attempt to operate on a null value and returns null instead of throwing a NullPointerException. NOTE: All Apex types are implicitly nullable and can hold a null value returned from the operator. Example - Account acc = [SELECT Name FROM Account WHERE Id = :accId]; if (acc != null) {     return acc.Name; } Using Safe Navigation Operator String accName = acc?.acc.Name; String accName =  [SELECT Name FROM Account WHERE Id = :accId]?.Name; The Safe Navigation Operator (?.) in Apex is a feature that allows developers to safely navigate objects and data structures, avoiding null pointer exceptions. When you use the Safe Navigation Operator to access a chain of references, Apex will evaluate the expression from left to right and return null immediately if it encounters a null reference rather tha...

Determine whether the Salesforce organization is a Sandbox or a Production

To determine if a Salesforce organization is a sandbox or a production environment in Apex. Salesforce's sObject Organization has a field called IsSandbox, which is true for sandboxes and false for Production. Boolean isSandbox = UserInfo.getIsSandbox(); Organization org = [Select Id, Name, IsSandbox from Organization]; if (org.isSandbox) {     System.debug('The organization is a sandbox.'); } else {     System.debug('The organization is a production environment.'); } You can use this check to conditionally execute logic based on whether the Apex code is running in a sandbox or production environment. This can be useful for implementing different behaviors or configurations specific to each environment. In Salesforce, the Organization object represents metadata and settings for a Salesforce organization. It provides information about the organization's configuration, such as its name, address, edition, features, limits, and more. The Organization object is rep...

Custom Notifications aka Bell Notifications from the Apex code.

Image
The Messaging.CustomNotification class allows you to create, configure, and send custom notifications using Apex code. Here is a basic outline of how you can create and send a custom notification from an Apex trigger: Create a Custom Notification Type : In the Setup, you should create a Custom Notification Type. This defines the type of notification you will be sending from Apex. Use CustomNotification Class : Once you set up your Custom Notification Type, you can craft your Apex code to create the notification. Here's an example code snippet: // Get the Id for our custom notification type CustomNotificationType notificationType = [SELECT Id, DeveloperName FROM CustomNotificationType WHERE DeveloperName='Lead_Due_Diligence_Completed']; Messaging.CustomNotification notification = new Messaging.CustomNotification();  notification.setTitle('Your Notification Title');  notification.setBody('This is the detail of the notification');  notification.setNotification...

Salesforce Experience Cloud and Salesforce Sites

Image
Salesforce Experience Cloud (formerly known as Salesforce Community Cloud) and Salesforce Sites are both platforms provided by Salesforce for external-facing applications, but they serve different purposes and have distinct features.  Setting up - Salesforce Sites Experience Cloud Here's a comparison between the two: Purpose : Salesforce Experience Cloud : This platform is designed for creating branded online communities, portals, and websites where organizations can engage with customers, partners, and employees. Experience Cloud allows you to build custom-branded sites with features like discussion forums, knowledge bases, and access to Salesforce data. Salesforce Sites: Salesforce Sites, on the other hand, is a platform for creating public-facing websites or web applications that are directly integrated with Salesforce data. Sites are typically used for customer-facing portals, self-service support sites, or custom web applications that leverage Salesforce data and functional...

Salesforce Lightning B2B Just Got Better with Subscriptions Enablement

Image
Docmation's Salesforce experts bring an innovative functionality that makes the Salesforce Lightning B2B experience 10x better. Salesforce Lightning B2B, with its Apps, Lightning components, and industry process flows, allowed its users to get an industry-wide experience in a solution that was still tailored around their individual use case. However, there were still gaps that needed to be filled. Customers wanted to integrate their CPQ and Billing with B2B Lightning while leveraging existing pricing rules and engines to automate the processes.  For instance – What about recurring purchases? Most customer carts have, at least part of an order that belongs to the said category – be it weekly, monthly, quarterly, or annually. However, no such direct processes currently exist within the system.  Docmation’s team of Salesforce experts has launched the all-new ‘subscriptions accelerators’ functionality that works out-of-the-box to seamlessly automate CPQ and Billing processes with ...

Sandbox Management Best Practices

Sandbox Management and Best Practices An overview of different types of sandboxes, top use cases for each type, and what is included with each when the sandbox is created or refreshed. There are 4 types of sandboxes and some are only included in certain Salesforce Editions or purchased for an additional cost, please contact your Salesforce Account Executive for details. Common use cases for each type of sandbox and recommended best practices Developer - may be refreshed every day, does not include any data automatically but allows 200 MB of data to be imported or created. The most agile and plentiful sandbox type for proof of concept, metadata-specific development, or just playgrounds for Developers and Admins to run through potential setup changes to review impact. Developer Pro - may be refreshed every day, does not include any data automatically but allows 1GB of data to be imported or created. Same idea as the Developer but with a higher storage limit for the purpose of creating or...

Data sensitivity and Compliance categorization with Data Classification Metadata

Image
Properly classifying sensitive data in Salesforce is of utmost importance for any organization to implement effective data management policies and ensure compliance with global privacy regulations such as GDPR, CCPA, HIPAA, and others. By categorizing data based on its sensitivity level, companies can apply appropriate security measures, access controls, and data handling practices to reduce potential risks and safeguard sensitive information. Here's how sensitive data can be classified to support data management policies in Salesforce: Compliance Categorization The compliance acts, definitions, or regulations that are related to the field’s data. Default values: CCPA—California Consumer Privacy Act COPPA—Children's Online Privacy Protection Act GDPR—General Data Protection Regulation HIPAA—Health Insurance Portability and Accountability Act PCI—Payment Card Industry PersonalInfo—Personal information. For use with the Enhanced Personal Information Management feature. Only ava...

Salesforce Sandbox Setup Considerations

When setting up a Salesforce sandbox environment, it is essential to consider specific factors to ensure adequate testing and development while maintaining data integrity and security. Here are some key considerations: Servers and IDs Each sandbox and production org has a unique org ID. When a sandbox is created or refreshed, Salesforce creates an org, and the org ID changes each time. In places where the org ID is used, such as metadata and text values, Salesforce replaces the old sandbox org ID with a new one. To find the org ID for the current org, you can go to Setup and search for "Company Information" in the Quick Find box. A hardcoded org ID should be updated with the current ID for the sandbox to ensure that scripts or processes, such as test scripts or Web-to-Lead, work properly. Salesforce creates sandbox orgs on multiple instances, and when a sandbox is created or refreshed, it is assigned to a specific instance, which can cause sandboxes to appear on different URL...

Salesforce Sandboxes

Image
Sandboxes create copies of your Salesforce org in separate environments. Use them for development, testing, and training, without compromising the data and applications in your production org.  Sandboxes: Staging Environments for Customizing and Testing Sandboxes are isolated from your production org, so operations that you perform in your sandboxes don’t affect your production org. Sandbox Types Developer Sandbox – A Developer sandbox is intended for development and testing in an isolated environment. A Developer Sandbox includes a copy of your production org’s configuration (metadata). Developer Pro Sandbox – A Developer Pro sandbox is intended for development and testing in an isolated environment and can host larger data sets than a Developer sandbox. A Developer Pro sandbox includes a copy of your production org’s configuration (metadata). Use a Developer Pro sandbox to handle more development and quality assurance tasks and for integration testing or user training. Partial ...

Sitemap in Salesforce (Experience Cloud)

Image
A sitemap typically refers to a navigational structure or hierarchy that defines the layout and organization of pages within a Community (Experience Cloud). It provides a roadmap for users to navigate through the various pages and components of the application, ensuring a cohesive and intuitive user experience.  Make it easy for guest users to find new products in web searches. After you perform an incremental update to your sitemap, third-party search index crawlers can find newly added, publicly available products. New products are picked up in manual and scheduled incremental updates to your sitemap. Where : This feature is available in Lightning Experience, in Enterprise, Performance, Unlimited, and Developer editions. How : To manually update your store sitemap, make your store available to the public in Experience Builder | Settings | General, and select Public can access the site. Then open the SEO tab, and click Generate Sitemap. SEO ' sitemap.xml ' feature is not autom...

Retrieve Guest User IP Address with VF Page

Image
The two standard objects:  AuthSession ,  LoginGeo don’t store the login information of a Guest User. Using a VF Page  <apex:page showHeader="false" sidebar="false" controller="userIPAddressController"  action="{!getUserIPAddress}">  <script>     setTimeout(function(){         var message = '{!ip}';         parent.postMessage(message, window.top.location.origin);               }, 3000);  </script>  <apex:form >      {!ip}  </apex:form> </apex:page> Controller public class userIPAddressController{     public string ip {get;set;}     public pageReference getUserIPAddress() {                  // True-Client-IP has the value when the request is coming via the caching integration.         ip = ApexPages.currentPage().getHeaders()...

Retrieve IP Address of a Community User

Image
For a variety of purposes, including displaying items, sending texts, and other security-related tasks, tracing IP addresses is necessary. Logged in User IP Address Getting IP Address for logged in user is relatively simple as Salesforce stores this information in two standard objects:  AuthSession ,  LoginGeo . List<AuthSession> auth = [SELECT Id , IsCurrent, SessionType, CreatedDate, LoginGeoId, NumSecondsValid FROM AuthSession WHERE UsersId =: Userinfo.getUserID()]; if(auth.isEmpty() == false && auth[0].IsCurrent ){ system.debug('yes, it is current user session'); }else{ system.debug('No, it is not current user session'); } List<LoginGeo> lg = [SELECT Id,City, Country, PostalCode, Subdivision, Latitude, Longitude,LoginTime FROM LoginGeo WHERE Id =: auth[0].LoginGeoId]; Alternatively, you can use  Auth.SessionManagement  Class as well as below: Auth.SessionManagement.getCurrentSession().get('LoginGeoId'); getCurrentSession() re...