function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
James George 00700James George 00700 

VS Code Execute Anonymous Apex displaying the code itself after the run

Hi Friends,
I  tried to run a simple hello world using the code below

string tempvar = 'Enter_your_name_here';
System.debug('Hello World!');
System.debug('My name is ' + tempvar);

The output after SFDX: Execute Anonymous Apex with Editor Contents
is showing the same code I have written without any value assignments

Below is the return from the execution
48.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO
Execute Anonymous: // Use .apex files to store anonymous Apex.
Execute Anonymous: // You can execute anonymous Apex in VS Code by selecting the
Execute Anonymous: //     apex text and running the command:
Execute Anonymous: //     SFDX: Execute Anonymous Apex with Currently Selected Text
Execute Anonymous: // You can also execute the entire file by running the command:
Execute Anonymous: //     SFDX: Execute Anonymous Apex with Editor Contents
Execute Anonymous: 
Execute Anonymous: string tempvar = 'Enter_your_name_here';
Execute Anonymous: System.debug('Hello World!');
Execute Anonymous: System.debug('My name is ' + tempvar);
00:14:41.21 (21039896)|USER_INFO|[EXTERNAL]|00555000004hwoa|test-qphxury38ylx@example.com|(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)|GMT-07:00
00:14:41.21 (21078526)|EXECUTION_STARTED
00:14:41.21 (21085467)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
00:14:41.21 (21721820)|USER_DEBUG|[9]|DEBUG|Hello World!
00:14:41.21 (21776425)|USER_DEBUG|[10]|DEBUG|My name is Enter_your_name_here
00:14:41.21 (21858188)|CUMULATIVE_LIMIT_USAGE
00:14:41.21 (21858188)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100

Can anybody show some light, what I'm missing?
Best Answer chosen by James George 00700
ayu sharma devayu sharma dev
Hello James

To find your output see the Debug tags. Running this command in VS code returns the Logs which includes debugging results.

00:14:41.21 (21721820)|USER_DEBUG|[9]|DEBUG|Hello World!
00:14:41.21 (21776425)|USER_DEBUG|[10]|DEBUG|My name is Enter_your_name_here

above is the output you are looking for. You can find it in your output log.

Regards
Ayush Sharma

All Answers

AnudeepAnudeep (Salesforce Developers) 
Hi James, 

I am seeing the following output with your anonymous code (I used command line : sfdx force:apex:execute). Guess this is what execute anonymous output looks like using SFDX 

> string tempvar = 'Enter_your_name_here';
System.debug('Hello World!');
System.debug('My Name is' + tempvar);
Compiled successfully.────────────────
Executed successfully.ep@lightning.com

48.0 APEX_CODE,DEBUG;APEX_PROFILING,INFOfdx force:apex:execute
Execute Anonymous: string tempvar = 'Enter_your_name_here';ine,
Execute Anonymous: System.debug('Hello World!');
Execute Anonymous: System.debug('My Name is' + tempvar);
04:36:42.20 (20543695)|USER_INFO|[EXTERNAL]|0057F000001ZALG|anudeep@lightning.com|(GMT-07:00) Pacific Daylight Time (America/Los_Angeles)|GMT-07:00mn: 1
04:36:42.20 (20579961)|EXECUTION_STARTED
04:36:42.20 (20588854)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
04:36:42.20 (21277702)|USER_DEBUG|[2]|DEBUG|Hello World!
04:36:42.20 (21343714)|USER_DEBUG|[3]|DEBUG|My Name isEnter_your_name_here
04:36:42.21 (21544541)|CUMULATIVE_LIMIT_USAGEorce:apex:execute
04:36:42.21 (21544541)|LIMIT_USAGE_FOR_NS|(default)| each line,
  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

04:36:42.21 (21544541)|CUMULATIVE_LIMIT_USAGE_END

04:36:42.20 (21590596)|CODE_UNIT_FINISHED|execute_anonymous_apex
04:36:42.20 (23153776)|EXECUTION_FINISHED

Anudeep
ayu sharma devayu sharma dev
Hello James

To find your output see the Debug tags. Running this command in VS code returns the Logs which includes debugging results.

00:14:41.21 (21721820)|USER_DEBUG|[9]|DEBUG|Hello World!
00:14:41.21 (21776425)|USER_DEBUG|[10]|DEBUG|My name is Enter_your_name_here

above is the output you are looking for. You can find it in your output log.

Regards
Ayush Sharma
This was selected as the best answer
James George 00700James George 00700
Hi Anu and Ayu,
Thanks for the time to look into my issue, it's working now.
I see that, the result is already there in my question, but debug log looks so clumsy to read and made me think something went wrong.

I can nowdebug logs in .cls and .apex files now.

Thanks for all the support
James