Skip to content

Instantly share code, notes, and snippets.

@jstvz
Created February 2, 2018 18:48
Show Gist options
  • Save jstvz/b1c716a1682f249b3019d1eeb1002e04 to your computer and use it in GitHub Desktop.
Save jstvz/b1c716a1682f249b3019d1eeb1002e04 to your computer and use it in GitHub Desktop.
Apex Snippets for Visual Studio Code (VSCode)
{
/*
// Place your snippets for Apex here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [
"console.log('$1');",
"$2"
],
"description": "Log output to console"
}
*/
"ni": {
"prefix": "ni",
"body": [
"$1 $2 = new $1();"
],
"description": "Construct a new variable and assign the result to a variable"
},
"sqv": {
"prefix": "sqv",
"body": "List<$1> $2 = [\n SELECT $3$0 \n FROM $1\n ];",
"description": "SOQL query assignment to List variable"
},
"sqm": {
"prefix": "sqm",
"body": "Map<Id, $1> $2 = new Map<Id, $1>([\n SELECT Id, $3$0 \n FROM $1\n ]);",
"description": "SOQL query assignment to Map variable"
},
"sqit": {
"prefix": "sqit",
"body": "for ($1 $2 : [\n SELECT $3$0 \n FROM $1\n ]\n ) {\n \n}",
"description": "Iterate SOQL query results"
},
"instt": {
"prefix": "instt",
"body": "if ($3 instanceof $1) {\n $1 $2 = ($1) $3;\n $0\n}",
"description": "Checks object type with instanceof and down-casts it"
},
"if": {
"prefix": "if",
"body": "if ($1) {\n $0\n}",
"description": "if"
},
"prwf": {
"prefix": "prwf",
"body": "{ \n get {\n $1\n }\n set {\n $2\n }\n}$0",
"description": "Read / write property getter and setter"
},
"tahe": {
"prefix": "tahe",
"body": "throw new AuraHandledException($0);",
"description": "Throw AuraHandledException"
},
"ahe": {
"prefix": "ahe",
"body": "AuraHandledException",
"description": "Insert AuraHandledException"
},
"nmj": {
"prefix": "nmj",
"body": "Map<String, Object> $1 = (Map<String, Object>) JSON.deserializeUntyped($0);",
"description": "Deserialize a JSON string into a new Map and assign the result to a variable"
},
"sdjs": {
"prefix": "sdjs",
"body": "System.debug(JSON.serializePretty($0));",
"description": "JSON serialize pretty"
},
"jsp": {
"prefix": "jsp",
"body": "JSON.serializePretty($0)",
"description": "JSON serialize pretty"
},
"ifmg": {
"prefix": "ifmg",
"body": "if ($1.containsKey($2)) {\n $3 $2 = $1.get($2);\n $0\n}\n\n}",
"description": "If Map contains key then get"
},
"ifm": {
"prefix": "ifm",
"body": "if ($1.containsKey($2)) {\n $0\n}\n\n}",
"description": "If Map contains key"
},
"mife": {
"prefix": "mife",
"body": "if ($1.containsKey($2)) {\n $0\n} else {\n\n}",
"description": "Map contains key if / else"
},
"sd": {
"prefix": "sd",
"body": "System.debug($0);",
"description": "Debug logging with System.debug()"
},
"pvtm": {
"prefix": "pvtm",
"body": "private $1 $2($3) {\n $0\n}\n",
"description": "Create private method"
},
"pvsm": {
"prefix": "pvsm",
"body": "private static $1 $2($3) {\n $0\n}\n",
"description": "Create private static method"
},
"tstm": {
"prefix": "tstm",
"body": "@isTest\nstatic void $2() {\n $0\n}\n",
"description": "Create test method"
},
"tst": {
"prefix": "tst",
"body": "Test.startTest();\n$0\nTest.stopTest();",
"description": "Test start/stop system static methods"
},
"tssu": {
"prefix": "tssu",
"body": "@testSetup static void $2() {\n $0\n}\n",
"description": "Create test setup method"
},
"dcom": {
"prefix": "dcom",
"body": "/**\n * $0\n */",
"description": "Doc Comment"
},
"pvsmc": {
"prefix": "pvsmc",
"body": "/**\n * $COMMENT$\n */\nprivate static $1 $2($3) {\n $0\n}\n",
"description": "Create private static method with comment"
},
"pvtmc": {
"prefix": "pvtmc",
"body": "/**\n * $COMMENT$\n */\nprivate $KEYWORD$ $1 $2($3) {\n $0\n}\n",
"description": "Create private method with comment"
},
"tstmc": {
"prefix": "tstmc",
"body": "/**\n * $COMMENT$\n */\n@isTest\nstatic void $2() {\n $0\n}\n",
"description": "Create test method with comment"
},
"pusm": {
"prefix": "pusm",
"body": "public static $1 $2($3) {\n $0\n}\n\n",
"description": "Create public static method"
},
"pubm": {
"prefix": "pubm",
"body": "public $1 $2($3) {\n $0\n}\n",
"description": "Create public method"
},
"puvm": {
"prefix": "puvm",
"body": "public void $1($2) {\n $0\n}\n",
"description": "Create public void method"
},
"dbin": {
"prefix": "dbin",
"body": "List<Database.SaveResult> saveResults = Database.insert($1, $2);\nfor(Database.SaveResult result : saveResults) {\n if (result.isSuccess) {\n $0\n } else {\n \n }\n}",
"description": "Insert and iterate over SaveResults"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment