Questions tagged [static]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
34 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 ...
user avatar
1 vote
1 answer
280 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 ...
user avatar
0 votes
1 answer
48 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(...
user avatar
13 votes
1 answer
455 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 ...
user avatar
2 votes
1 answer
255 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 ...
user avatar
  • 23
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’); } ...
user avatar
2 votes
2 answers
266 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% ...
user avatar
0 votes
3 answers
716 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 ...
user avatar
  • 1,151
5 votes
2 answers
215 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 ...
user avatar
2 votes
3 answers
1k 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 ...
user avatar
  • 107
0 votes
1 answer
205 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 ...
user avatar
  • 1,387
2 votes
2 answers
126 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 ...
user avatar
  • 1,494
2 votes
1 answer
698 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 ...
user avatar
0 votes
1 answer
129 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 ...
user avatar
-1 votes
1 answer
494 views

Static Methods and Return Values?

Do Static Methods In Salesforce Return Values Like public static integer MethodName(){}
user avatar
  • 21
0 votes
1 answer
381 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 ....
user avatar
1 vote
2 answers
5k 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 ...
user avatar
  • 1,387
1 vote
3 answers
345 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 ...
user avatar
1 vote
1 answer
1k 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 ...
user avatar
1 vote
2 answers
5k 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(){ ...
user avatar
1 vote
1 answer
126 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 { @...
user avatar
  • 2,068
5 votes
2 answers
688 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 ...
user avatar
  • 685
0 votes
2 answers
70 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 ...
user avatar
  • 97
0 votes
1 answer
242 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 ...
user avatar
  • 49
1 vote
1 answer
141 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 ...
user avatar
  • 2,900
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,...
user avatar
  • 1,020
5 votes
1 answer
123 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 ...
user avatar
  • 5,435
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 ...
user avatar
1 vote
1 answer
115 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 ...
user avatar
  • 2,900
-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 ...
user avatar
3 votes
2 answers
3k 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 ...
user avatar
  • 439
0 votes
1 answer
858 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 ...
user avatar
0 votes
1 answer
64 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'); } ...
user avatar
1 vote
2 answers
1k 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 ...
user avatar
  • 6,100
7 votes
1 answer
57k 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 ...
user avatar
0 votes
1 answer
3k 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 ...
user avatar
1 vote
2 answers
2k 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 ...
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 ...
user avatar
7 votes
3 answers
6k 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. ...
user avatar
  • 523
1 vote
1 answer
30 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 ...
user avatar
0 votes
1 answer
493 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 ...
user avatar
3 votes
1 answer
3k 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 ...
user avatar
  • 1,702
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 ...
user avatar
  • 3,764
0 votes
2 answers
504 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> <...
user avatar
  • 716
0 votes
0 answers
1k views

Static method throwing common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object

This is the Exception I am getting common.apex.runtime.impl.ExecutionException: Attempt to de-reference a null object I'm getting a Exception thrown while running a unit test. I'm looking at it ...
user avatar
2 votes
1 answer
283 views

Central class for calling static methods in Data Access Layer

Much like the Factory pattern I am looking for a good way to call the desired Data Access methods through a central class. Unfortunately, my DAL classes are static (as I need them to cache records) so ...
user avatar
  • 3,764
6 votes
1 answer
6k views

Public Static List Method

I have been studying Salesforce Dev for the past few weeks and can't find any documentation on something very simple. Can anyone explain why I would make the public static method a type of list rather ...
user avatar
  • 3,167
7 votes
2 answers
661 views

Why do static and non-static lists behave differently in batch and test contexts?

Given the following batch code: global without sharing class POCBatch implements Database.Stateful, Database.Batchable<Sobject>{ public static List<String> staticList = new List&...
user avatar
  • 2,700
0 votes
1 answer
888 views

Static variable used for Recurssion check

Scenario: I have two objects - Object A and Object B.Object A has recursion checking mechanism using Static Boolean variables covering different events(IsBeforeUpdate,IsBeforeInsert etc..) I have two ...
user avatar
  • 111
2 votes
1 answer
2k views

Dynamically expanding a wrapper class for an object as custom fields are added.

I've reached a bit of a dead end in my latest programming endeavour. To give a brief overview I'm creating a console that houses data for four custom objects linked together loosely only by their ...
user avatar