Skip to content

Instantly share code, notes, and snippets.

View mhamzas's full-sized avatar

Hamza Siddiqui mhamzas

View GitHub Profile
@mhamzas
mhamzas / COMPARISON V 1
Created February 1, 2024 21:55 — forked from forcethesales/COMPARISON V 1
Nonprofit Year End Donation Receipt
public class yearEndCampaignTable implements
Database.Batchable<sObject>,Database.Stateful {
//instance member to retain state across transactions
public static Integer emailLimits;
public Integer recordsProcessed =0;
public Database.QueryLocator start(Database.BatchableContext bc) {
Integer year = Date.Today().year()-1;
return Database.getQueryLocator([SELECT LastName, id,Gifts_Last_Year__c, (SELECT Id, CloseDate, Amount, Campaign.Name FROM Opportunities
WHERE CALENDAR_YEAR(CloseDate) =:year AND IsWon = True ORDER
@mhamzas
mhamzas / DeleteRecordsBatchable.cls
Created November 19, 2023 21:18 — forked from donners77/DeleteRecordsBatchable.cls
Bulk delete records in Salesforce using an Apex batch job
// Example use:
// First edit code below and replace ###ObjectName### with Contact
// Then execute in the Developer Console | Debug | Open Execute Anonymous Window
// DeleteRecordsBatchable batchable = new DeleteRecordsBatchable('SELECT Id FROM Contact WHERE Name = \'DeleteMe\'');
// Id batchId = Database.executeBatch(batchable, 10);
global class DeleteRecordsBatchable implements Database.Batchable<sObject> { // created to bulk delete records - use with care!
// Fields
global final String Query;
@mhamzas
mhamzas / Credits
Created April 17, 2023 07:09
Helpful methods to get information about fields and objects, including schema information by Kevin Antonioli - https://live.playg.app/play/field-utils
This is by "Kevin Antonioli" publised on https://live.playg.app/play/field-utils
@mhamzas
mhamzas / setup.sh
Created February 14, 2023 08:06 — forked from metadaddy/setup.sh
Setup a SalesforceDX scratch org, open an IP range, check we can log in
#! /bin/bash
#
# Requires jq - see https://stedolan.github.io/jq/
#
# Assumes that the following env vars are set:
#
# CLIENT_ID - the client ID for your OAuth 2 app
# JWT_KEY_FILE - path to the private key for creating a JWT
# HUB_USERNAME - authentication username
@mhamzas
mhamzas / DynamicDML.cls
Last active October 18, 2022 11:27
Dynamic Parent Child Insertion in single DML
// Initiaing a new list to insert
List<sObject> insertList= new List<sObject>();
//Account Object
sObject accObj = Schema.getGlobalDescribe().get('Account').newSObject();
// Account Object Data mapping
accObj.put('Name','Test');
accObj.put('ExtId__c','Test'); //External Id
@mhamzas
mhamzas / logentries_manual_setup.md
Created August 11, 2022 21:37 — forked from ostinelli/logentries_manual_setup.md
How to use a single Logentries account on Heroku.

If you have multiple applications on Heroku and would like to use a single Logentries account for all of them, this is how you do it. Basically, do not use add-ons, and send all drains to your account.

  • In your Logentries account, click on Add Log
  • Select Manual
  • In the form that appears, input the following:
    • Log Name: access.log
    • Select Set: new set named myapp-{environment}, for instance myapp-staging (at least, this is how I like to name my entries)
    • Select the Plain TCP, UDP - logs are sent via syslog option
  • Click on Create Log Token
@mhamzas
mhamzas / gist:6844968d47bdda9d696b19125f44b76b
Created July 8, 2022 08:27 — forked from sunilmurali/gist:44a968ff1ce910980272
Apex Queueable Interface Skeleton with Callouts
/**
* @description Extend a queueable job to complete the merge request from the page
*
*
*/
public class QueueJob implements Queueable, Database.AllowsCallouts {
public class QueueJobException extends Exception {}
public QueueJob ( ) {
/* Name: CrudFlsUtility
Description : Utility class that contains methods to help in CRUD & FLS checks
Author : Raja Karuppasamy
Source: https://rajasfdc.com/2020/09/28/enforce-crud-fls-check-in-apex-using-stripinaccessible/
*/
public with sharing class CrudFlsUtility {
/*
Purpose: Used to check CRUD & FLS access for the logged in user using StripInaccessible feature
Input(s): records - List of Sobjects that you either queried already or going to be used in DML
accessCheck - AccessType enum - CREATABLE/READBLE/UPDATABLE/UPSERTABLE
@mhamzas
mhamzas / searchandRemove.js
Created June 23, 2022 07:21
JSON - Search for keys in nested object and delete them
/* https://stackoverflow.com/questions/68678126/search-for-keys-in-nested-object-and-delete-them */
function cleanData(data, deleteKeys) {
// There is nothing to be done if `data` is not an object,
// but for example "user01" or "MALE".
if (typeof data != "object") return;
if (!data) return; // null object
for (const key in data) {
if (deleteKeys.includes(key)) {
delete data[key];
@mhamzas
mhamzas / permChecker.cls
Last active June 23, 2022 07:08
This method is to check all the Object and fields per object has the access - Obj & FLS secuity checker
/* This method is to check all the Object and fields per object has the access
Obj & FLS secuity checker */
public static void permChecker(String objName, string listofCommaSeperatedFields, String perm){
String appNameSpace = FilogixWrapperBinding.getAppNameSpace();
// Checking permission on Object
if(!String.isBlank(objName) && !String.isBlank(perm)){
// Appending a NameSpace if it's a custom object.
if(objName.endsWith('__c') && !objName.startsWith(appNameSpace)){
objName = appNameSpace+objName;