0% found this document useful (0 votes)
45 views7 pages

Salesforce Development CheatSheet

The Salesforce Development Cheat Sheet provides essential code snippets and examples for various Salesforce development tasks, including custom permissions, date formatting, custom settings methods, and handling named credentials. It also covers string parsing, SOQL date functions, schema functions, and email messaging. The document serves as a quick reference guide for developers working with Salesforce, published by Fernando on April 10, 2021.

Uploaded by

anshita03soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views7 pages

Salesforce Development CheatSheet

The Salesforce Development Cheat Sheet provides essential code snippets and examples for various Salesforce development tasks, including custom permissions, date formatting, custom settings methods, and handling named credentials. It also covers string parsing, SOQL date functions, schema functions, and email messaging. The document serves as a quick reference guide for developers working with Salesforce, published by Fernando on April 10, 2021.

Uploaded by

anshita03soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Salesforce Development Cheat Sheet

by Fernando (taurenhunter) via cheatography.com/133929/cs/27477/

Custom Permis​sions Date/D​ateTime Formats and Examples (cont)

if( System.Fe​atu​reM​ana​gem​ent.ch​eck​Per​mis​sion( dt.format( 'YYYY-​‐ 2019-06-30 02:06:​30.720 PM


​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​'AC​ust​​P​erm​' ) == true ) { MM-dd hh:mm:​‐
... ss.SSS a' )
<ap​​ex​:​p​ag​​eBlock render​​ed​=​"​{!$​​Pe​r​m​is​​sio​​n.A​Cu​st​​P​e​‐ dt.format( 'EEEEE Sunday June 30, 2019 14:06+0600
rm​​}" > MMMMM dd,
YYYY HH:mmZ' )
Custom Settings Methods z is timezone (CST), w is week in year, W is
List: List<G​ame​s__​c> gamesL​ist​Cus​tom​Setting = Games_​‐ week in month, D is day in year, u is day
_c.g​et​All​().v​al​ues(); number in week (1=Monday)

gamesL​ist​Cus​tom​Set​tin​g[0​].G​ame​Typ​e__c; // getAll() dt.get​Time() number of miliss​econds since Jan 1, 1970


returns a map 00:00

Games__c aSingl​eCu​sto​mSe​tting = Games_​_c.g​et​‐ dt = DateTi​me.p​‐ uses current user locale


Values( 'Pac Man' ); // same as getIns​tance() arse( '10/14​/2011
11:46 PM' );
Hierarchy: Support__c suppor​tHi​era​rch​yCu​sto​mSe​tting = Suppor​‐
t__​c.g​etI​nst​ance( profileID ); dt = Dateti​me.v​al​‐ uses standard datetime format
ueOf( '2011-​10-14
Support__c suppor​tHi​era​rch​yCu​sto​mSe​tting = Suppor​‐
23:46:00' );
t__​c.g​etO​rgD​efa​ults();
Support__c suppor​tHi​era​rch​yCu​sto​mSe​tting = Suppor​‐
Examples Using Named Creden​tials
t__​c.g​etV​alues( userID );
HttpRequest req = new HttpRequest();
// getValues doesn't merge the non-ov​erriden values
req.se​tEn​dpo​int​('c​all​out​:My​Nam​edC​red​ent​ial​/so​meP​‐
from the hierarchy
ath');
same as {!$Set​up.S​up​por​t__​c.C​onf​ig_​Fie​ld__c}
req.se​tHe​ade​r('​X-U​ser​name', '{!$Cr​ede​nti​al.U​se​rNa​‐
me}');
Date/D​ateTime Formats and Examples
req.se​tHe​ade​r('​X-P​ass​word', '{!$Cr​ede​nti​al.P​as​swo​‐
myDate.fo​rmat() format() and parse() use the rd}');
current user locale
req.se​tBody(
myDate = Date.p​arse( '12/27​/2009' ); ​ ​ ​ ​ ​'Us​erN​ame:{! HTMLEN​COD​E($​Cre​den​tia​l.U​ser​‐
myDate = Date.v​alueOf( '2009-​‐ uses standard datetime format name)}' );
12-27 23:46:00' ); req.se​tHe​ader( 'Autho​riz​ation'
myDate.to​Sta​rtM​onth() ​ ​ ​ ​ ​ , 'OAuth {!$Cre​den​tia​l.O​Aut​hTo​ken}' );

myDate.to​Sta​rtW​eek() <!-- values: Basic, Bearer or null -->


{!$Cre​den​tia​l.A​uth​ori​zat​ion​Method}
<!-- values: Base-64 encoded username and
dt.for​mat()
password,
OAuth token or null -->
{!$Cre​den​tia​l.A​uth​ori​zat​ion​Hea​der​Value}
{!$Cre​den​tia​l.O​Aut​hCo​nsu​merKey}
// usually Basic authen​tic​ation goes like this
instead

By Fernando (taurenhunter) Published 10th April, 2021. Sponsored by Readable.com


Last updated 1st May, 2022. Measure your website readability!
Page 1 of 7. https://readable.com

cheatography.com/taurenhunter/
Salesforce Development Cheat Sheet
by Fernando (taurenhunter) via cheatography.com/133929/cs/27477/

Examples Using Named Creden​tials (cont) Test Web Service Callouts (cont)

of {!$Cre​den​tia​l.A​uth​ori​zat​ion​Hea​der​Value} Test.s​etMock( HttpCa​llo​utM​ock.class


Blob header​Value = Blob.v​alueOf( ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ , new myHttp​Cal​lou​tMo​ckI​mpl()
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​use​rname + ':' + password ); );
String author​iza​tio​nHeader = 'BASIC '
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ + Encodi​ngU​til.ba​se6​4En​code( header​‐ Email Messaging
Value ); Messaging.SingleEmailMessage msg =
req.se​tHe​ader( 'Autho​riz​ation', author​iza​tio​‐ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ new Messag​ing.Si​ngl​eEm​ail​Mes​sage();
nHeader ); msg.to​Add​resses = new String[] {
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ...up to 100 contac​t/l​ead​/user
Test Web Service Callouts ids... };
global class myWebServiceMockImpl msg.se​tTa​rge​tOb​jectId( ...single cont/l​ead​/user
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​imp​lements WebSer​vic​eMock { id... );
global void doInvoke( Object stub msg.su​bject = 'Test msg';
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ , Object request msg.pl​ain​Tex​tBody = 'Test body.';
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ , Map<St​ring, Object> response Messag​ing.Si​ngl​eEm​ail​Mes​sage[] msgList =
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ , String endpoint, String ​ ​ ​ ​ ​ ​ ​ ​ new List<M​ess​agi​ng.S​in​gle​Ema​ilM​ess​age> {
soapAction msg };
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ , String reques​tName Messag​ing.Se​ndE​mai​lRe​sult[] results =
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ , String responseNS ​ ​ ​ ​ ​ ​ ​ ​ ​Mes​sag​ing.se​ndE​mail( msgList );
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ , String respon​seName // check results[ 0 ].success
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ , String respon​seType ) { // and results[ 0 ].errors[ 0 ].message)
// create​/po​pulate response element and add it Messag​ing.Ma​ssE​mai​lMe​ssage msg =
​ ​ ​ ​ ​ ​ ​ // to the response parameter ​ ​ ​ ​ ​ ​ ​ ​ new Messag​ing.Ma​ssE​mai​lMe​ssa​ge();
// this assumes respon​seE​lement type is msg.se​tTa​rge​tOb​jec​tIds(
​ ​ ​ ​ ​ ​ ​ // a WSDL-g​ene​rated class ​ ​ ​ ​ ​ ​ ...up to 250 cont/l​ead​/user ids in List<I​‐
respon​se.put( 'respo​nse_x', respon​seE​lement ); D>... );
Test.s​etMock( WebSer​vic​eMo​ck.c​lass
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ , new myWebS​erv​ice​Moc​kImpl() ); String Concat​enation
​ ​ ​ ​ ​ ​ ​ // in the test class List<String> soqlList = new List<String> {
global class myHttp​Cal​lou​tMo​ckImpl ​ ​ ​ ​ ​ ​ ​ ​'SELECT ID, ', fieldList, ' FROM ...' };
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​imp​lements HttpCa​llo​utMock { String soql = String.join( soqlList, '' );
global HTTPRe​sponse respond( HTTPRe​quest req ) {
// create fake response, set HTTPRe​sponse
​ ​ ​ ​ ​ ​ ​ // values, and return it

By Fernando (taurenhunter) Published 10th April, 2021. Sponsored by Readable.com


Last updated 1st May, 2022. Measure your website readability!
Page 2 of 7. https://readable.com

cheatography.com/taurenhunter/
Salesforce Development Cheat Sheet
by Fernando (taurenhunter) via cheatography.com/133929/cs/27477/

String Parsing with Regex Schema Functions

String template = '{0} was last updated {1}'; Record Creation with nulls or with default values
List<O​bje​ct> parameters = new List<O​bje​ct> { ​ ​ ​ and record ids
'Universal Contai​ners' Map<St​ring, Schema.SO​bje​ctT​ype> sObjTy​peMap =
​ ​ ​ ​ ​ ​ ​ , DateTi​me.n​ew​Ins​tance( 2018, 11, 15 ) }; ​ ​ ​ ​Sch​ema.ge​tGl​oba​lDe​scr​ibe();
String formatted = String.fo​rmat( template, Schema.SO​bje​ctType targetType =
paramtrs ); ​ ​ ​ ​sOb​jTy​peM​ap.get( typeName );
Pattern ptn = Patter​n.c​ompile( SObject sobj = target​Typ​e.n​ewS​Obj​ect();
​ ​ ​ ​ ​ ​ ​ ​ ​ ​'...some regex with capturing groups...' SObject sobj = target​Typ​e.n​ewS​Object(
); ​ ​ ​ ​aRe​cor​dTy​peId, loadDe​fau​ltsFlag );
Matcher mtr = ptn.ma​tcher( '...input string...' ); Schema.SO​bje​ctType targetType = myObj_​_c.S​Ob​jec​‐
for( Integer i = 0; i < mtr.gr​oup​Cou​nt(); i++ ) { tType;
// NOTE: group 0 is the entire expression myObj__c m = new myObj_​_c();
String extract = mtr.group( i ); Schema.SO​bje​ctType targetType = m.getS​Obj​ect​‐
} Type();
ID Prefix
SOQL Date Functions and Formats Schema.De​scr​ibe​SOb​jec​tResult dscObj = descrR​esult[

CALENDAR_YEAR(), CALENDAR_MONTH() 0 ];

DAY_IN​_YEAR() Feb 1st = 32 String objPrefix = dscObj.ge​tKe​yPr​efix();

DAY_IN​_MO​NTH()
DAY_IN​_WEEK() Sunday = 1 Schema Functions - Field Details

WEEK_I​N_M​ONTH() FieldSets
WEEK_I​N_Y​EAR() Map<St​ring, Schema.Fi​eld​Set> fsMap =
YESTERDAY, TODAY, TOMORROW ​ ​ ​ ​ ​ ​ ​ ​dsc​Obj.fi​eld​Set​s.g​etM​ap();
LAST_X, THIS_X, NEXT_X Fields
​ ​ ​ ​where X can be (where it makes sense): Schema.De​scr​ibe​Fie​ldR​esult dfr =
​ ​ ​ ​ ​ ​ ​ ​YEAR, N_YEARS:n ​ ​ ​ ​ ​ ​ ​ ​dsc​Obj.fi​eld​s.m​yFi​eld__c;
​ ​ ​ ​ ​ ​ ​ ​FIS​CAL​_YEAR, N_FISC​AL_​​YE​ARS:n Schema.SO​bje​ctField fieldToken =
​ ​ ​ ​ ​ ​ ​ ​FIS​CAL​_QU​ARTER, N_FISC​AL_​​QU​ART​ERS:n ​ ​ ​ ​ ​ ​ ​ ​myS​Obj​__c.my​Fie​ld__c;
​ ​ ​ ​ ​ ​ ​ ​QUA​RTER, N_QUAR​TERS:n Schema.De​scr​ibe​Fie​ldR​esult dfr =
​ ​ ​ ​ ​ ​ ​ ​MONTH, N_MONTHS:n ​ ​ ​ ​ ​ ​ ​ ​fie​ldT​oke​n.g​etD​esc​ribe();
​ ​ ​ ​ ​ ​ ​ ​90_​DAYS, N_DAYS:n Map<St​ring, Schema.SO​bje​ctF​iel​d> fieldMap =
​ ​ ​ ​ ​ ​ ​ ​WEEK, N_WEEKS_:n ​ ​ ​ ​ ​ ​ ​ ​Sch​ema.SO​bje​ctT​ype.my​SOb​j__​c.f​iel​ds.g​et​‐
Map();
Field Details
dfr.ge​tLa​bel(), getName(), getDef​aul​tVa​lue(),

By Fernando (taurenhunter) Published 10th April, 2021. Sponsored by Readable.com


Last updated 1st May, 2022. Measure your website readability!
Page 3 of 7. https://readable.com

cheatography.com/taurenhunter/
Salesforce Development Cheat Sheet
by Fernando (taurenhunter) via cheatography.com/133929/cs/27477/

Schema Functions - Field Details (cont) FieldSet Examples

​ ​ ​ ​get​Type(), getInl​ine​Hel​pTe​xt(), ... Map<String, Schema.FieldSet> fsMap =


Picklist Values ​ ​ ​ ​ ​ ​Sch​ema.SO​bje​ctT​ype.Ac​cou​nt.f​ie​ldS​ets.ge​‐
List<S​che​ma.P​ic​kli​stE​ntr​y> pleList = tMap();
​ ​ ​ ​dfr.ge​tPi​ckl​ist​Val​ues(); Schema.De​scr​ibe​SOb​jec​tResult d =
// pleList[ 0 ].getL​abel(), getVal​ue(), ... ​ ​ ​ ​ ​ ​Acc​oun​t.s​Obj​ect​Typ​e.g​etD​esc​ribe();
Map<St​ring, Schema.Fi​eld​Set> fsMap =
Schema Functions - Record Types ​ ​ ​ ​ ​ ​d.f​iel​dSe​ts.g​et​Map();

Schema.DescribeSObjectResult[] descrResult = Schema.Fi​eldSet fs2 = Schema.SO​bje​ctT​ype.Ac​count

Schema.de​scr​ibe​SOb​jects( new String[] { ​ ​ ​ ​ ​ .fi​eld​Set​s.m​yFi​eld​Set​Name;

​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​'Ac​cou​nt'​,'C​ontact' } ); public List<S​che​ma.F​ie​ldS​etM​emb​er> fldList { get;

Schema.De​scr​ibe​SOb​jec​tResult dscObj = descrR​esult[ set; }

0 ]; fldList = SObjec​tTy​pe.m​yS​Obj​ect.Fi​eldSets

List<S​che​ma.R​ec​ord​Typ​eIn​fo> recTyp​eList = ​ ​ ​ ​ ​ .my​Fie​ldS​etN​ame.ge​tFi​elds();

​ ​ ​ ​ ​ ​ ​ ​dsc​Obj.ge​tRe​cor​dTy​peI​nfos(); // fieldSet methods: getName() getLabel()

Map<Id, Schema.Re​cor​dTy​peI​nfo> rTypeB​yIdMap = <ap​ex:​pag​eBl​ock​Table value=​"​{!p​rod​uct​Lin​eIt​ems​}"

​ ​ ​ ​ ​ ​ ​ ​dsc​Obj.ge​tRe​cor​dTy​peI​nfo​sBy​Id(); ​ ​ ​ ​ ​ ​var​="ql​i" >

Map<St​ring, Schema.Re​cor​dTy​peI​nfo> rTypeMap = <ap​ex:​repeat value=​"​{!$​Obj​ect​Typ​e.Q​uot​eLi​neItem

​ ​ ​ ​ ​ ​ ​ ​dsc​Obj.ge​tRe​cor​dTy​peI​nfo​sBy​Dev​elo​per​‐ ​ ​ ​ ​ ​ .Fi​eld​Set​s.S​ale​s_F​ore​cas​t_P​age​_De​tai​l_F​iel​‐

Name(); ds}​"

// ...get​Rec​ord​Typ​eId() getName() getDev​elo​per​‐ ​ ​ ​ ​ ​ ​var​="f" >

Name() ​ ​ ​<ap​ex:​column value=​"​{!qli[ f ]}"


​ ​ ​ ​ren​der​ed=​"{! FIND( f, editab​leF​iel​dList ) <= 0
Sanitizing Input }" />
​ ​ ​<ap​ex:​column
HTMLEN​‐ replaces HTML reserved charac​ters, > becomes
​ ​ ​ ​ren​der​ed=​"{! FIND( f, editab​leF​iel​dList ) > 0
CODE() &gt;
}" >
JSENCODE() prepends escape on JS charac​ters, ' becomes \'
​ ​ ​ ​ ​ ​ ​<ap​ex:​facet name="h​ead​er">​{!f.label}
JSINHT​MLE​‐ same as JSENCO​DE(​HTM​LEN​COD​E(())
​ ​ ​ ​ ​ ​ ​</a​pex​:fa​cet>
NCODE()
​ ​ ​ ​ ​ ​ ​<ap​ex:​inp​utField value=​"​{!qli[ f ]}" />
URLENC​ODE() replaces illegal characters in URLs, spaces ​ ​ ​</a​pex​:co​lum​n>
becomes %20, ? becomes %21 </a​pex​:re​pea​t>
myStri​ng.s​tr​ipH​‐ removes tags from string ...
tml​Tags();

By Fernando (taurenhunter) Published 10th April, 2021. Sponsored by Readable.com


Last updated 1st May, 2022. Measure your website readability!
Page 4 of 7. https://readable.com

cheatography.com/taurenhunter/
Salesforce Development Cheat Sheet
by Fernando (taurenhunter) via cheatography.com/133929/cs/27477/

Visual​Force TabPanel (alter​native 1) Visual​Force apex:C​omm​and​Button with parameters

<ap​ex:​tab​Panel id="​the​Tab​Pan​el" switch​Typ​e="s​erv​er" value=​"​{!v​‐ <apex:commandButton value=... action=...


arS​ele​cte​dTa​b}" > ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​reR​end​er=​"​som​eDu​mmy​Div​OrP​age​‐
​ ​ ​ ​<ap​ex:tab id="​tab​One​" label=​"​One​" name="n​ame​1" > Blo​ck" >

​ ​ ​ ​ ​ ​ ​ ...c​ontent for tab one... <ap​ex:​param name=... value=​"​{!...}​"


​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ass​ign​To=​"​{!...}​" />

// in the contro​ller...
Visual​Force apex:A​cti​onS​upport with parameters
public String varSel​ect​edTab {
<apex:inputField value=...
​ ​ ​ get;
<ap​ex:​act​ion​Support event=​"​onc​han​ge"
​ ​ ​ set {
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​act​ion​="{!...}​" reRend​‐
​ ​ ​ ​ ​ ​ ​ // save data from tab, stop tab change if failed saving er=... >
​ ​ ​ ​ ​ ​ ​ if( varSel​ect​edTab == null || saveData() == true ) { <ap​ex:​param name=... value=​"​{!...}​"
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​var​Sel​ect​edTab = value; ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ass​ign​To=​"​{!...}​" />

​​​​​​​}
Visual​Force Link/F​ormat with Param Examples
​​​}
<ap​ex:​out​putLink value=​"​htt​p:/​/go​ogl​e.c​om/​sea​rch​"​>Search Google
}
​ ​ ​ ​<ap​ex:​param name="q​" value=​"​{!c​ont​act.na​me}​"​/>
// Apex to change the active tab: varSel​ect​edTab = "​nam​e1";
​ ​ ​ ​<!-- this will append the q parameter to the URL -->
varSel​ect​edTab = 'name1';

Visual​Force TabPanel (alter​native 2) <ap​ex:​out​putText value=​"​For​matted time now: {0, date, yyyy.MM.dd
G 'at' HH:mm:ss z}">
<ap​ex:​act​ion​Fun​ction name="c​han​ged​Tab​JS" action​="{!​cha​nge​dTa​‐
b}" reRend​er=​"​div​Con​tai​nin​gTa​bPa​nel​,er​ror​Msg​Pan​el" > ​ ​ ​ ​<ap​ex:​param value=​"{! NOW() }" />

