Code snippets for Salesforce (Apex) for Vs Code editor. Additional useful code snippets not included in the Salesforce Extension Pack and improved syntax of some that are.
- Launch VS Code Quick Open
Ctrl
-P
(Windows, Linux) orCmd
-P
(OSX) - paste
ext install lcotter.salesforce-snippets
and press enter.
or
- Search for Salesforce Snippets in the extensions market place and install it.
- Apex (.cls)
To use the snippets type part of a snippet and press Tab
or Enter
or, press ctrl
+Space
to activate instellisense.
Snippet | Description |
---|---|
foreach |
For-each loop |
formap |
For loop for entries in a map |
ifelse |
if/else statement |
ifnull |
if statement null check |
ifnotnull |
if statement not null check |
ter |
x ? y : z |
constructor |
New constructor |
newobj |
New Object |
field |
New field |
method |
New method |
staticmethod |
New static method |
setidsfromrecordlist |
Set of Ids from List of records |
mapfromrecordlist |
Map from List of records |
sobjecttype |
SObjectType for SObject |
describesobjectresult |
DescribeSObjectResult for SObjectType |
sobjectfield |
SObjectField for SObject Field |
describefieldresult |
DescribeFieldResult for SObject Field |
sysdebug |
Debug Statement |
sysassf |
System.assert(false, message); |
sysasseq |
System.assertEquals(expected, actual); |
sysassnull |
System.assertEquals(null, actual); |
sysassnotnull |
System.assertNotEqual(null, actual); |
testmethod |
Test method |