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 / apexsetadvancedmethods.cls
Created November 8, 2021 14:43
Code used in set advanced methods tutorial on SFDC Stop (https://youtu.be/SYzg37oIU8A)
clear():
----------
Set<Integer> numbers = new Set<Integer>{30,30,30,20,20,10,40,40};
System.debug(numbers);
numbers.clear();
System.debug(numbers);
isEmpty():
-----------
@rahulmalhotra
rahulmalhotra / apexset.cls
Created November 8, 2021 13:41
Code used in set basics apex tutorial on SFDC Stop (https://youtu.be/ENkGqx03sOY)
Set Data Structure in Apex
-------------------------------
Def: A set is an unordered collection of elements that do not contain any duplicates.
1. Creating a set of Integers
Set<Integer> numbers = new Set<Integer>();
System.debug(numbers);
@rahulmalhotra
rahulmalhotra / account-and-contact-upsert-together-with-error.cls
Created October 24, 2021 07:56
This code snippet is used in First error: Insert/Upsert failed. First exception on row 100; first error: INVALID_FIELD, Cannot specify both an external ID reference Parent and a salesforce id, ParentId: [] salesforce tutorial to specify error when we're having both id of the parent object and reference populated as well.
List<SObject> records = new List<SObject>();
records.add(new Account(Name='Test Account', Reference_ID__c = 234));
records.add(new Contact(LastName='Test Contact', AccountId = null, Account = new Account(Reference_ID__c = 234)));
Database.upsert(records);
@rahulmalhotra
rahulmalhotra / account-and-contact-upsert-together.cls
Created October 24, 2021 07:39
Gist to insert account and contact record together
List<SObject> records = new List<SObject>();
records.add(new Account(Name='Test Account', Reference_ID__c = 123));
records.add(new Contact(LastName='Test Contact', Account = new Account(Reference_ID__c = 123)));
Database.upsert(records);
@rahulmalhotra
rahulmalhotra / apex-heap-size-demo.cls
Created October 2, 2021 07:48
This code is used in apex heap size error resolution tutorial of SFDC Stop
List<Account> accounts = new List<Account>();
for(Integer i=1; i<=10000; i++) {
accounts.add(new Account(Name = 'Account ' + i));
}
insert accounts;
List<Account> accounts = [SELECT Id FROM Account];
System.debug('Heap size when queried list of accounts = ' + Limits.getHeapSize());
@rahulmalhotra
rahulmalhotra / apexlist.cls
Created September 10, 2021 12:34
Code used in Apex List Tutorial
List Data Structure in Apex
-------------------------------
1. Creating a list of Integers
List<Integer> numbers = new List<Integer>();
System.debug(numbers);
List<Integer> numbers = new List<Integer>{10,20,30,40,50,60,70};
@rahulmalhotra
rahulmalhotra / ApexUtil.cls
Created August 8, 2021 05:18
Utility class consisting of Dynamic Apex methods
/*
* Author:- Rahul Malhotra
* Description:- Utility class consisting of some common methods
* Created Date:- 08-08-2021
* Last Modified:- 08-08-2021
* Code Origin:- SFDC Stop (https://www.sfdcstop.com)
*/
public with sharing class ApexUtil {
/*
@rahulmalhotra
rahulmalhotra / asyncapexjob.soql
Last active July 5, 2021 05:52
Code snippet used in Scheduled Jobs Custom LWC Component post on sfdcstop
SELECT
ApexClassId,
ApexClass.name,
Id,
JobItemsProcessed,
JobType,
Status,
NumberOfErrors,
MethodName
FROM AsyncApexJob
@rahulmalhotra
rahulmalhotra / crontrigger.soql
Created July 5, 2021 05:15
Code snippet used in Scheduled Jobs Custom LWC Component blog on sfdcstop
SELECT
ID,
CronExpression,
CronJobDetail.Name,
CronJobDetailId,
EndTime,
NextFireTime,
PreviousFireTime,
StartTime,
State,
@rahulmalhotra
rahulmalhotra / node-gyp install command
Created July 2, 2021 11:09
Command to install node-gyp module for lwc local server
npm install -g node-gyp