Category: PD II

All About Asynchronous Apex

While studying for the Salesforce Platform Developer II certification, I was going through the different options Apex provides to run Apex code asynchronously. This post is all about sharing the study notes with key points to remember.Apex provides four options to run code asynchronously. Future Method, Queueable Apex, Batch Apex and Scheduled Apex.Future MethodsMethods are annotated with @future annotation.Future methods should be static and can only return void type.It supports parameters, but parameters should be primitive data types, arrays of primitive data types, or collection. sObjects or objects cannot be used as parameters to future methods.These methods run in their own thread and will only start when the resources are available.They are used for long running operations and prevent any delay in apex transaction.They can be used for callouts to external web services and also separating DML operations to prevent Mixed DML error.Future methods should not be used for processing large amount of data. In that case, Batch Apex should be used.To test future methods, enclose test code between startTest and stopTest test methods.Future methods not necessarity execute in the same order as they are called.Future methods cannot be used inside Visualforce controllers getter, setter, constructor methods.Reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking_future_methods.htmhttps://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_future_methodsQueueable ApexApex code must implement Queueable interace.By implementing Queueable interface, Apex class can be added to the job queue and it will run when the system resources are available.The difference between Queueable Apex...

Read More

Important points to remember regarding actionRegion, actionFunction, actionSupport, actionPoller

Last night(July 17th, 2019) while preparing for Platform Developer II certification, I was going through my notes to revise the different ways to call Apex Controller functions from Visualforce page, I thought of making a post regarding actionRegion, actionFunction, actionSupport, actionPoller & actionStatus. Just setting the expectation beforehand – It is not a post which will explain you all, but I will share the developer guide link for each of them so that you can go and read them (highly recommended).actionRegionThe specifies the components to be processed on Force.com server. Without this tag, the whole page will be processed. With actionRegion also the whole form is submitted, but only the part within the tag will be processed.It needs a reRender attribute to be effective. It will only refresh the part of the page using the data contained within the tag. This can be very effectively used to avoid validation errors that may occur due to present of standard validation rule in VF page like required attribute.Here is the example without ActionRegion:Controller:public with sharing class WithoutActionRegionController { public String valueEntered{get;set;} public String country{get;set;} public String state{get;set;} public WithoutActionRegionController() { country = ”; state = ”; valueEntered = ”; } public PageReference countrySubmitted(){ valueEntered = ‘Country: ‘ + country; return null; }}Visualforce Page:<apex:page controller=”WithoutActionRegionController”> <apex:form id=”myForm”> <apex:pageMessages id=”messages1″/> <apex:pageBlock id=”topPageBlock”> <apex:pageBlockSection columns=”2″ title=”Country & State”> <apex:outputText value=”Enter Country” /> <apex:inputText value=”{!country}” > <apex:actionSupport...

Read More
Loading

Earlier Posts

  • 2024 (25)
  • 2023 (47)
  • 2022 (25)
  • 2021 (35)
  • 2020 (41)
  • 2019 (13)
  • 2018 (16)
  • 2017 (14)
  • 2016 (18)
  • 2015 (74)
  • 2014 (20)