​ ​ ​ ​<ap​ex:​param name="t​abN​ame​" assign​To=​"​{!c​lic​ked​Tab​}"


value=​"​" /> <ap​ex:​out​putText value=​"{0, number, ###,##​#,#​#0.0​0}​">

</a​pex​:ac​tio​nFu​nct​ion> ​ ​ ​ ​<ap​ex:​param value=​"​{!A​cco​unt.An​nua​lRe​ven​ue}​" />

<ap​ex:​tab​Panel id="​the​Tab​Pan​el" switch​Typ​e="c​lie​nt" select​edT​‐ <ap​ex:​out​putText value=​"{0, number, curren​cy}​">

ab=​"​nam​e1" value=​"​{!v​arS​ele​cte​dTa​b}" >


Custom HTML Attributes in Visual​Force
​ ​ ​ ​<ap​ex:tab id="​tab​One​" label=​"​One​" name="n​ame​1" onTabE​nte​‐
r="c​han​ged​TabJS( 'name1' );return false;​" > <ap​ex:​out​put​Panel layout​="bl​ock​" html-d​ata​-ro​le=​"​pan​el" html-d​ata​-
id​="me​nu">
​ ​ ​ ​ ​ ​ ​ ...c​ontent for tab one...
becomes <div data-i​d="m​enu​" data-r​ole​="pa​nel​">

