Questions tagged [static]
The static tag has no usage guidance.
67
questions
0
votes
1
answer
40
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
38
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
63
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
103
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
75
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
2k
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
68
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
802
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(...
15
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 ...
2
votes
1
answer
650
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 ...
0
votes
1
answer
33
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’);
}
...
2
votes
2
answers
400
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% ...
0
votes
3
answers
1k
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 ...
5
votes
2
answers
334
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 ...
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 ...
0
votes
1
answer
604
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 ...
2
votes
2
answers
234
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 ...
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 ...
0
votes
1
answer
403
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 ...
-1
votes
1
answer
1k
views
Static Methods and Return Values?
Do Static Methods In Salesforce Return Values
Like
public static integer MethodName(){}
0
votes
1
answer
630
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
....
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 ...
1
vote
3
answers
584
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 ...
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 ...
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(){
...
1
vote
1
answer
237
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 {
@...
5
votes
2
answers
929
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 ...
0
votes
2
answers
105
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 ...
0
votes
1
answer
454
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 ...
1
vote
1
answer
162
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 ...
0
votes
2
answers
2k
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,...
5
votes
1
answer
195
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 ...
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 ...
1
vote
1
answer
175
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 ...
-1
votes
2
answers
1k
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 ...
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 ...
0
votes
1
answer
877
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 ...
0
votes
1
answer
372
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');
}
...
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 ...
7
votes
1
answer
62k
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 ...
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 ...
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 ...
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 ...
7
votes
3
answers
7k
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. ...
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 ...
0
votes
1
answer
776
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 ...
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 ...
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 ...
0
votes
2
answers
722
views
how to add library to static resource
<apex:page standardController="Account" >
<apex:form >
<script type="text/javascript" url="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<...