Documente Academic
Documente Profesional
Documente Cultură
Cheatsheet
Overview
Apex code is a strongly-typed programming language that executes on the Force.com platform. Using Apex code, you can add business logic to
applications, write database triggers, and create Visualforce controllers. Apex code has a tight integration with the database and query language, web
services, and email handling support. It also includes features such as asynchronous execution and support for testing.
Blob Binary data Blob myBlob = String Set of characters String s = 'repeating memes';
Blob.valueof('idea');
stored as surrounded by
a single object single quotes
Boolean Value that can Boolean isWinner = true; Object Any data String s = 'repeating memes';
only be assigned type that is
true, false, supported i
or null n Apex
Date Particular day Date myDate = Date.today(); Time Particular time Object obj = 10;
Date weekStart = // Cast the object to an integer.
myDate.toStartofWeek(); Integer i = (Integer)obj;
System.assertEquals(10, i);
Datetime Particular day Datetime myDateTime =
Datetime.now(); Object obj = new MyApexClass();
and time // Cast the object to the
Datetime newDateTime =
myDateTime.addMonths(2); // MyApexClass custom type.
MyApexClass mc = (MyApexClass)obj;
// Access a method on the
Decimal Number that Decimal myDecimal = 12.4567; // user-defined class.
Decimal divDec = myDecimal.divide
includes a mc.someClassMethod();
(7, 2, System.RoundingMode.UP);
decimal point. system.assertEquals(divDec, 1.78);
Decimal is
an arbitrary
precision Trigger Context Variables
number.
Variable Operators
Double 64-bit number Double d=3.14159;
that includes a isExecuting Returns true if the current context for the Apex code
decimal point. is a trigger only
Minimum value
-263. Maximum isInsert Returns true if this trigger was fired due to an insert
value of 263-1 operation
ID 18-character ID id='00300000003T2PGAA0'; isUpdate Returns true if this trigger was fired due to an update
Force.com operation
record identifier
isDelete Returns true if this trigger was fired due to a delete
Integer 32-bit number Integer i = 1; operation
that doesnt
include a isBefore Returns true if this trigger was fired before any record
decimal point. was saved
Minimum value
-2,147,483,648 isAfter Returns true if this trigger was fired after all records
maximum were saved
value of
2,147,483,647 isUndelete Returns true if this trigger was fired after a record was
recovered from the Recycle Bin
Long 64-bit number Long l = 2147483648L;
that doesnt new Returns a list of the new versions of the sObject
include a records.(This sObject list is available only in insert
decimal point. and update triggers. The included records can be
Minimum modified only in before triggers.)
value of -263
maximum value newMap A map of IDs to the new versions of the sObject
of 263-1. records. (Only available in before update, after
insert, and after update triggers.)
Object Any data Object obj = 10;
// Cast the object to an integer. old Returns a list of the old versions of the sObject
type that is
Integer i = (Integer)obj; records. (Only available in update and delete
supported in System.assertEquals(10, i); triggers.)
Ape
Object obj = new MyApexClass();
// Cast the object to the oldMap A map of IDs to the old versions of the sObject
// MyApexClass custom type. records. (Only available in update and delete
MyApexClass mc = (MyApexClass) triggers.)
obj;
// Access a method on the
// user-defined class. size The total number of records in a trigger invocation,
mc.someClassMethod(); both old and new.
Apex Code Cheatsheet
DescribeSObjectResult Class
Limits Class
fields fieldSets
getChildRelationships getKeyPrefix getAggregateQueries getLimitAggregateQueries
getLabel getLabelPlural getAsyncCalls getLimitAsyncCalls
getLocalName getName getCallouts getLimitCallouts
getRecordTypeInfos getRecordTypeInfosByID getCpuTime getLimitCpuTime
getSobjectType isAccessible getDMLRows getLimitDMLRows
getDMLStatements getLimitDMLStatements
getRecordTypeInfosByName isCreateable
getEmailInvocations getLimitEmailInvocations
isCustom isCustomSetting
getFutureCalls getLimitFutureCalls
isDeletable isDeprecatedAndHidden
getHeapSize getLimitHeapSize
isFeedEnabled isMergeable
getMobilePushApexCalls getLimitMobilePushApexCalls
isQueryable isSearchable getQueries getLimitQueries
isUndeletable isUpdateable getQueryLocatorRows getLimitQueryLocatorRows
Schema.RecordTypeInfo rtByName = getQueryRows getLimitQueryRows
rtMapByName.get(rt.name); getQueueableJobs getLimitQueueableJobs
Schema.DescribeSObjectResult d = getSoslQueries getLimitSoslQueries
Schema.SObjectType.Account;
UserInfo Class
getDefaultCurrency getFirstName
getLanguage getLastName
getLocale getName
getOrganizationId getOrganizationName
getProfileId getSessionId
getTimeZone getUiTheme
getUiThemeDisplayed getUserEmail
getUserId getUserName
getUserRoleId getUserType
isCurrentUserLicensedq isMultiCurrencyOrganization
developer.salesforce.com