Apex

Convert List To Map in Apex Salesforce

Sometimes, we need to convert list of elements to map. instead of looping each element and put that into a map, here is a simple trick to do that in …

Check Current user has a custom permission

The custom permission could be assigned via a Permission Set or a Permission Group set.  Sometimes, we need to check the logged in user has custom pe…

Access JSON Object Properties in Apex

Sometimes we need to parse simple json objects in apex. for that, we need to create a new wrapper class with those properties and deserialize the res…

Write targeted apex assertions in test classes

Salesforce winter 23 release, introduced new  System.Assert class to provides methods that handle all types of logical assertions and comparisons. w…

Generate unique random ID or String in apex

Some times we required to generate some unique random id for externalId purpose or sometime we need random string. salesforce OOTB provides some util…

Iterate over a Complex Map using a for loop

Its the most common use case to use a list inside map method. here I'm going to show you how to iterate a list of elements in the map using a sim…

Copy List of sObject records to Map in apex

Sometimes, we need to copy a list of sObject records into Map of, record id as a key and record as a value. here is a simple solution to how to do th…

Copy records from one Map to another Map In Apex

We can copy element from one Map to another map with same Key and values datatypes. If you trying to copy different key or values it will throw error…

How to Add Elements to Map in apex

Now I'm going to define a simple map and then add elements to that map. here I'm taking fruit's Names as values and the key as Serial Nu…

What is a Map in apex salesforce?

Map is the one of the best collection type in apex programming language. It's more powerfull and more flexible collection in apex. It stores data…

Delete all Scheduled jobs from salesforce

Sometimes we need to delete schedule batch jobs not to run in future. if we have limited jobs then we can delete those manually. if you have more sc…

Abort the Batch jobs from Developer console

sometime when we are saving apex classes, we will get error message batch jobs are pending. so that we cant able to save it. to save that apex class…

Single line code to creates and delete record in apex

Sometimes we need to write a code to create some test records and to delete some test records once its' testing is over. so here we will show yo…

One line code to Add records to list and Map apex

Sometimes, we need to query records from database and have take it into one Map, with id as a key and record as a value. for this, first we will que…

Single line if-else statements in apex

some times, for simple if else conditions, we can write one line if-else statements to add more readability for your apex code. Single line if else: …

Single line variable declaration in apex

Declare multiple similar data type of variables in one line. so save line of cod and readability.  One line var declaration apex // variable declara…

Get the Protocol from base url in salesforce

Some times, we need to fetch the protocol of the our call. It should be http or https . here is the method for fetch protocol of salesforce. Answers…

Create sample account URL from the base URL

Create a dynamic record URL using base URL method. Some time, we need to create record and redirect to that record details page. so here is the samp…

Get the salesforce Host Name

Get the salesforce Host Name, Returns the host name of the current URL. Solution: 1 salesforce winter 23 release a new class  DomainCreator . It has …

Get the base URL of Salesforce Org

How to know base URL of a salesforce org, without using soql Query in apex. Answer url baseURL = URL.getSalesforceBaseUrl(); System.debug('Base …