Questions tagged [execute-anonymous]

The Execute Anonymous Apex tool in the Developer Console runs the Apex code you enter using ExecuteAnonymous and generates a debug log with the results of the execution.

Filter by
Sorted by
Tagged with
0 votes
1 answer
48 views

Method does not exist or incorrect signature: void date() from the type Date

As per the title, I am encountering this issue when running an anonymous apex script: List <ServiceContract> serviceContractList = [SELECT Id, Status__c, Status FROM ServiceContract WHERE ...
Jaemy Malik's user avatar
1 vote
1 answer
149 views

Vscode Execute Anonymous Apex with button?

While working with a co-worker. Realized his VSCode has a button to execute Anonymous Apex. Rather than using commands to execute 'SFDX: Execute Anonymous Apex with Currently Selected Text' or 'SFDX: ...
YCS's user avatar
  • 27
0 votes
3 answers
67 views

3E-13 value on SOQL result Currency field

When I execute an SOQL query on my currency field (5,2) length, Im getting this value as a result: 3E-13 What it does mean and how could I get the actual value? Same if I do it through Anonymous: List&...
BoDiE2003's user avatar
  • 437
3 votes
1 answer
813 views

How to control logging level of VSCode's output when executing Apex anonymous?

When working with a scratch org within VSCode, I periodically setup a simple file to test out various Apex commands, etc. I will setup the Apex script and the use VSCode's command palette to run the ...
ImJohnMDaniel's user avatar
0 votes
1 answer
683 views

Passing a List in SOQL Query

I'm trying to pass a list of 1000 account IDs and retrieve their corresponding count of Contacts and write the results to a CSV file. I'm using the Anonymous Execute window to run the code below as I ...
ManiS's user avatar
  • 3
1 vote
1 answer
481 views

How can I execute a global Apex class from the Anonymous Apex window?

Hi I have a managed package installed in an org with several global classes. Which are documented as the following: Apex class - global with sharing class FeatureConsoleService Method of Class - ...
plateaued1's user avatar
1 vote
1 answer
430 views

Apex unexpected token '<'

Apex Unexpected token '<'. I'm getting this error on anonymous window. Line: 3, Column: 13 Unexpected token '<'. using this code: String devName1 = 'Mass_Parcel_Update'; List<Block__mdt>...
newbieApexLWCDev's user avatar
0 votes
1 answer
1k views

execute method of batch apex not running from anonymous window

I have a batch apex that I made few changes. The functionality of the batch apex is to pull assets of a specific record type, and updates a specific field to true based on a criteria. To test my ...
Balaji Pooruli's user avatar
0 votes
3 answers
140 views

How do I retrieve a String from a SOQL query?

How can I retrieve data as a string from a SOQL query? The code I have below gives an error: "System.ListException: List index out of bounds: 0" If a run a check through Query Editor or even ...
user avatar
1 vote
1 answer
634 views

API POST not working on executeAnonymous BUT IS working on Postman

I'm having trouble getting a POST request to go trough using the Execute Anonymous window. The endpoint is exactly the same in my postman and it goes trough with no issues, but keeps returning a 400 ...
potato46's user avatar
2 votes
1 answer
378 views

loop over multiple items in a list? 'Duplicate Value Error'

I am looping over a list of records and trying to set a field on those records one by one (the field value will be different for each) but my loop keeps putting the same value for each record. List<...
potato46's user avatar
0 votes
2 answers
407 views

Future method executing (success), but not working

I bulk-updating phone numbers on objects, following method working on single or multiple numbers, but when I delete conditions in query for low amount of records, its exception CPU time exceeded. So I ...
jur1s77's user avatar
  • 47
0 votes
2 answers
377 views

Anonymous code for bulk update of text field

I have a text field named TestId in the object test which is capturing the Id of the record.Actually I have used an automation such as flow to update the value in the text field. Since I cannot make ...
JK123's user avatar
  • 69
0 votes
1 answer
251 views

Why this code only works on execute anonymous?

I'm doing a challenge for a course and I was trying in a class, not in execute anonymous, and in the class, it show errors and the execute anonymous don't. Why that? Look the photos to understand, is ...
Alexia Ribeiro's user avatar
0 votes
1 answer
352 views

Run Test Suite from Apex

I have a test suite which contains all test classes. I want to run the test suite from Anonymous Window so at the end of suite run completion I can create custom object records to track the coverage. ...
वरुण's user avatar
2 votes
1 answer
1k views

Anonymous code to run a bulk update

I have three objects, namely Tests, Grant, and Grant Contracts. Here in Tests object I have given a lookup to Grant and Grant Contract. I have also given a lookup in Grant Contract to the Grant object....
JK123's user avatar
  • 69
0 votes
1 answer
2k views

Method does not exist or incorrect signature: void getUserName() from the type UserInfo

I dont know what is the problem. When I am trying to use UserInfo.getUserName() in my main org it doesnt work and gives me error like in title, but in another org it works perfectly. What can I do? So ...
Terdivi's user avatar
  • 51
0 votes
2 answers
1k views

execute Anonymous apex code from VS code, do I need to connect to SF org?

SFDC beginner and like to configure my VS code to connect development org. But before connecting to Org I would like to execute some apex code "hello.apex" created during project creation. ...
CHANDRA SEKARAN MURUGESAN's user avatar
0 votes
1 answer
2k views

SOSL use FIND with bind list of Strings - Specified search expression can not be converted to string

I have a list of strings (phones) which I'm trying to use inside my SOSL Find clause and its giving me issues: List<String> phonesList = new List<String>(); for(Account acc : acclist) { ...
BoDiE2003's user avatar
  • 437
3 votes
2 answers
6k views

Batch Apex -- Constructor Not Defined

I've read through some other similar posts, and what seems to usually throw this error (Ex: constructor takes 3 args and you've only given it 2) I don't think is the case here. My constructor only ...
JH-105539's user avatar
1 vote
0 answers
534 views