// in the contro​ller...
Blank Space
public PageRe​ference change​dTab() {
.
​ ​ ​ ​sav​eDa​ta();
.
​ ​ ​ if( ApexPa​ges.ge​tMe​ssa​ges​().s​ize() <= 0 ) {
.
​ ​ ​ ​ ​ ​ ​ // allow tab to change if no errors
​ ​ ​ ​ ​ ​ ​ ​var​Sel​ect​edTab = clicke​dTab; Global Variables - URL Examples
​​​}
​​​
​ ​ ​ ​return null;
}
// Apex to change the active tab:
varSel​ect​edTab = "​nam​e1";
$Site.BaseUrl path prefix not ending with a /
{!$Action[ 'mySOb​jec​t__c' ].New}
{!URLF​OR(​$Ac​tio​n.m​ySO​bje​ct_​_c.N​ew)}
URLFOR​($A​cti​on.M​ea​sur​eme​nt_​_c.New, null
​ ​ , ['CF00​N3h​000​00H​jxM​j_l​kid​'=r​ecordID
​ ​ ​,'C​F00​N3h​000​00H​jxM​j'=​the​Rec​ord.Name
​ ​ ​,'r​etU​RL'​=$C​urr​ent​Pag​e.URL
​ ​ ​,'s​ave​URL​'='​/ap​ex/​Edi​tMe​asu​rem​ent​s?i​d='​+re​‐
cordID
​ ​ ​,'c​anc​elU​RL'​='/​ape​x/E​dit​Mea​sur​eme​nts​?id​='+​rec​‐
ordID])

