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 / 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 / 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 / gist:9d881ad0a485f1e3e187eb1175a2d58d
Created June 15, 2022 12:34 — forked from lfreeland/gist:df5c757036e38751874f5d4b874e5a19
Lightning Field Set Form Apex Controller
public with sharing class FieldSetFormController {
@AuraEnabled
public static FieldSetForm getForm(Id recordId, String objectName, String fieldSetName) {
FieldSetForm form = new FieldSetForm();
form.Fields = getFields(recordId, objectName, fieldSetName);
form.Record = getRecord(recordId, objectName, form.Fields);
return form;
}
@mhamzas
mhamzas / Integration_BasicAuthRestCallout.cls
Created May 18, 2022 10:18
This is a quick overview of an Apex REST Callout using Basic Authentication from within Salesforce
// Method to perform callouts
public String MakeCallout(string description, string keyToVerify){
// define a response to caller
String outcomeMsg;
// define basic information for later, store these in a protected custom setting
string endpoint = 'http://api.yourendpoint.com/'; // be sure this is configured in "Remote Site Settings"
string resource = 'products/';
string username = 'api_user';
@mhamzas
mhamzas / gist:1d6b4c26f39676fe4867e7425edac702
Last active November 6, 2022 14:07 — forked from Sunil02kumar/gist:396b9ec81b59a23aee29e5ca41a28202
Find All Content Version Ids from Library and Generate File download URLs
string LibraryName='Demo Download Library';
ContentWorkspace ws = [SELECT Id, RootContentFolderId FROM ContentWorkspace WHERE Name = :LibraryName LIMIT 1];
Set<string> fileNameList = new Set<string>();
List<ContentDocumentLink> filesToDelete= new List<ContentDocumentLink>();
string csvString='';
String domainUrl=URL.getSalesforceBaseUrl().toExternalForm();
for(ContentDocumentLink con:[select id,LinkedEntityId,ContentDocumentId ,ContentDocument.LatestPublishedVersion.Title from ContentDocumentLink where LinkedEntityId=:ws.Id]){
csvString = csvString +domainUrl+'/sfc/servlet.shepherd/version/download/'+con.ContentDocument.LatestPublishedVersionId+'\n';
}
@mhamzas
mhamzas / SandboxPostCopyUpd.cls
Created November 17, 2021 11:15 — forked from az-ak/SandboxPostCopyUpd.cls
Apex SandboxPostCopy example
global without sharing class SandboxPostCopyUpd implements SandboxPostCopy {
global void runApexClass(SandboxContext context) {
LIst<Contact> ConList = [SELECT ID FROM CONTACT];
for (Contact con : ConList) {
con.Email = '[email protected]';
}
update ConList;
}
}