Skip to main content

Questions tagged [apex-variable]

Filter by
Sorted by
Tagged with
13 votes
4 answers
3k views

Is there any benefit, performance-wise, to declaring Apex variables as final?

In other languages (see, for instance, Swift), stating explicitly that a variable is final lets the compiler optimize the code accordingly. Is this the case with Apex?
catalandres's user avatar
4 votes
1 answer
233 views

What is the difference between a variable and an automatic read-write property?

Accordingly to the Apex Developer Guide, An Apex property is similar to a variable; however, you can do additional things in your code to a property value before it is accessed or returned. ...
gvgramazio's user avatar
3 votes
2 answers
3k views

What is this technique called?

public static List<Holiday> holidays { get { if(holidays == null) holidays=[Select h.StartTimeInMinutes, h.Name, h.ActivityDate From Holiday h]; ...
John Lima's user avatar
3 votes
1 answer
833 views

Flow and InvocableMethod Simple Question

How would I create an array of the values from the flow and pass them into the APEX @InvocableMethod? My method is taking in a list of Strings: @InvocableMethod public static List<String> ...
Olivia's user avatar
  • 3,471
2 votes
2 answers
280 views

Lombok for Salesforce Apex

I'm looking for some solution, which helps me to write less code in Apex. Is there any tool like Lombok for Java.
michal98kowalczyk's user avatar
2 votes
1 answer
985 views

Pass value from apex component to controller

I have a visualforce force component: <apex:component controller="NewITAssetController"> <apex:outputPanel> <label>Date field</label> ...
Viktor's user avatar
  • 360
2 votes
1 answer
354 views

VF Component modifying an apex:variable outside of its scope

I just stumbled upon a weird behavior of Visualforce Components (or apex:variables). Please see the code below and then the end result: VF Page <apex:page> <apex:variable var="foo" ...
smukov's user avatar
  • 5,613
2 votes
3 answers
541 views

Accessing passed variable from Visualforce page OR pass Controller.addFields in TEST

I want to pass the pricebook2id from an opportunity to my apex class and then use this when querying. I can get it using the Controller.addFields when declaring the controller like this: public ...
jaw999's user avatar
  • 1,317
2 votes
1 answer
720 views

Pass a variable from Javascript to Apex Controller

I'm trying to pass a variable from a javascript inside a VF page to a varibale in the Apex Controller. The VF page code is: <apex:page controller="uploadDataTosObject" apiVersion="36.0"> [...
L.benedettini's user avatar
1 vote
2 answers
2k views

Variables in Interface in Salesforce

Can you declare variables in Interface in Apex (Salesforce). In Java, it allows you to declare and initialize variables with public static final keywords in Interface. Also in Apex, are all abstract ...
Faiz's user avatar
  • 31
1 vote
1 answer
1k views

Dynamic Fields in for Loop

Is there a way to dynamically change the fields within a for loop? As an example, if I have for loop: for(Account a: myQueryResult){ if(a.parentId = fieldVariable){ Do something ...
Chance's user avatar
  • 1,070
1 vote
3 answers
11k views

Round off an apex variable upto two decimal places

I have apex variable in my visualforce page, which is calculated as below - <apex:variable var="cntFinal" value="{!IF(cntVar1==0,0,(cntVar2+cntVar3)*100/cntVar1)}"/> Now, I want to set this ...
Pramit's user avatar
  • 43
1 vote
2 answers
4k views

Trouble passing variable from Apex to VF Page

I'm trying to pass a simple string to a vf page, but can't seem to. What am I doing wrong? APEX public class ControllerJSGeo{ public String pId; public String testString {get;set;} ...
MRG's user avatar
  • 355
1 vote
1 answer
206 views

Compile Error on Map: Variable WhoId Doesn't Exist

Got the compile error for the snippet of code below. Says variable record.whoId (bolded) doesn't exist. Tried adding more brackets to the if statement, capitalizing WhoId and didn't work. Here's the ...
Brooks Bruce's user avatar
1 vote
1 answer
1k views

Flow Currency Decimal Places being dropped when passed to Apex Class

My flow has a screen where the users enters a value in a currency field that has 2 decimal places and that value gets passed to a variable in an Apex Action within the flow. For some reason, when I ...
Heather's user avatar
  • 73
1 vote
1 answer
593 views

Define apex:variable in apex:inputText

I'm trying to pass parameters while using immediate=true. (actionRegion is not an option) Since this won't work: <apex:inputText value="{!searchValue}" /> <apex:commandButton value="...
itsmebasti's user avatar
  • 6,535
1 vote
1 answer
967 views

Variable does not exist: insert record

I'm trying to insert a new record into an object where I pull information from OpportunityLineItem, Product, Opportunity, and Account. I did a query and get the results I want. Then I go to create a ...
Dan Wooding's user avatar
  • 3,651
1 vote
0 answers
246 views

How to pass an Apex-Defined Collection Variable from apex action in flow to a screen component (LWC) in Flows?

I have been working a small requirements where I need to display the Count of all Accounts Group by CreatedDate for Calendar Year. I have created an apex action 'FetchAccountData' as below public ...
Abhishake Chandra's user avatar
1 vote
1 answer
393 views

How to pass phone and email to invocable method

I have a visual flow from which I want to pass some person account info to an invocable method. It seems that when I use a phone and email field I can't assign them to my invocable class. Is this ...
Thomas's user avatar
  • 2,320
1 vote
0 answers
375 views

SOAP Call w/o WSDL body too large error

I am working on integrating an asmx webservice into salesforce. I was unable to parse the WSDL into apex, so have to build the calls manually. The call I built works and is received when literal ...
JoshuaWS's user avatar
  • 113
1 vote
2 answers
497 views

New Line in Apex Variable

I am trying the following code: <apex:variable var="variable1" value="{!CASE(object.field, "val1", "line1 line2", "val2", "...
Afroz Kazi's user avatar
0 votes
2 answers
852 views

How to switch on RecordTypeId inside a loop?

Alternative Title : How to optimize grouping each SObject records by Recordtypes public static Id sgRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Singapore')....
compski's user avatar
  • 1,367
0 votes
2 answers
2k views

Get value from custom setting

I have a batch process that I want to be able to dynamically tweak the batch size without changing the code in sandbox and then deploying each time. I figure I can use a custom setting as I have been ...
Dan Wooding's user avatar
  • 3,651
0 votes
2 answers
330 views

Apex variable shows as null

I have the following code below. The field generatedToken gets populated in getTokenFromA(), but when I access it in PutA() it is null. I have tried defining it as just static (without public) and ...
SFApexUser's user avatar
0 votes
1 answer
117 views

Soql on Account returns empty Id

I have a controller where I get a token from a visualforce page with account as a standard controller and controller extension. In my unittest I insert the variables but the accid throws an exception ...
Thomas's user avatar
  • 2,320
0 votes
3 answers
324 views

Variable does not exist on trigger class

For the following class, I get the error 'variable does not exist: mq' on lines 25 - 27 Public with sharing class InspectionQuotasHandler{ public static void UpdateMonthlyQuotaOfInspection(List&...
Sebastian's user avatar
0 votes
1 answer
44 views

One set of code for multiple package versions - Conditional Compile?

We have a managed package installed in about 1800 different orgs and, as such, there are multiple versions of the managed package out there. I'm trying to write an unmanaged package that will ...
Mike Jones's user avatar
0 votes
1 answer
283 views

How to pass query variable from soql into loop

I am trying to bulkify a callout where I want to pass the recordtype in my loop but I get: Error: Variable does not exist: RecordType If I try public RecordType personAccountRecordType I get ...
Thomas's user avatar
  • 2,320
0 votes
1 answer
824 views

How to make variable show the count of records from a dynamic soql query [duplicate]

I have a custom controller with a variable 'count.' I want this to update on the page every time the account list updates. Right now it's static. It just displays the original number of records in the ...
Sebastian's user avatar
0 votes
1 answer
4k views

Variable does not exist in test class

ProcessHandlerShowAccounts class works, but I am trying to get my test class up to par to validate my data. I am getting a variable does not exist, not sure why Did I initiate the class wrong? Also ...
nameishi's user avatar
0 votes
1 answer
1k views

Variable does not exist within invocable method

I am trying to access the variables sent from the Process Builder within the apex class. It says the variable accountParamter does not exist, which confused me because I declare it in the parameters ...
nameishi's user avatar
0 votes
1 answer
2k views

Flow Variable of Email addresses to Invocable Apex action

I'm trying to pass in the flow variable collection of Email addresses to Apex action to send out one email to each email address. I got some idea from Question, the code works fine when i ran it from ...
Saaki's user avatar
  • 55
0 votes
1 answer
714 views

ORDER BY Variable in Apex Class

I am trying to run a query that allows me to sort data inside a table. Depending on the value that gets chosen to sort by I have different queries: if(selectedField == 'Name'){ warehouses = ...
Jan Tonnet's user avatar
0 votes
1 answer
1k views

Variable does not exist - Batch Apex Query

I have a Batch Apex which is invoked from process builder. I can see Ids are coming into the variable (please see debug log) but same variable inside the query gives "Variable does not exist" error. I ...
SunnyG's user avatar
  • 421
0 votes
1 answer
282 views

Can i create changing variable in apex class

Hello guys i wrote to update class for case object and this object have a many records thats why i cant execute Soql queries, I encountering error: "So many soql queries",i searched i found one way, i ...
Furkan Kuyular's user avatar
0 votes
2 answers
61 views

Removing record reference in class

Expansion to original question: Error: Future method cannot be called Need to remove record variable from reference. Can someone help me and explain the process? Error: Error: Compile Error: ...
user avatar
0 votes
1 answer
2k views

Issues updating a apex variable on visualforce page

I have an apex variable that is the summed value of record amounts in a pageBlockTable. The idea is when an amount value is changed, a javascript function is called to recalculate the amount for all ...
justinpdove's user avatar
0 votes
1 answer
694 views

Variable does not exist in global method - batch class

I have tried to put together a batch class to update parent Account records with credit scores.. I need to make 2 list variables public so I am able to access them in the finish global batch method, ...
CharniW's user avatar
  • 57
0 votes
1 answer
1k views

Escaping variables in Email templates

I am trying to build the body of an email by using the fields of a given custom object(SObject). On this given SObject I am including some variables. One of those variables is the title of the Contact....
Cuban coffee's user avatar
  • 1,606
0 votes
1 answer
362 views

Accessing the deserialised object from a different class

I am using the following class to deserialise a JSON object: //Method to deserialize the response body public static responseResource deserialize(httpResponse res){ return (...
Kamil Mieczakowski's user avatar
0 votes
0 answers
203 views

The assigned variable shows 'null' in the WhatsApp

I have an error where the deviceType variable shows as null in the WhatsApp message. The queueable method is called depending on the selected email template to send and the relevant details should be ...
546 546's user avatar
0 votes
1 answer
232 views

Salesforce return value from function based on input

I am a complete novice in Salesforce, learning as I go, but I want to make sure I structure something in the best way as it can be a bit of a beast to manage if I don't. I am building some VisualForce ...
G-Man's user avatar
  • 117
0 votes
1 answer
492 views

Modify Date Range

How do I modify the code below to have the week range from Thursday 12 PM Central Time Zone to the following Thursday 12 PM, so setting the Start date of the week to be Thursday and end week to be ...
Julian's user avatar
  • 33
0 votes
1 answer
524 views

getting Must trace apex_code at finest when checking the variable panel

I have already set the apex debug level at FINEST but still when I check the variable panel I still see the message must trace APEX_CODE at Finest can someone please suggest on the same? Below is the ...
gs650x's user avatar
  • 2,708
0 votes
1 answer
230 views

Add a starting value to an Apex:Variable in a Apex:repeat Table

I have created a simple table of data in a VF page, which uses Apex:Repeat to list records. There is a column that contains a cumulative amount, by way of apex:variable. The cumulative amount works ...
TheMikeyBoosh's user avatar
0 votes
0 answers
703 views

Stop increment of apex variable

In my VF page I have: <apex:pageblockTable value="{!interview.Skill_review__r}" var="skillreview"> <apex:column headerValue="Rating"> <apex:...
SfdcBat's user avatar
  • 4,839
0 votes
2 answers
1k views

Strings holding exact same value still returning false when compared

I have 2 string variables. One of them holds data retrieved from custom metadata and another is explicitly declared. Both return exact same data when debugged, but still if I compare them, it returns ...
sourav guha's user avatar
-1 votes
1 answer
154 views

sObject Variable Assignment keeps the same values

I have a question regarding variable's assignment and the values within them. Account a = new Account(Name = 'TMP'); system.debug(Logginglevel.INFO, 'a '+a); // Name = 'TMP' Account b = new Account();...
Christos's user avatar
-1 votes
1 answer
33 views

Issue with variable-declaration

I have this string 'SELECT Id,Account,(SELECT field1, field2.... Further on I declare a for-loop with 2 variables: for(Opportunity opp : oppList) { Id AccId = opp.AccountId; ...
KonJfK's user avatar
  • 1