Questions tagged [static]
The static tag has no summary.
72 questions
3 votes
1 answer
96 views
Is it possible to have multiple separate transactions in one testmethod
I'm wondering if there is a way to get multiple transactions (with different contexts as far as static variables are concerned) within one test. I have a Trigger handler class where there is some ...
0 votes
0 answers
136 views
What are the options to display static content (html) on Experience cloud site
What are the options to display static content (html) on Experience cloud site as a reusable asset between pages/portals? I understand that there are options like following: Use external system like ...
0 votes
1 answer
515 views
Static field cannot be referenced from a non static context
I have a batch class and some static variables which I am initializing in the constructor. Getting the error: Static field cannot be referenced from a non static context. This error is shown from ...
0 votes
1 answer
77 views
Using static variables from other classes in dynamic queries
I am trying to run a dynamic query, using Database.query(), which includes a static variable from another class. This works correctly: static Id x = LocalUserInfo.currUserId; system.debug (x); User u =...
1 vote
1 answer
190 views
Retrieve Batch Class Name from Trigger
In order to cover a specific requirement, I need to determine that the DML action of inserting the records of an sObject has been triggered through a batch. The System class provides the isBatch() ...
0 votes
1 answer
172 views
Private Static variable get method fails with error Variable is not visible
I do not understand why I get an error in the line isExecuting = false (Variable is not visible) But if I comment out that line the error disappears. Thus, from the same getter, the line if ( ...
0 votes
1 answer
66 views
How can I get the field information by its name in static method?
I tried to write my code like this: public static string getPicklistValues(String fieldApi) { List<String> picklistValue = new List<String>(); Schema.DescribeFieldResult picklist = ...
1 vote
1 answer
124 views
Duplicate variable is not detected as duplicate after compilation
Definining 2 class variables with same name does not always fire Duplicate field compilation error when deploying apex class to the org. Code sample : public with sharing class MyClass { Boolean ...
3 votes
1 answer
138 views
Static flag being ignored in tests since Spring 23 Release
As of Spring 23, several tests where we publish platform events started failing. We use a static flag as a condition to execute a code block and looks like now the line where the flag is being set is ...
0 votes
1 answer
332 views
Retrieve data once and reference from static methods
I need to make a callout to retrieve some data, then have that accessible from static apex methods. The easy option is to perform the callout from within the static method but that would be ...
1 vote
1 answer
5k views
"Variable does not exist" error where variable is a class does exist
I have an Apex class OpportunityUpserter with a static method, where the static method makes a call to another static method in a class called IntegrationUtilities, as shown below. This gives me a ...
0 votes
0 answers
115 views
Static method cannot be referenced from a non static context - trigger before update failing
I understand questions like this have been asked in the past, mostly relating to test classes from what I've seen. I've spent hours trying to find a legitimately applicable question/answer to the ...
1 vote
1 answer
2k views
Stub api with static methods
I have a global class with a static method which makes post callout and I want to use Stub API, but I don't get how to do it when a method is static. I understand what to do inside mock classes, but I ...
0 votes
1 answer
58 views
How can I commit an entry to a static variable?
In one method I set the value of a static variable, in the other I want to get it, but I get null: public class CurrencyExchangeController { public static String requestDate; @future(...
17 votes
1 answer
2k views
Interface method can be implemented as static
Assume we have some simple interface: public interface IExecutable { void execute(); } and some class that implements the interface: public class Executor implements IExecutable { public ...