Skip to content

Instantly share code, notes, and snippets.

View rahulmalhotra's full-sized avatar
😃
Working on something amazing...!!

Rahul Malhotra rahulmalhotra

😃
Working on something amazing...!!
View GitHub Profile
@rahulmalhotra
rahulmalhotra / batch-apex-mechanism-detail.cls
Created January 9, 2022 11:31
Code used in "How many batches will be executed? 20000 records & 250 batch size | Salesforce Batch Apex Interview" (https://youtu.be/LgHxpR_6Vrs)
-> '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 December 22, 2021 17:15
Code used in "How to create a Batch Class in Salesforce Apex? | Batch Apex | Apex Tutorial Series by SFDC Stop" (https://youtu.be/1JyWuEQrHco)
/*
* 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 December 12, 2021 04:59
This gist is used to enable first checkbox named "enable" on current page
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 December 9, 2021 18:41
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)
-----------------------------------------------------------------------------------------
-> 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 December 7, 2021 16:12
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)
-------------
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 December 4, 2021 15:11
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)
---------------------------------------------------------------------------------------------------------------------------
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 November 25, 2021 15:11
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)
// * 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 November 20, 2021 14:01
Code used in map advanced methods tutorial on SFDC Stop (https://youtu.be/km2gUwkBN78)
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 November 20, 2021 13:12
Code used in map basic methods tutorial on SFDC Stop (https://youtu.be/MKqylTF4yGo)
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 November 8, 2021 16:11
Code used in set to list and list to set conversion tutorial on SFDC Stop https://youtu.be/ArSOAxTOuHo
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]);