Skip to content

Instantly share code, notes, and snippets.

Avatar
😃
Working on something amazing...!!

Rahul Malhotra rahulmalhotra

😃
Working on something amazing...!!
View GitHub Profile
@rahulmalhotra
rahulmalhotra / batch-apex-mechanism-detail.cls
Created Jan 9, 2022
Code used in "How many batches will be executed? 20000 records & 250 batch size | Salesforce Batch Apex Interview" (https://youtu.be/LgHxpR_6Vrs)
View batch-apex-mechanism-detail.cls
-> 'Create a Batch Class to opt out contact records from email, call and fax whose Unsubscribe Date has passed'
20,000 records -> total
200 records
How many batches?
-> 20,000 / 200 -> 100 batches in total
@rahulmalhotra
rahulmalhotra / batch-apex.cls
Created Dec 22, 2021
Code used in "How to create a Batch Class in Salesforce Apex? | Batch Apex | Apex Tutorial Series by SFDC Stop" (https://youtu.be/1JyWuEQrHco)
View batch-apex.cls
/*
* Author:- Rahul Malhotra
* Description:- This batch class is used to update all contacts who have opted out of email, call and fax
* Created:- 18-12-2021
* Last Updated:- 18-12-2021
*/
public class UpdateContactsBatch implements Database.Batchable<sObject> {
// * Return a maximum of 50 million records
public Database.QueryLocator start(Database.BatchableContext batchableContext) {
@rahulmalhotra
rahulmalhotra / enable_first_checkbox_on_page.js
Last active Dec 12, 2021
This gist is used to enable first checkbox named "enable" on current page
View enable_first_checkbox_on_page.js
let inputs = document.getElementsByTagName('input');
for(let input of inputs) {
if(input.type === 'checkbox' && input.name === 'enable') {
input.disabled = false;
break;
}
}
@rahulmalhotra
rahulmalhotra / sort-util.cls
Created Dec 9, 2021
Code used in "Sort a list of sObject records based on a field value | Salesforce Apex Tutorial Series by SFDC Stop" (https://youtu.be/4qyJfelUMjs)
View sort-util.cls
-----------------------------------------------------------------------------------------
-> Sort a list of sObject records based on field value
-----------------------------------------------------------------------------------------
List<Account> accounts = new List<Account>();
accounts.add(new Account(
Name = 'Hooli',
NumberOfEmployees = 50,
AnnualRevenue = 10000
));
@rahulmalhotra
rahulmalhotra / enum.cls
Created Dec 7, 2021
Code used in "Enums in Apex | What is Enum and where do we use it? | Salesforce Apex Tutorial Series by SFDC Stop" tutorial on SFDC Stop (https://youtu.be/N3du8bRbYSs)
View enum.cls
-------------
Enums in Apex
--------------
An enum is an abstract data type whose values consist of a finite set of identifiers.
Enums are typically used to define a set of possible values that don’t otherwise have a numerical order.
public enum Color { RED, BLUE, GREEN, ORANGE, PURPLE }
values()
@rahulmalhotra
rahulmalhotra / custom-comparator.cls
Created Dec 4, 2021
Code used in "Apex List Comparator | System.ListException: One or more of the items in this list is not Comparable" tutorial on SFDC Stop (https://youtu.be/Sf95Bl_zP2U)
View custom-comparator.cls
---------------------------------------------------------------------------------------------------------------------------
Custom Comparator
---------------------------------------------------------------------------------------------------------------------------
List<Integer> numbers = new List<Integer>{ 5, 3, 2, 1, 4 };
System.debug('Initial list of Integers => ' + numbers);
System.debug('Sorting Integers....');
numbers.sort();
@rahulmalhotra
rahulmalhotra / solvingrealworldproblemusingmapapex.cls
Created Nov 25, 2021
Code used in "Write efficient code using Data Structures in Salesforce Apex | Reduce Time Complexity using Map" video on SFDC Stop (https://youtu.be/KJOt-QVNOds)
View solvingrealworldproblemusingmapapex.cls
// * Link accounts with parent accounts
Update 10,000 accounts
-----------------------
// * Brute Force Approach - Very time consuming
List<Account> accounts = [SELECT Reference_ID__c, Parent_Reference_ID__c FROM Account];
List<Account> accountsToUpdate = new List<Account>();
@rahulmalhotra
rahulmalhotra / mapadvancedmethods.cls
Created Nov 20, 2021
Code used in map advanced methods tutorial on SFDC Stop (https://youtu.be/km2gUwkBN78)
View mapadvancedmethods.cls
Map advanced methods:
----------------------
keySet(): Get all keys from a map
-------------------------------------
Map<Integer, String> employeesMap = new Map<Integer, String>{
1 => 'Richard',
2 => 'Monica',
3 => 'Erlich',
@rahulmalhotra
rahulmalhotra / mapbasicmethods.cls
Created Nov 20, 2021
Code used in map basic methods tutorial on SFDC Stop (https://youtu.be/MKqylTF4yGo)
View mapbasicmethods.cls
Map Data Structure in Apex
-------------------------------
Def: A map is a collection of key-value pairs where each unique key maps to a single value.
1. Creating a Map of Employees
-------------------------------
Map<Integer, String> employeesMap = new Map<Integer, String>();
System.debug(employeesMap);
@rahulmalhotra
rahulmalhotra / settolistandlisttoset.cls
Created Nov 8, 2021
Code used in set to list and list to set conversion tutorial on SFDC Stop https://youtu.be/ArSOAxTOuHo
View settolistandlisttoset.cls
Convert Set to List
---------------------
Set<Integer> numbers = new Set<Integer>{30,30,30,20,20,10,40,40};
System.debug('Initial Set -> ' + numbers);
List<Integer> numbersList = new List<Integer>(numbers);
System.debug('List from Set -> ' + numbersList);
System.debug('Number at index 2 = ' + numbersList[2]);