Skip to content

Instantly share code, notes, and snippets.

@jvolkov
jvolkov / DateToDatetime
Last active November 22, 2022 21:37
Convert date to a datetime in apex
Date today = System.today();
Integer d = today.day();
Integer mo = today.month();
Integer yr = today.year();
DateTime dt = DateTime.newInstance(yr, mo, d);
// returns 2022-11-22 08:00:00
Datetime todayWithTime = dt.addHours(12);
system.debug(' todayWithTime: ' + todayWithTime);
// returns 2022-11-22 20:00:00
@jvolkov
jvolkov / insertCampaignMemberStatuses
Created June 14, 2022 23:05
create salesforce campaign member statuses
// change the campaign id and status to the correct values
Campaign campaign = [SELECT Id FROM Campaign WHERE Id = 'ENTER THE CAMPAIGN ID' LIMIT 1];
List<CampaignMemberStatus> newStatusesToInsert = new List<CampaignMemberStatus>();
List<String> statuses = new List<String>{'Ideal User', 'MQL', 'Assigned', 'Touched', 'Disqualified', 'Clicked', 'Demoed', 'Opportunity', 'Won'};
for (String status: statuses) {
system.debug(status);
CampaignMemberStatus newStatus = new CampaignMemberStatus ();
newStatus.Label = status;
newStatus.CampaignId = campaign.Id;
Sub SalesforceDate()
Application.FindFormat.NumberFormat = "m/d/yyyy"
Application.ReplaceFormat.NumberFormat = "yyyy-mm-dd"
Cells.Replace What:="", Replacement:="", _
SearchFormat:=True, ReplaceFormat:=True
End Sub
@jvolkov
jvolkov / queryDLRS
Last active June 23, 2021 18:04
query all declarative lookup rollup summaries
SELECT
Id,
Label,
dlrs__ChildObject__c,
dlrs__FieldToAggregate__c,
dlrs__ParentObject__c,
dlrs__AggregateResultField__c,
dlrs__Description__c,
dlrs__RelationshipCriteriaFields__c,
dlrs__RelationshipCriteria__c,
@jvolkov
jvolkov / apex-snippet.json
Last active April 22, 2022 18:12
vs-code-snippets
{
//For List
"List_Apex": {
"prefix": "listToUpdate",
"body": [
"List<${1:object}> ${2:lstName} = new List<${1}>();"
],
"description":"List of sObjects"
},
@jvolkov
jvolkov / get_sample_leads.sh
Last active July 10, 2017 23:08
Move Salesforce lead data from one Salesforce org to another using the Force.com CLI (https://force-cli.heroku.com)
#!/bin/bash
# enter product username
echo -e "enter production username: "
read prod_user
# enter product password with security token
echo -e "enter production password followed by security token, no spaces: "
read prod_pass_token
@jvolkov
jvolkov / join.py
Last active July 10, 2017 23:07
Quick and dirty way to append data between 2 files instead using an Excel vlookup
import pandas as pd
data = pd.read_csv('desktop/data.csv')
ind = pd.read_csv('desktop/index.csv')
data = data.set_index('org')
ind = ind.set_index('org')
data.info()
ind.info()
join = ind.join(data)
join.info()
join.to_csv('desktop/join.csv')
@jvolkov
jvolkov / promotion_record_transfers.sh
Last active July 10, 2017 23:06
Transfer data from one username to another inside Salesforce
#!/bin/bash
# get users old user id
echo -e "enter the user id for the old username: "
read user_id
# get users new user id
echo -e "enter the user id for the new username: "
read new_user_id