13

Too long for a comment, not a proper evaluation for 100% confidence So if you run the following script in anonymous Apex you will find that the loop with the final variable always runs faster than the one with the non-final variable. final Integer finalVal = 1000000; Integer changeableVal = 1000000; DateTime startTime; Long changeableDuration; ...


11

I only use it as part of making the intent clearer in code. So to me: private static final String OPEN = 'Open'; or: private static final Set<DisplayType> LIKE_SUPPORTED = new Set<DisplayType>{ DisplayType.STRING, DisplayType.PICKLIST, DisplayType.EMAIL, DisplayType.PHONE }; are fairly clearly constants not expected to change....


7

It's called Lazy Loading or Lazy initialization Lazy loading is a design pattern to defer initialization until the point at which it is needed. Reference Lazy Loading Lazy initialization


7

There's a benefit for you, the developer, since you're restricting the possible ways a variable can be assigned. For example, you're more likely to catch accidental assignments (using = instead of ==), and by restricting when a variable can be initialized, you're more likely to remember to initialize it correctly (as Adrian said, reducing the need for null ...


7

One big optimization regardless of what the compiler does with the declaration is that you can eliminate many null checks from your code. Consider the below example. If you remove the final declaration, your code becomes susceptible to NullPointerException unless you add a null check. public class Foo { final List<String> collection; public ...


6

Yes you just use get instead. You can cache a String or SObjectField. SObjectField field = Account.ParentId; for (Account record : [SELECT ParentId FROM Account LIMIT 10]) { Object value = record.get(field); } Note that it returns Object. If you want to return a concrete type, you'll have to cast. Id value = (Id)record.get(field);


5

Keeping everything in visualforce here, there is a function to do precisely what you're looking for, ROUND. It appears about half-way down the documentation page on visualforce functions ROUND Returns the nearest number to a number you specify, constraining the new number by a specified number of digits. ROUND(number, num_digits) and replace number ...


4

If you are looping over a List<Event>, you'll need to pull the WhoId from the loop record: for (Event record : [SELECT WhoId, ... FROM Event WHERE ...]) { if (!events.containsKey(record.WhoId)) events.put(record.WhoId, new List<Event>()); events.get(record.WhoId).add(record); } The documentation isn't great here, but the syntax ...


4

The apex code can be modified as below Approach 1 - Using property as getter and setters variable public class ControllerJSGeo{ public String pId; public String testString {get;set;} public ControllerJSGeo(ApexPages.StandardController stdController){ pId = ApexPages.CurrentPage().getParameters().get('id'); testString(); } private void ...


4

The component's controller is distinct from the page's controller. To pass the value back to the page, you'd need to pass in the controller through an attribute: Component (Parts) <apex:component> <apex:attribute name="controller" type="NewITAssetController" description="page controller" required="true"> ... <apex:input type="text" value="{...


4

Can you declare variables in Interface in Apex (Salesforce). No. Also in Apex, are all abstract methods are public by default? No. All methods and classes are private by default. You must provide an access modifier to grant more than private access. If the methods exist inside an inner class, the abstract methods can be implemented, but if they are not ...


3

I have made small changes in the Extension class. Added TheOpp = (Opportunity)sc.getRecord(); in the Constructor. public class myextension { private ApexPages.StandardController sc; public Opportunity TheOpp{get;set;} public String PassedPricebookId { get { return String.valueOf(TheOpp.Pricebook2id); //take from ...


3

apex:variable variables always have a global scope. You necessarily need use different variable names in all components and/or pages (e.g. via apex:include). Rarely, it happens that this behavior is desirable if you want to communicate across components, but mostly it is just a hassle. You should avoid using apex:variable for any real work, and instead use ...


3

Probably, this could be easy solution. I would suggest to gather a String value in a comma delimited way from the flow and then pass it to the Invocable method. The resultant String will look like this: {!varCRCId} & ',' & {!varCRId} & ',' & {!varManualStart} & ',' & {!varProcessStep} So change the signature from List<String&...


3

Change Integer oppsize to static as that is being accessed from static variable. static Integer oppsize = setting.Batch_Size__c; private static final Integer MAX_OPPTLI_IN_BATCH = oppsize;


3

The main reason why there is a distinction is because of Visualforce. You cannot access a variable in Visualforce, but you can access a property. To illustrate this at the most basic level, consider this code: public class myController { public String helloWorld = 'Hello, world!'; } <apex:page controller="myController"> <!-- following line ...


3

In your test class, you're setting PageReference to a variable, this does not adds the parameter to Page's URL in testing mode. A small step you're missing is to set the PageReference with current page using Test.setCurrentPage: PageReference pageRef = Page.EscrowLink; pageRef.getParameters().put('token',ev[0].Token__c); // set current page Test....


2

you can try something like <apex:variable var="input" value="" /> <apex:inputText value="{!input}" styleclass="textCls"/> <apex:commandButton value="Search" onclick="passValue()" rerender="none"/> <apex:actionfunction action="{!doSearch}" immediate="true" /> <apex:param name="value" assignTo="{!...


2

Well its combination of few, As Robs mentioned its caled lazy loading. Also Its called as Singleton Pattern. Singleton pattern makes sure, you have a single instance of a particular instancein the whole transaction(in your case holidays). Src: https://developer.salesforce.com/page/Apex_Design_Patterns_-_Singleton


2

The mq variable is scoped to the loop over your Monthly_Quota__c query. It's not defined once that loop completes, which it does just above the lines where you see this error. Did you mean to use i rather than mq there?


2

You can set the string in the Constructor as so. public class ControllerJSGeo { public String pId; public String testString {get;set;} public ControllerJSGeo(ApexPages.StandardController stdController){ pId = ApexPages.CurrentPage().getParameters().get('id'); testString = 'Hello'; } } Then get the value as so in the ...


2

Couple of issues here on your current code: RecordType personAccountRecordType = [SELECT Id FROM RecordType WHERE Name = 'Person Account' and SObjectType = 'Account'][0].RecordType; Account acc = new Account(lastname=guestsClass[0].lastName, RecordType = personAccountRecordType); RecordType is not a Type for variable declaration [0].RecordType -- there's ...


2

Since this property is derived, you don't need a setter, and you don't need to perform an assignment in your getter at all. Just do public Integer count { get { return Accounts.size(); } } Your Visualforce page should not compile, because count is not a list of objects to iterate over in the <apex:pageBlockTable>. To answer your ...


2

Here's your problem: List<ProcessHandlerShowAccounts.AccountParameter> testAcctList = new List <ProcessHandlerShowAccounts.AccountParameter>(); //accountId & name variables do not exist testAcctList.accountId.add('0011C000WW210zZ5'); testAcctList.name.add('create'); Your testAcctList variable holds a List, and that type has no accountId nor ...


2

You have the typo in your parameter at line 5. You should replace accountParamters with accountParameters public class ProcessHandlerShowAccounts { public class AccountParameter{ @InvocableVariable(required=true) public Id accountId; @InvocableVariable(required=true) public String name; } @InvocableMethod(label='...


1

There's a few parts of your code that are incorrect. document.getElementById('totalAwards').value = currentTotal; You can't get a variable by name; it is a construct that only exists while the server is rendering the page. Instead, you would need a real client-side DOM element to work with. var awards = document.getElementsByClassName('{!$Component....


1

Line 21 closes the loop, so you can't see "mq" beyond this line. If mq was meant to be used, it's likely you meant to place it later, perhaps around line 32. In the future, make sure you're matching up your indentation, because it would have been "obvious" why this was happening. Also, with regards to the if statement that doesn't have curly braces around ...


1

Why would you need to update your list of accounts in the finish method rather than at the end of your execute method ? Because your batch is already running mainly on your list of accounts, you can update your account within the execute methods itself. The blocker you are facing is probably around wholesaler which maybe should be included in your scope ...


1

I know two possible workarounds. Have a numbered list of possible parameters: 0 -> $recipient.title 1 -> $recipient.email 2 -> ... and then having a field value of Your title is {0} and in the template something like <apex:outputText value="{!relatedTo.MainMessageTop__c}" escape="false"> <apex:param value="{!recipient.title}"/> &...


1

Use setScale() method to round a decimal Decimal no = 1.23345; Decimal result = no.setScale(2); system.debug(result);


Only top voted, non community-wiki answers of a minimum length are eligible