Month: July 2019

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: 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 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

Advanced Currency Management in Salesforce

Salesforce supports multi currency. You can enable the same by going to Company Information and then checking the box – “Activate Multiple Currencies”. You need to read the below article before enabling multi currency. done, you can enable Dated Exchange Rate to define the exchange rate for any kind of periods like month, quarter, year etc. To do that you can go to Company profile -> Manage CurrenciesNow you can add the entries for dated exchange rates by clicking on the “Manage Dated Exchange Rates” button. And then click on “New Exchange Rates” button. Below images shows how to add dated exchange rates.This dated exchange rates are used in Opportunities, Opportunity products and Opportunity Reports.The object used to store this information is DatedConversionRate. You can run SOQL queries against this object to get the details -SELECT IsoCode,ConversionRate,NextStartDate,StartDate FROM DatedConversionRate ORDER BY NextStartDate ASCYou can use Rest Explorer also to add/delete new DatedConversionRate like below -Important Objects/Fields:CurrencyType: This object stores the list of currencies used in the org when multi currency is enabled. If single currency is used in the org, then this object is not available.DatedConversionRate: This object stores the dated exchange rates.CurrencyIsoCode: This additional field is present in object which has current field and the org has multi-currency...

Read More

Earlier Posts

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