Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs

Questions tagged [static]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
59 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() ...
Tzinm's user avatar
  • 21
0 votes
1 answer
82 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 ( ...
SFDC Dev 27's user avatar
0 votes
1 answer
43 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 = ...
Tuấn Trần quốc's user avatar
1 vote
1 answer
81 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 ...
Shamina's user avatar
  • 4,275
3 votes
1 answer
110 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 ...
user127426's user avatar
0 votes
1 answer
181 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 ...
ministe's user avatar
  • 324
1 vote
1 answer
3k 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 ...
yvoloshin's user avatar
  • 113
0 votes
0 answers
82 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 ...
jdrussett's user avatar
1 vote
1 answer
1k 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 ...
lemleborze's user avatar
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(...
unique user's user avatar
16 votes
1 answer
1k 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 ...
Oleh Berehovskyi's user avatar
2 votes
1 answer
783 views

If a trigger handler calls a static method, what happens when another of the same type of trigger fires before that method finishes execution?

All the samples I've seen of Apex trigger handlers have them calling static methods in a helper/service class. What happens when a second trigger of the same type (say after insert) on the same object ...
djklord's user avatar
  • 23
0 votes
1 answer
35 views

System throwing error for simple codings

Public class StaticExample { Public static void method1() { System.debug(‘I am static method’); } Public void method2() { System.debug(‘I am static method’); } ...
user avatar
2 votes
2 answers
478 views

How do you know what to include in a test class for any given trigger?

I've had a fairly simple run in writing test classes, but am not sure if I'm doing it right or adhering to best practices. Below you'll find one of my triggers and its corresponding test class (100% ...
Nauman Husnani's user avatar
0 votes
3 answers
2k views

Reading Apex enums in LWCs: "AuraEnabled fields cannot be static" when annotating enum with @AuraEnabled

I have a service class with some error types: public with sharing class ServiceClass { public enum ErrorType { ERROR } } And a controller method: @AuraEnabled(cacheable=true) public static ...
Andy Ray's user avatar
  • 1,468
5 votes
2 answers
377 views

Can Apex static values be used to safely communicate between executions of process builder?

We have a Process Builder which currently gets a hardcoded Salesforce Id out of an abused label and assigns it to the record. Of course, this means the solution causes tests to fail outside ...
Brian Kessler's user avatar
2 votes
3 answers
5k 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
0 votes
1 answer
750 views

Static variable is cleared between page load and button click - how do I keep the values?

I have a VF page in which I load an account on the page load. I've created a static variable to save the loaded account in to, in order to compare whether any changes were made on the page as I need ...
Irene's user avatar
  • 1,839
2 votes
2 answers
256 views

Public set of strings to use in the entire code?

I have a picklist field called Meeting Type that's being used in multiple classes. Whenever someone wants to change the value of the picklist, i have to search for all instances of that value in the ...
Dana Griff's user avatar
  • 1,576
2 votes
1 answer
1k views

How to call Static Variable in non-static method?

In an apex controller constructor I have set a value in a static variable (say VerificationCode). In the VFP button click action, I am invoking the registerUser method (non-static method), in the same ...
Mahesh Raghuraman's user avatar
0 votes
1 answer
431 views

Static method cannot be referenced from a non static context - Test Class

I'm trying to write a test class for this class but not sure how to provide code coverage for what I'm doing here. In my class I'm just running a query, looping through the query and creating a list ...
Adam Parker's user avatar
-1 votes
1 answer
2k views

Static Methods and Return Values?

Do Static Methods In Salesforce Return Values Like public static integer MethodName(){}
Faiz's user avatar
  • 31
0 votes
1 answer
697 views

@AuraEnabled methods and fields : field declared as @AuraEnabled not available in @AuraEnabled method

I am new to lightning and i have written a controller for the component. public class TScontroller{ @AuraEnabled public Case caseDetail {get;set;} . .// few @AuraEnabled variables declared as above ....
Ankur ---'s user avatar
1 vote
2 answers
6k views

Why am I getting "Static method cannot be referenced from a non static context: String String.valueOf(Object)"?

I have this static class called from my lightning component, but am getting the error "Static method cannot be referenced from a non static context: String String.valueOf(Object)" on the line ...
Irene's user avatar
  • 1,839
1 vote
3 answers
652 views

How can I get Id from @AuraEnabled method in simple method?

I have a Lightning cmp with some logic, and I need to get Id to continue work with it in Lightning. But I get null. How can I fix it? public static Id toolId; @AuraEnabled public static void ...
Yagami Raito's user avatar
1 vote
1 answer
2k views

What is the life-cycle of static properties in Apex classes?

Sometimes when developing Apex, I've populated some static property. But then later -- most often in an Async or Test context -- I go to access it again and discover SFDC is behaving like it is ...
Brian Kessler's user avatar
1 vote
2 answers
7k views

Variable does not exist?

I know I am missing something very small, but I cannot get my head around. This is what I've tried public class SampleClass { public String currentUserId {get;set;} public SampleClass(){ ...
Austin Evans's user avatar
1 vote
1 answer
278 views

Is it possible to call a future static callout method from a scheduler

I have a static callout which i want to schedule every 5 minutes. How would i approach this I have tried the following but the the incorrect signature error: Callout public class or_service { @...
Thomas's user avatar
  • 2,298
5 votes
2 answers
967 views

Maintain state in Visualforce Page without using View State

I would know if there is some way to maintain state across different transactions without using View State. For example, if in my Custom Controller, for every action method, I need 100 Account's ...
vt89's user avatar
  • 725
0 votes
2 answers
107 views

Create list of records in Before and delete the list in After Context

I need to write a trigger on Case object where I need to delete the placeholder records and relate the case to existing records. I need to prepare the list of placeholder in before context and delete ...
P P's user avatar
  • 107
0 votes
1 answer
525 views

Update list from static method

I have a static method and it has this annotation @RemoteAction so it can be called from java script, I query a list in this method and I want to change a field value and update the list, this doesn't ...
Roody's user avatar
  • 49
1 vote
1 answer
163 views

Call Excel VF Page from a static method in controller

I have a MS Excel VF Page that perfectly downloads data. Now in main VF Page I am having a remote action static method called using vf remoting from button on main page. From that method I need to ...
Testing_SFDC's user avatar
  • 2,940
0 votes
2 answers
3k views

Pass Set to static method

My understanding of static methods is that they hold the data until the end of the transaction, right? So, if I wanted to pull information about a set of ids that would be referenced during a for loop,...
Chance's user avatar
  • 1,070
5 votes
1 answer
204 views

Using a single trigger approach - how to manage the object changes - Before Insert mainly

I am trying to follow a single trigger approach. there are several resources and patterns for it. I am doing something very simple My main question: Whenever we need to add new functionality to the ...
Saariko's user avatar
  • 5,610
0 votes
1 answer
1k views

(Why?) Is it good for Apex methods to be static? [closed]

Many native objects in Apex rely on static methods and properties. This seems an abnegation of S.O.L.I.D., or at least of the Dependency inversion principle. As a developer who values the test ...
Brian Kessler's user avatar
1 vote
1 answer
177 views

Attempt to dereference a null object : Static method add Id to set

I have below static method where I am trying to add an Id to a set of Ids. This throws subject line error. Can someone please let me know where i am doing wrong? Apex Method public Id ...
Testing_SFDC's user avatar
  • 2,940
-1 votes
2 answers
2k views

String class- static vs Instance method

I want to clear my understanding on when to declare a method as static or an instance method. In the apex string class itself, some methods are static like isBlank() while others are instance method ...
Deep Singhal's user avatar
3 votes
2 answers
4k views

Updated the value of a local variable using different class

I was able to update the value of a local variable in a method from a different class. I am trying to understand how is it possible! Isn't that variable out of scope for another method. Moreover the ...
Arnold's user avatar
  • 439
0 votes
1 answer
887 views

Save Error in Test Class for @InvocableMethod: Static method cannot be referenced from a non static context

I'm trying to write a simple text class for another simple class that has an @InvocableMethod method, but receive the save error in the question's title. I can't figure out its cause or how to ...
Gabriel Rivera's user avatar
0 votes
1 answer
463 views

Method does not exist even method is static

Simple Code I am putting, Complex one working :( public class Kat { public String name; public Integer age; public static void accentureDetail() { System.debug('Anything to fix bug'); } ...
Jagdeep Singh's user avatar
1 vote
2 answers
2k views

SObjectType for RecordType?

Is there a statically accessible SObjectType for RecordType? System.debug(Account.SObjectType); // Result: Account System.debug(RecordType.SObjectType); // Result: SObjectType RecordType class ...
itsmebasti's user avatar
  • 6,457
7 votes
1 answer
65k views

Static method cannot be referenced from a non static context: List<String>

I believe this is a basic query and am missing something out. However am exasperated finding an answer to the issue and thus seek your guidance. The intent is to create a static method ...
max steel's user avatar
0 votes
1 answer
4k views

accessing static variables in method

I have static variables declared outside class and i am instantiating the variables in one method and access the same value in other method.But in spite of variable being set to static its still ...
Deepak Agarwal's user avatar
1 vote
2 answers
3k views

Is it possible to get value of a static String dynamically from an apex class

I have a apex class consisting some static variables, is there any way to get the value of one of these variables dynamically? Example : public with sharing class ConstantsClass { public ...
Shri's user avatar
  • 147
3 votes
3 answers
2k views

Significance of Static variable in a Trigger [duplicate]

Can anyone help me in understanding the significance of having a Static variable in Trigger with any real time example. For Example Trigger on Account(after Insert,after Update) { Static String ...
Lokesh Koppaka's user avatar
7 votes
3 answers
8k views

Include custom font in lightning components

I am trying to include a custom font in my lightning components. Unfortunately I am not managing in doing that. I uploaded a .eot file to my static resources and now I am trying to reference to it. ...
Ant12345's user avatar
  • 543
1 vote
1 answer
31 views

TestClass Codecoverage coming in CodeCoverage Section [duplicate]

I have written a simple Trigger as part of my learning. As per my trigger based on all new Account created a Case is created using Trigger. I have written the Test Class as well and everything looks ...
Robert Thomas's user avatar
0 votes
1 answer
906 views

Create a BaseTest class with common variables and methods

I'm trying to create a class that will act like a BaseClass for my Test classes. It must include several variables, constants and methods common to my test methods. The kicker is that Test methods ...
Matheus Gonçalves's user avatar
3 votes
1 answer
4k views

Lightning Component - maintaining a counter in Server Controller using Static Variable

I have a very simple sample lightning component to understand the concept. I have button and on click on the button, I am incrementing a static variable in Apex Server controller. I am expecting that ...
apn's user avatar
  • 1,722
1 vote
2 answers
45 views

Do trigger contexts in 2 different packages share the same record references?

Assume there are 2 managed packages, PKGA and PKGB. Both have a static list of trigger records. Will changes made to a record in PKGA be reflected in PKGB as well? To paraphrase, here's how the ...
Mossi's user avatar
  • 3,966