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
13 votes
Accepted

Why do primitive variables behave differently than object variables when being passed through void methods?

This is because objects and primitives behave differently in apex. “In Apex, all primitive data type arguments, such as Integer or String, are passed into methods by value. This means that any ...
Sebastian Kessel's user avatar
11 votes
Accepted

Public Static List Method

Here are the components of that method declaration: Access Modifier - public Static vs. Instance - static Return Type - List<List<SObject>> Method Name - searchContactsAndLeads Parameters ...
Adrian Larson's user avatar
  • 150k
11 votes
Accepted

Calling aura:method and return value

Methods in Lightning components do not return a value, also came to the same outcome as yourself. However, I did learn to use and love component events with dynamic event handlers. What you can do ...
Adam's user avatar
  • 361
8 votes

How to refactor Synchronous code with future method

There is no choice here but to move the "association code" to a method that you call from the end of the future method and the other classes: public class MyUtilClass { @future public static ...
Keith C's user avatar
  • 136k
8 votes
Accepted

Does an Apex Class run linearly (procedurally?)?

There's a few different mechanisms that cause Apex code to be executed, so it depends on the context. Execute Anonymous/Triggers Code is executed from top-to-bottom, with methods and so on being ...
sfdcfox's user avatar
  • 494k
7 votes

Calling aura:method and return value

+1 for Adam's repsonse. Update: One can now use a return statement to pass back the desired response. Documentation: https://developer.salesforce.com/docs/atlas.en-us.210.0.lightning.meta/lightning/...
Luke Freeland's user avatar
7 votes
Accepted

Overloading method return type in Apex

Yes, if the method signature is different you can have a different return type In a class you can have Integer add(Integer) String add(String) But you can't have Integer add(Integer) String ...
benahm's user avatar
  • 2,597
7 votes
Accepted

Access one methods input parameters in another method of same class

There are two different way to go about it. You could make static variables to hang on to this information: static String requestFirstName; @HttpPost global static String doPost(...) { ...
Adrian Larson's user avatar
  • 150k
7 votes
Accepted

Multiple Methods on Trigger

To directly answer your question, yes, it's common practice to include multiple methods or pieces of functionality in a trigger. Methods are run in sequence, and any exception that occurs in any of ...
David Reed's user avatar
  • 93.1k
7 votes
Accepted

Question About Static Methods

Something that is static is "outside" of instance storage. In other words, it's a shared element across all copies of a class. For example, given this class: public class MyClass { ...
sfdcfox's user avatar
  • 494k
6 votes
Accepted

Utility method checking if input is numeric - implementation advice

You can simply use instanceof here: public static Boolean isValueNumeric(Object value) { return value instanceOf Double; } Some tests can confirm its veracity: system.assert(isValueNumeric(20));...
Adrian Larson's user avatar
  • 150k
6 votes

Is there any way to make an Apex method parameter lazy?

Not exactly, but you can do something like lazy evaluation by making use of the Callable interface (or rolling your own). Here's an example using Callable... To start with, a test: @IsTest private ...
Aidan's user avatar
  • 13.7k
6 votes
Accepted

Unexpected token: 'Map' for method that returns a Map

map is a keyword, and it cannot be used as an identifier (the name of a variable, method, etc...). Chose a different name for your variable, update the lines of code which use that variable, and you ...
Derek F's user avatar
  • 62.1k
5 votes
Accepted

Pass null to method in test class

It looks like a condition ambiguity in the code. You want to prevent null and blank to enter in main code. But if(sourceSystemID != '' ||sourceSystemID != null) will not work. If you pass a null, it ...
Ashwani's user avatar
  • 22.6k
5 votes

Calling a method with List<string> Ids parameter

Apex has neat collection initialization syntax (for arrays, lists, sets and maps) that allows less verbose code: innerclassList = OuterClassName.methodname(new List<String>{id1, id2}); Better ...
Keith C's user avatar
  • 136k
5 votes
Accepted

convert hex value to integer

You can convert hex to a value using a few primitive functions: String hex = '0123456789abcdef'; String[] hexValue = sourceHex.split(''); Decimal result = 0; for(Integer index = 0; index < ...
sfdcfox's user avatar
  • 494k
5 votes
Accepted

Update Parent when all children have the same field

Typically the easiest way to implement such requirements is to have two rollups which you might name for example Child_Count__c and Ready_Count__c. If your relationship is Lookup rather than Master-...
Adrian Larson's user avatar
  • 150k
4 votes
Accepted

Calling an Apex method on an Apex Trigger

your method should be static public static void mailSending(){ //rest of your code } now you can call this method using EmailExample.mailSending(); if you don't want to use static method then ...
Ratan Paul's user avatar
  • 22.7k
4 votes
Accepted

Can we straightly send to printer from VisualForce?

Whatever you are asking is something close to IoT (Internet of things). There have been some integrations between the printer and Visualforce (or any hosted page). However, there we also need to use ...
Ashwani's user avatar
  • 22.6k
4 votes

Access one methods input parameters in another method of same class

Simply change your signature to: public static void sendErrroMail(String errorMessage, String firstName){ and then call it like this: sendErrroMail(e.getMessage(),firstName);
Eric's user avatar
  • 54.2k
4 votes

Difference between lock row and Record Currently Unavailable

The two errors are essentially the same thing, but one is designed to appear in Apex/API contexts, the other is meant for UI contexts (e.g. a user is editing a record in the UI). The cause is ...
sfdcfox's user avatar
  • 494k
4 votes
Accepted

Calling apex imperative method in lightning web component needs two click to show data

Assuming your event fire mechanism (it's not clear in your code where exactly that is) is behaving correctly, the pubsub mechanism will pass the event to any subscribing component listening to ...
tsalb's user avatar
  • 3,735
4 votes
Accepted

Help with Rest Resource

You need to annotate your POST handler method with the @httpPost decorator. That way Salesforce knows to run that method when the REST Request method from outside is set to "POST". It should ...
John Thompson's user avatar
4 votes

Question About Static Methods

You call a static method like so: MyClass.myMethod(/*parameters*/) You call an instance method like so: new MyClass().myMethod(/*parameters*/)
Adrian Larson's user avatar
  • 150k
4 votes
Accepted

Method does not exist or incorrect signature: void getOppty(Id) from the type classname (108:19)

The error is providing you with some good, albeit subtle, information. In programming, data types matter. A Set<Id> is different from an Id, which is different from an Integer, etc... and in ...
Derek F's user avatar
  • 62.1k
4 votes
Accepted

Passing a method as parameter from a parent LWC to a chil LWC

Inside a component's markup, the on prefix is reserved for event handlers (e.g. you can't declare a variable called onsuccess). Inside the component that is dispatching the event, you'll find code ...
sfdcfox's user avatar
  • 494k
3 votes

Calling an Apex method on an Apex Trigger

The issue is that the method has been defined as an instance method, meaning you cannot access it directly, you first must instantiate the class. For example, you would have to do the following to ...
Adam's user avatar
  • 361
3 votes

Value '[X]' cannot be converted from Text to core.apexpages.el.adapters.metadata.VFSObjectELAdapter

Looks to be same issue as posted here in the Developer Forums, you may want to check that the object is properly instantiated and that the mapping param name from VF page is correct. It should be &...
Gaurav Kheterpal's user avatar
3 votes
Accepted

Datetime Format Method not working as desired

Look at Java SimpleDateFormat. These format strings are case-sensitive, as different casings of the same letter can have different meanings. m outputs Minute in hour. M outputs Month in year. So ...
Adrian Larson's user avatar
  • 150k
3 votes
Accepted

Calling a method with List<string> Ids parameter

List<InnerClassName> innerclassList = new List<InnerClassName>(); List<String> strList = new List<String>(); strList.add(id1); strList.add(id2); innerclassList =...
sfdcNani's user avatar

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