SF FLOW - Remove duplicated Opportunity records from Opportunity Collection using Apex Action

I am currently working on a flow in Salesforce Lightning using the Flow Builder and I would like to remove duplicates from an Opportunity collection before updating it. In order to do so I created the ...
Yann M.'s user avatar
  • 23
1 vote
1 answer
1k views

Recieving error "Unexpected token '<'." while defining a list in anon apex

The following code returns the error: List<ContentDocumentLink> docLinks = [SELECT ContentDocumentId FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM Case ) and LinkedEntity....
Adam Carr's user avatar
0 votes
1 answer
633 views

Execute Anonymous Error unexpected token 'test1'

I am trying to insert a case using anonymous apex but I keep getting an error unexpected token 'test1'. Could somebody help to understand what's wrong with this code? In other threads, people pointed ...
P1otr's user avatar
  • 1
5 votes
1 answer
1k views

How does Developer Console save its state?

I have worked as SF dev for many years and I have asked this question to many more experienced than me without a conclusive answer. How does Developer console (DC) save it's state (including Anonymous ...
MarcLee's user avatar
  • 115
0 votes
1 answer
280 views

Unexpected Token equal symbol in execute anonymous window

I am facing an unexpected token error when I am trying to insert a record through execute anonymous window. list<location_tracing__c> newRecs = new list<location_tracing__c>(); ...
Brindha Sharadha's user avatar
3 votes
1 answer
610 views

Apex Final Property Behaves Like a Member Variable

