Skip to content

Instantly share code, notes, and snippets.

@forcethesales
forcethesales / add Campaign Member Status
Created June 26, 2023 23:33
quickly add new campaign member status to all campaigns of Type Email
List<Campaign> exampleTwo = new List<Campaign>([SELECT Id, Name FROM Campaign WHERE Type = 'Email']);
List <CampaignMemberStatus> newStati = new List <CampaignMemberStatus> ();
for (Campaign camp : exampleTwo) {
CampaignMemberStatus newStat = new CampaignMemberStatus();
newStat.CampaignID = camp.Id;
newStat.Label= 'Subscribed';
newStati.add(newStat);
}
insert newStati;
@forcethesales
forcethesales / yearEndGiftBatchTest
Last active January 19, 2023 02:14
Nonprofit Year End Tax Deductible Letter
//Instructions
//In your developer console in your sandbox, find the class called yearEndGiftBatchTest
//and replace all the code with this code.
//You don't need to modify this code at all.
//Code by Jessie Rymph
//January 12, 2023
//Tests the Year End Gift Batch process using the YearEndtestDataFactory class
//https://wp.me/p9qPLI-1q8
@forcethesales
forcethesales / batchable class
Created December 28, 2022 22:04
bulk year end tax receipt
public class qGiftsLastYear implements Database.Batchable<sObject>
//,Database.Stateful
{
//ideally it could be invoked by a flow but that's not being used in this version
@InvocableMethod(description='Year End Tax Flow' )
public static void yearEndTaxMethod () {
database.executeBatch(new qGiftsLastYear(),10); }
public Database.QueryLocator start(Database.BatchableContext bc) {
@forcethesales
forcethesales / Excel To VF
Created October 19, 2022 22:25
Visualforce Page like Excel Spreadsheet
/** This visualforce page allows you to total up columns, total up rows, and total it all up, just like you would in excel!
<apex:page StandardController="outfunds__Funding_Request__c" lightningStylesheets="true">
<apex:slds />
<apex:form id="form">
<apex:outputText value="Voices for Healthy Kids Budget Planning Tool" id="header"/>
<apex:panelGrid columns="4" id="theGrid">
<apex:outputText value="" id="thefirst"/>
<apex:outputText value="Non Lobbying" id="theSecond"/>
<apex:outputText value="Lobbying" id="theThird"/>
@forcethesales
forcethesales / Add Contacts from Certain States
Last active July 20, 2022 17:15
Add Contacts from Certain States
//This works but times out with too big of a spreadsheet
public class sfdoIdo_addContactsByState {
@InvocableMethod (label = 'Select State for Maps' description = 'select states for map.')
//Query your files in static resources and get their content as String
public static void getStatesList (List<String> states) {
StaticResource ctcSR = [SELECT Id, Body FROM StaticResource WHERE Name = 'sfdoido_Contact' LIMIT 1];
String bodyCtcSR = ctcSR.Body.toString();
@forcethesales
forcethesales / COMPARISON V 1
Last active February 1, 2024 21:55
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
@forcethesales
forcethesales / Invocable Method to look at Opps
Created August 4, 2021 17:00
This invocable method gets one contact id from the Flow and returns all associated Opps as a collection variable
public class contactsListAction {
//this invocable method takes a single contact from Flow from a text variable
//and returns a list of lists of opportunities associated with that contact.
//the list of lists is stored as a collection variable in the Flow.
@InvocableMethod (label = 'SendContactsGet Opps' description = 'returns opps for this contact.')
//the method will return a List of Lists of Opportunities, and receive a List of Salesforce ids
public static List<List<Opportunity>> getContactIds (List<ID> ids) {
//declare a new list of Opps
List <Opportunity> oppIds = new List <Opportunity> ();
//declare a new list of lists of opps
@forcethesales
forcethesales / Contact Classic HTML Template
Last active May 20, 2021 21:02
Unsubscribe Link Email Templates
Classic Contact HTML Email Template
Dear {!Contact.FirstName} {!Contact.LastName}, </br>
<a href="https://InsertYourSiteDomainHere/Unsubscribe?recordId={!Contact.Id}&Email={!Contact.Email}">Click here to unsubscribe from all emails from our organization.</a>
</br>
Instructions: </br>
<li>Change ONLY this part of the HTML above:</li>
InsertYourSiteDomainHere</br>
to the Site Domain you saved earlier.</br>
@forcethesales
forcethesales / Custom Metadata Type in VF Controller
Last active April 14, 2021 15:10
Custom Metadata Type in VF Controller
//Controller by Jessie Rymph included with unmanaged package Unsubscribe Link from AppExchange & Salesforce Labs.
//the controller tells the visualforce page jrsl_ul_UnsubscribeFinish to display text if a custom metadata type says "Yes" to a confirmation email
//April 9, 2021
public without sharing class jrsl_ul_UnsubscribeController {
private final jrsl_ul_Unsubscribe_Link__mdt uLmDt;
public string displayText {get; set;}
public boolean booly {get; set;}
public jrsl_ul_UnsubscribeController(){
@forcethesales
forcethesales / CustomMetadataUtils
Created January 26, 2021 00:20
invocable method in Flow to Update Custom Metadata Type
//https://www.biswajeetsamal.com/blog/create-or-update-custom-metadata-type-using-apex/
public class CustomMetadataUtils implements Metadata.DeployCallback {
//Interface method
public void handleResult(Metadata.DeployResult result, Metadata.DeployCallbackContext context) {
if (result.status == Metadata.DeployStatus.Succeeded) {
//Success
System.debug('Success Result-' + result);
} else {
//Failed