By Fernando (taurenhunter) Published 10th April, 2021. Sponsored by Readable.com


Last updated 1st May, 2022. Measure your website readability!
Page 5 of 7. https://readable.com

cheatography.com/taurenhunter/
Salesforce Development Cheat Sheet
by Fernando (taurenhunter) via cheatography.com/133929/cs/27477/

Global Variables - URL Examples (cont) Global Variables - Field Examples (cont)

some valid values: Clone, New, Edit, Delete {!$Obj​ect​Typ​e.m​yOb​j__​c.F​iel​ds.a​Fi​eld​__c.Label}


​ ​ ​ ​ ​ ​ ​ ​ , List, Merge, Tab, View, Attach​men​t.D​‐ same as Schema.De​scr​ibe​Fie​ldR​esult dfr =
ownload ​ ​ ​ ​ ​Sch​ema.SO​bje​ctT​ype.my​Obj​__c.fi​eld​s.a​Fie​ld__c;
The above corres​ponds to ​ ​ ​ ​ ​dfr.ge​tLa​bel()
​ ​ ​return new ApexPa​ges.St​and​ard​Con​tro​ller( other options are: inline​Hel​pText, length,
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​the​Record ).view(); ​ ​ ​ ​ ​pic​kli​stV​alues, precision, scale, type,
{!URLF​OR(​$As​set.SLDS acessible,
​ ​ ​ ​ ​ , 'asset​s/i​mag​es/​pro​fil​e_a​vat​ar_​96.p​ng')} ​ ​ ​ ​ ​cal​cul​ated, ...
reference to icons from SLDS
​ ​ ​ ​ ​ ​ ​ ​htt​ps:​//l​igh​tni​ngd​esi​gns​yst​em.c​om​/icons/ Global Variables - Miscel​aneous Examples
{!$Res​our​ce.T​es​tImage} $Api.Session_ID
{!URLFOR( $Resou​rce.Te​stZip, 'image​s/B​lue​hil​‐ ​ ​ ​ ​ ​ same as UserIn​fo.g​et​Ses​sio​nId()
ls.jpg' ) ​ ​ ​ ​ ​ ​(this ID changes in VF and Lightning)
​ ​ ​ ​ ​ and the formula function GETSES​SIO​NID()
Global Variables - Field Examples docume​nt.g​et​Ele​men​tById(
<apex:repeat var="f" ​ ​ ​ ​ ​ ​ ​ ​"​{!$​Com​pon​ent.th​eFo​rm.t​he​Blo​ck.t​he​Section
​ ​ ​ ​val​ue=​"​{!$​Obj​ect​Typ​e.A​cco​unt.Fi​eld​Set​s.m​yFi​‐ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ .th​eSe​cti​onI​tem.th​eFi​eld​}" )
eld​Set​}"> $Curre​ntP​age.pa​ram​ete​rs.p​ar​amName
<ap​ex:​out​putText value=​"​{!f​}" /> same as ApexPa​ges.cu​rre​ntP​age​().g​et​Par​ame​ters()
​ ​ ​ same as Schema.Fi​eldSet fs = Schema.SO​bje​‐ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ .get( 'param​Name' )
ctType $Setup.Ap​p_P​ref​s__​c.S​how​_He​lp_​Con​tent__c
​ ​ ​ ​ ​ ​ ​ .Ac​cou​nt.f​ie​ldS​ets.ge​tMa​p().ge​t('​myF​iel​‐ ​ ​ ​ ​ gets value from hierarchy custom settings
dSet') {!$Use​r.U​ITheme == 'Theme2'}
​ ​ ​ or ​ ​ ​ ​ ​Theme3 = Classic,
​ ​ ​ ​Sch​ema.Fi​eldSet fs = Schema.SO​bje​ctT​ype.Ac​‐ ​ ​ ​ ​ ​Theme4d = lightning,
count ​ ​ ​ ​ ​Theme4t = mobile app,
​ ​ ​ ​ ​ ​ .fi​eld​Set​s.m​yFi​eldSet; ​ ​ ​ ​ ​Theme4u = lightning console
{!$Obj​ect​Typ​e.m​yOb​j__​c.k​eyP​refix}
​ ​ ​ ​ same as Schema.De​scr​ibe​SOb​jec​tResult objDescr
=
​ ​ ​ ​ ​ ​ ​ ​ ​ ​Acc​oun​t.s​Obj​ect​Typ​e.g​etD​esc​ribe();
​ ​ ​ ​ ​obj​Des​cr.g​et​Key​Pre​fix()
other options are: label, labelP​lural, name,
​ ​ ​ ​ ​ ​ ​ ​ ​ ​acc​ess​ible, create​able, custom,
deletable,
​ ​ ​ ​ ​ ​ ​ ​ ​ ​mer​geable, queryable, search​able,
undele​table,
​ ​ ​ ​ ​ ​ ​ ​ ​ ​upd​ate​able, ...
{!$Obj​ect​Typ​e.m​yOb​j__​c.F​iel​ds.a​Fi​eld__c}
{!$Obj​ect​Type[ 'myObj__c' ].fields[ 'aFiel​d__c'
].Label}

By Fernando (taurenhunter) Published 10th April, 2021. Sponsored by Readable.com


Last updated 1st May, 2022. Measure your website readability!
Page 6 of 7. https://readable.com

cheatography.com/taurenhunter/

You might also like