ããã«ã¡ã¯ãåè°·(id:a-kura)ã§ãã
ä»å¹´ããã¤ã®ã¾ã«ãã¢ããã³ãã«ã¬ã³ãã¼ã®ææã«ãªã£ã¦ãã¾ãã¾ãããçãã¾ãããããéããã§ããããï¼
ãã¦ãSalesforce DX CLI ã®ç´¹ä»ã§ã¯ã権éã»ããã®ä»ä¸ããã¼ã¿ãã¼ãããã¢ããã¦ãã¾ããããå®ã¯ããä¸ã¤éè¦ãªæ©è½ãããã¾ãã
ãããä»»æã® Apex ãå®è¡ã§ããæ©è½ã§ãã
ä»åã¯ãSalesforce DX CLI ã使ã£ã¦ã Apex ãå®è¡ããæ¹æ³ã«ã¤ãã¦ç´¹ä»ãããã¨æãã¾ãã
ãã«ã
ã¾ãã¯ãApex ã³ã¼ããå®è¡ããããã®ã³ãã³ãã®ãã«ããåç §ãã¾ããä¸è¨ã®ã³ãã³ããå®è¡ããã¨ããã«ãã表示ã§ãã¾ããä»ã®ã³ãã³ãã調ã¹ãã¨ããåæ§ãªã®ã§è¦ãã¦ããã¨å½¹ç«ã¡ã¾ãã
$ sfdx help force:apex:execute Usage: sfdx force:apex:execute [-f <file>] [-u <string>] [--json] [--loglevel <string>] execute anonymous Apex code Flags: -f, --apexcodefile APEXCODEFILE path to a local file containing Apex code -u, --targetusername TARGETUSERNAME username or alias for the target org; overrides default target org --json format output as json --loglevel LOGLEVEL logging level for this command invocation (error*,trace,debug,info,warn,fatal) Executes one or more lines of Apex code, or executes the code in a local file. Before you enter code, run this command with no parameters to get a prompt. From the prompt, all commands are executed in a single execute anonymous request. For more information, see "Anonymous Blocks" in the Apex Developer Guide. Examples: $ sfdx force:apex:execute -f ~/test.apex $ sfdx force:apex:execute >> Start typing Apex code. Press the Enter key after each line, >> then press CTRL+D when finished.
ã³ãã³ãã©ã¤ã³ãã Apex ã³ã¼ããå ¥åãã¦å®è¡ãã
ã§ã¯ãã³ãã³ãã©ã¤ã³ãã ç´æ¥ Apex ã³ã¼ããå ¥åãã¦å®è¡ãã¦ã¿ã¾ãããã èªè¨¼ãæ¸ã¾ãããã¨ãå ã»ã©ã®ãã«ãã§åç §ããå 容ãåèã«å®è¡ãã¦ã¿ã¾ãã
$ sfdx force:apex:execute
ã³ãã³ããå®è¡ããã¨ãä¸è¨ã®ãããªã¡ãã»ã¼ã¸ã表示ããã¦ãå ¥åå¾ ã¡ã«ãªãã¾ãã
>> Start typing Apex code. Press the Enter key after each line, >> then press CTRL+D when finished.
ä¸è¨ã®ããã«é©å½ãª Apex ã³ã¼ããå ¥åãã¦ãCTRL+D ãæ¼ä¸ãã¾ãã
System.debug('Hello, Astro!');
ããããã¨ãå®è¡çµæã表示ããã¾ãã å®è¡çµæã®å 容ãè¦ãã¨ãéçºè ã³ã³ã½ã¼ã«ããå®è¡ããã¨ãã®ãã°ã¨åããã®ã表示ããã¦ãããã¨ããããã¾ãã
Compiled successfully. Executed successfully. 41.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO Execute Anonymous: System.debug('Hello, Astro!'); 23:41:42.11 (11567895)|USER_INFO|[EXTERNAL]|005xxxxxxxxxxxxxx|[email protected]|æ¥æ¬æ¨æºæ|GMT+09:00 23:41:42.11 (11592457)|EXECUTION_STARTED 23:41:42.11 (11597237)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex 23:41:42.11 (12249513)|USER_DEBUG|[1]|DEBUG|Hello, Astro! 23:41:42.12 (12311326)|CUMULATIVE_LIMIT_USAGE 23:41:42.12 (12311326)|LIMIT_USAGE_FOR_NS|(default)| Number of SOQL queries: 0 out of 100 Number of query rows: 0 out of 50000 Number of SOSL queries: 0 out of 20 Number of DML statements: 0 out of 150 Number of DML rows: 0 out of 10000 Maximum CPU time: 0 out of 10000 Maximum heap size: 0 out of 6000000 Number of callouts: 0 out of 100 Number of Email Invocations: 0 out of 10 Number of future calls: 0 out of 50 Number of queueable jobs added to the queue: 0 out of 50 Number of Mobile Apex push calls: 0 out of 10 23:41:42.12 (12311326)|CUMULATIVE_LIMIT_USAGE_END 23:41:42.11 (12348943)|CODE_UNIT_FINISHED|execute_anonymous_apex 23:41:42.11 (13282152)|EXECUTION_FINISHED
ãã¡ã¤ã«ãã Apex ã³ã¼ããå®è¡ãã
次ã«ãApex ã³ã¼ããä¿åãããã¡ã¤ã«ãã Apex ã³ã¼ããå®è¡ãã¦ãã¾ãããã ã¾ãã¯ãå®è¡ããããã® Apex ã³ã¼ããæºåãã¾ãã
ããã§ã¯ãApex ã³ã¼ããå®è¡ã§ããã試ãããã ããªã®ã§ãå ã»ã©ã¨åãã³ã¼ãããã¡ã¤ã«ã«ä¿åãã¾ãã
HelloAstro.apex
System.debug('Hello, Astro!');
å ã»ã©ã®ãã«ãã®ã¨ããããã¡ã¤ã«ãæå®ããå ´åã¯ã--apexcodefileãã¾ãã¯ã-fãã®ãã¨ã«ãã¡ã¤ã«åãå ¥åãã¾ãã
$ sfdx force:apex:execute --apexcodefile HellpAstro.apex
ããããã¨ãå ã»ã©ã³ãã³ãã©ã¤ã³ãã Apex ã³ã¼ããå ¥åãã¦å®è¡ããã¨ãã¨åãå®è¡çµæã«ãªãã¾ãã
æ´»ç¨æ¹æ³
Apex ã³ã¼ããå®è¡ã§ããã¨ãã©ããã£ãå¬ãããã¨ãããã®ã§ããããï¼
å®ã¯ããã¼ã¿ã®åæåãªã©ã§ãªãã¸ã§ã¯ãã®ã¬ã³ã¼ãéã«ç¸äºåç §ãªã©ãããã¨ããã¼ã¿ã¤ã³ãã¼ããé£ãããªããã¨ãããã¾ãããããã£ãå ´åã«ã¯ãApex ã³ã¼ãã¨çµã¿åããããã¨ã§å¹ççã«ãã¼ã¿ã¤ã³ãã¼ããã§ããããã«ãªãã¾ãã
éçºè ããã¼ã¿ãã¯ãªã¢ãããå ´åããµã³ãã«ãã¼ã¿ãªã©ãä¸æ¬ä½æããå ´åãªã©ã«ã¯ãApex ã³ã¼ããæºåãã¦ããã¨ãç¡é§ãªæéãå°ãçããããã«ãªããéçºå¹çåä¸ã«ãè²¢ç®ã§ãããã§ãã
ã¾ãããªãã·ã§ã³ã--jsonããã¤ãã¦å®è¡ãããã¨ã§ãå®è¡çµæãJSONå½¢å¼ã§åãåããã¨ãã§ãã¾ãã JSONå½¢å¼ã§åãåããã¨ãã§ããã°ãJenkisããããå¦çå ã§å®è¡çµæãæ¡ä»¶å¤å®ãããããªå¦çãè¨è¿°ã§ããããã«ãªãã¾ãã
ã·ã§ã«ã«çµã¿è¾¼ããããã«ãªãã¨ãæ´»ç¨ã®å¹ ãåºãã£ã¦ãã¾ãããããã£ãæè»æ§ãä¸ãããã¨ããã®ã³ãã³ãã®ã¡ãªããã¨è¨ããã§ãããã
ããã³
Apex ã³ã¼ããã³ãã³ãã©ã¤ã³ããå®è¡ãã¦ã¿ã¾ããããåèã«ãªãã¾ããã§ããããï¼
Apex ã³ã¼ããå®è¡ã§ããããã«ãªããã¨ã§ããªãæè»ãªãã¨ãã§ããããã«ãªãã¾ãã®ã§ãçãã¾ãããã¢ã¤ãã¢ãããã°å ±æãã¦ããããã¨å¹¸ãã§ãã
æå¾ã«ãªãã¾ãããããã®æ稿㯠チームスピリット Advent Calendar 2017 - Adventar 㨠Salesforce Platform Advent Calendar 2017 - Qiita 第2æ¥ç®ã®æ稿ã«ãªãã¾ãã
ãããã¼ã»ã¯ãªã¹ãã¹ï¼