VsCode中的Apex自定义代码片段!
程序员文章站
2024-03-23 20:28:16
...
VsCode中的Apex自定义代码片段!
今天博主跟大家聊一聊如何使用VsCode中的Apex自定义代码片段!不喜勿喷,如有建议欢迎补充、讨论!
关于安装和汉化可以观看博主的这篇文章《下载安装及汉化 》,安装完毕重启VsCode!
來了
1. 文件 => 首选项 => 用户代码片段
2. 选择你需要新建的代码片段的语言(我们这里输入apex进入apex.json)
3. 进入代码片段编辑界面
键入一下代码你想要的应有尽有(调用方式prefix的值打出来回车即可)
{
//For List
"List_Apex": {
"prefix": "List<",
"body": [
"List<${1:object}> ${2:lstName} = new List<${1}>();"
],
"description": "List of sObjects(list 快捷)"
},
// for set
"Set_Apex": {
"prefix": "Set<",
"body": [
"Set<${1:object}> ${2:setName} = new Set<${1}>();"
],
"description": "Set of sObjects(Set 快捷)"
},
// for map
"Map_Apex": {
"prefix": "map<",
"body": [
"map<${1:object}, ${2:object}> ${3:mapName} = new map<${1}, ${2}>();"
],
"description": "Map of sObjects (Map 快捷)"
},
// for each loop
"For_Loop_Apex": {
"prefix": "for",
"body": [
"for (${2:element} ${3:iteratorName} : ${1:array}) {",
"\t$0",
"}"
],
"description": "For Loop(for 快捷)"
},
// if condition
"if_cond_Apex": {
"prefix": "if",
"body": ["if ($1) {\n $0\n}"],
"description": "if statement for apex(if 快捷)"
},
// soql apex
"soql_Apex": {
"prefix": "soql",
"body": ["List<$1> $2 = [SELECT $3 $0 FROM $1];"],
"description": "SOQL query assignment to List variable(SOQL 快捷)"
},
// Get on the same day
"Date_todat_Apex": {
"prefix": "datet",
"body": ["Date today = date.today();"],
"description": "Get today!(获得today 快捷)"
},
// Gets an empty string
"string_n_Apex": {
"prefix": "strn",
"body": ["String emptys = '';"],
"description": "Gets an empty string!(获得一个为空的字符串 快捷)"
},
// If a value is null
"if_value_null_Apex": {
"prefix": "ifnull",
"body": ["if ( XXX.isEmpty() ) return false;"],
"description": "If a value is null!(判断某个值为空返回false 快捷)"
},
// Change to the sysout form of Java
"sysout_Apex": {
"prefix": "sysout",
"body": ["System.debug( 'XXXXX-->' );"],
"description": "Change to the sysout form of Java!(用sysout打印 快捷)"
},
}
好了快去试试吧!光看不试等于白搭
最后
-
更多参考精彩博文请看这里:陈永佳的博客
-
喜欢博主的小伙伴可以加个关注、点个赞哦,持续更新嘿嘿!
上一篇: OC 类工厂及类的本质和启动过程