Assume we have a simple class: public with sharing class SomeClass { public String property { get; set; } { property = 'Default Property Value'; } public ...
Oleh Berehovskyi's user avatar
0 votes
1 answer
50 views

CPU Timeout Error

I have a one to many relationship between Project and Insurance. When a record is created on Insurance object, it needs to get the Project record and then count how many Insurance records are present ...
Krishnamurthy's user avatar
3 votes
1 answer
443 views

Reports.ReportManager classified as variable

I'm working on a way to collect all the reports that utilize a certain field in my Org, but I'm having a very weird problem. I've been attempting to run this code in an Anonymous Exe block but keep ...
Ronoc Eroom's user avatar
0 votes
1 answer
2k views

How does return work?

I'm trying to understand the use of the return keyword at the end of a method. I made a class to calculate a simple value: public class Calc { Decimal monthlyWage = 32; Decimal ...
RedMan's user avatar
  • 107
0 votes
1 answer
339 views

Anonymous Apex - Create/Insert new profile to scratch org

Is it possible to create/insert Standard User Profile in Scratch Org using Anonymous Apex or Apex Class? Thank You
SFguru's user avatar
  • 25
2 votes
3 answers
4k views

Question About Static Methods

I'm new to Apex and development in general... So, I'm playing around coding and doing some badges in Trailhead. I created a small piece of code, as below, and have no actual use: public class ...
RedMan's user avatar
  • 107
9 votes
4 answers
6k views

How to see anonymous code debug logs in visual studio code?

I installed the Salesforce CLI and the Salesforce Salesforce Extension Pack on Visual Studio Code because it's easier to write code than the Developer Console but I got a problem. I want to get the ...
Stefano 's user avatar
0 votes
2 answers
600 views

can not access parent fields on a master detail

I need to an object and modify it's parent if condition are fullfiled but i'm encoutering an wierd behavior: in my SOQL the __r.field doesn't retrieve the fields values: Below my anonymous code: list&...
Julien Souchi's user avatar
3 votes
1 answer
1k views

Running Anonymous Apex error: This org has reached its daily usage limit of apex log headers

I am running updates via sfdx commands by sending an .apex file. The command looks like this: sfdx force:apex:execute -f <myFile.apex> <my_org_credentials> After running 1000 of these, I ...
Json Bourne's user avatar
1 vote
1 answer
761 views

Developer Console "Unpacking results" never finishes, even though log file indicates ready

So you think, OK, just dismiss the popup that says "Unpacking results" and get on with it. The thing is, it looks as though the anonymous Apex code that was run, hasn't quite finished, as ...
Sander de Jong's user avatar
1 vote
2 answers
16k views

How do I update multiple records with apex using execute anonymous [closed]

I have the following piece of code that I am able to execute to update a single record at a time Opportunity opp = new opportunity(id='006G000000mHTSE', StageName='Transferred', Membership_Status__c='...
samantha catanzaro's user avatar
0 votes
1 answer
480 views

Scheduled Job trigger is 9 hours delayed

I have a set of records(around 90,000 records) to be updated at 1AM every day. But I cannot update at least 10,000 records in a bulk as salesforce reaches governor limits. Then I wrote a schedulable ...
Isuru Buddhika Herath's user avatar
0 votes
1 answer
1k views

getSalesforceBaseUrl() returning an error in Anonymous

I want to execute a call to Lightning Platform REST API in Anonymous window. When I am writing the following: String sfURL = URL.getSalesforceBaseUrl().toExternalForm(); I am getting the following ...
Roxana Elena Cismaru's user avatar
1 vote
2 answers
890 views

How do I get the logs (results) of executing anonymous Apex code in jsforce?

I have been trying to execute the following Apex code in jsforce (Node.js): var apexBody = "System.debug(UserInfo.isMultiCurrencyOrganization());"; conn.tooling.executeAnonymous(apexBody, function(...
Sumit Israni's user avatar
3 votes
1 answer
2k views

Access Parent Record from child SOQL - APEX

This question seems silly but i am really stuck! I want to get the Account name and Account Rating for my contacts via Apex code, but instead of Account name and rating, it returns the accountId! I ...
Giorgos Galaios's user avatar
0 votes
1 answer
1k views

My class executed before. But now it doesn't. Execute Anonymous Error Invalid Type Line 1 Column 1

I am 12-years into Salesforce BUT new to APEX coding and am writing a class to simply trigger an update on all records on Budget__c in order to fire some declarative workflow rules (if anyone has ...
cloudconsulting's user avatar
1 vote
1 answer
2k views

Delay timer in between record execution

I was wondering if there any batch method that will allow me to add a delay between 2 records. Sy for example I have 100 records. I want to add a delay for execution between record 1 and record 2 and ...
MnZ's user avatar
  • 3,170
0 votes
1 answer
2k views

Add a delay timer when a batch class is executed without Scheduler

Here's a use case I'm trying to figure out for while: I run the following batch class to update records: MyBatchClass batchInstance = new MyBatchClass (); database.executeBatch(batchInstance ,1); ...
MnZ's user avatar
  • 3,170
1 vote
1 answer
5k views

Why I get DUPLICATE_VALUE, duplicate value found: SetupOwnerId?

Code Map<String,Decimal> nbrbRates = NBRBService.getNBRBRates(); List<CustomSettingRate__c> customSettingRates = new List<CustomSettingRate__c>(); CustomSettingRate__c ...
Noker's user avatar
  • 57
0 votes
2 answers
2k views

Schedule for Batch

I made a Batch class and Schedule to call that class. However, I am not able to test in Execute Anonymous Window. schedule global class UpdateUserDataSchedule implements Schedulable {      global ...
Juliana's user avatar
1 vote
0 answers
417 views

Schema.getGlobalDescribe not showing all standard object even from System Admin Profile

I am trying to run very simple code in a static method under classs. Method: public class TestUtil { public static void testMethod1() { for(String str : Schema.getGlobalDescribe().keyset()...
Piyush Kalra's user avatar
0 votes
1 answer
986 views

Apex class tried to execute in anonymous window

I am beginner in Salesforce and still in initial steps in understanding the concepts..i tried the below class and the output didn't come as expected public class mytest2 { Public integer marks; ...
Apex Beginner's user avatar
0 votes
0 answers
710 views

DUPLICATE_VALUE Error while inserting a knowledge article

I am receiving the following error while inserting a knowledge article through the class (not a test class but a regular handler class) when called from Trigger. DUPLICATE_VALUE, The URL Name ...
sandroid's user avatar
0 votes
0 answers
567 views

Insert a new record with multiple fields Error 431 HTTP

I am trying to insert a new records in my custom object Monitor__c with too many fields, when I execute my code in an anonymous window in the developer console, It delivers the following error: ...
Mar Andrés López's user avatar
0 votes
0 answers
535 views

How to delete data of Big Objects? (Preferably via Anonymous Apex)

I have some sample data in my Booking Big Object and now I want to delete the records so I tried writing this in Anonymous Apex: List<Booking__b> booking = new List<Booking__b>(); ...
compski's user avatar
  • 1,352