21
votes
Accepted
Unfamiliar Syntax
This is called a type cast. Apex has what is called a strict, static typing discipline, which means that all variables and values have a type, and that type is declared for variables at the time of ...
17
votes
Accepted
Checking if element is in a Set
Please close the if condition with extra parens.
if(!existingAccTeam.contains(accId.User__c))
{
}
13
votes
Accepted
Static method cannot be referenced from a non static context: List<String>
The code you have posted does compile. To call it you will need to use the class name like this (because the method is static):
String[] stringArray = test_clonestring.generateStringArray(5);
This ...
13
votes
Accepted
Method does not exist or incorrect signature: void contains(String) from the type List<String>
You are deploying to production. list.contains was added in spring 2018 and i dont think its deployed to production instances yet. Its only in preview instances(sandboxes).
12
votes
Accepted
DML requires SObject or SObject list type error
You can't update SObjects using a map.
You have to do:
update pipelines.values();
12
votes
Call to another constructor must be the first statement in constructor block
I believe you should be doing it this way:
public class MyClass
{
final String someProperty;
public MyClass()
{
/* some default logic */
}
public MyClass(String ...
10
votes
Accepted
Illegal assignment from Datetime to Date
You can get the Date value from a Datetime instance by calling the date() method:
obj2.Date__c = obj1.CreatedDate.date();
If you're calling this method on a Datetime instance where you are not sure ...
10
votes
Accepted
Why is Map<Id, Set<Id>> an unsupported parameter type in future methods?
The list of primitives doesn't include Map, Set, or List. Therefore, what you have is a collection of non-primitives. They've also explicitly excluded Object, so you can't weasel your way around that ...
10
votes
Accepted
Why is CaseFeed.CreatedById Polymorphic?
Looks like before Spring 12, CreatedBy field, on some objects, could be linked with User or SelfServiceUser object.
Refer to screenshot below obtained from a 2010 blog post (link to blog is no longer ...
9
votes
Accepted
Unexpected token Error
The problem is probably that "commit" is a reserved word in Apex so you can't use it as a method or variable name. (When the compiler encounters such a word it has special meaning, it's part of the ...
9
votes
Accepted
Cannot Assign Private Variable In Test Class
You can't ordinarily "see" private members, but you can add @TestVisible to allow the unit test to see the variable:
@TestVisible DataToCompare compareAnIssue;
Then, your unit test can do stuff with ...
9
votes
Accepted
Call to another constructor must be the first statement in constructor block
I think this speaks somewhat to Apex inheriting so much from Java.
Try the same thing with a Java compiler:
public class HelloDog
{
public static void main(String[] args)
{
Dog myDog = new ...
9
votes
Accepted
Rollback Block?
You can't directly do this. While Java does have a syntax for this via anonymous classes, that isn't a language feature of Apex Code. The closest you can get would be to write an interface and ...
9
votes
Accepted
List.indexOf does not exist?
This method was introduced in the Spring '18 Release, which likely hasn't been rolled out to your org yet. You can see the calendar for major releases at https://status.salesforce.com/status. For ...
8
votes
Accepted
DML requires SObject or SObject list type: List<List<Commission_Line__c>>
When you have a Map<T1, T2> and call values, you get a List<T2>. So when you have a Map<T, List<T>>, you get a List<List<T>>. Basically, you're going to have to ...
8
votes
Accepted
What is the best way to cast/convert Map<String, SObject> to Map<Object, Object> and back again?
Looking in to this question, I realized that the type system is inherently broken. They have "fixed" Maps, it seems, but in a way that no longer lets you mix and match some types, especially Object.
...
8
votes
Accepted
SOQL Not Recognizing Field?
You need to add a preceding colon when using bind variables:
Correct
WHERE Field__c = :value
Incorrect
WHERE Field__c = value
See also: Using Apex Variables in SOQL and SOSL Queries (emphasis ...
8
votes
Accepted
Dynamic list using ternary if are not accepted by apex
That's not true, for the same SObject types, it works, you just forgot new:
List<SObject> lstSObject = (sentence ? new List<typeA__c>() : new List<typeA__c>());
And for different ...
7
votes
Accepted
Why does it say 'method does not exist' in my Apex code?
You'll get this error if you try to call a non-static method in a static method in the same class. Consider the example below:
public class TestClass {
public TestClass() {}
public void ...
7
votes
Accepted
Group By in Soql
There are a few different issues with your code.
All fields in your SELECT clause must be in your GROUP BY clause or wrapped in an aggregate operation.
You can't GROUP BY a Datetime field (chances ...
7
votes
Cannot Return a List of Strings - Void method must not return a value
You declared your return type as void. Change it to List<String>.
Incorrect
public static void generateStringArray
Correct
public static List<String> generateStringArray
It would be ...
7
votes
Call to another constructor must be the first statement in constructor block
Summary: Your initial assumption was (kind of) wrong. Which led to some interesting findings. Read on.
Consider the following code:
class DoNothing { Integer value; }
Integer getInt() {
return 5 ...
7
votes
Unfamiliar Syntax
To add to David's answer, the casts in this case are following the pattern of the expected JSON structure and how JSON.deserializeUntyped converts from JSON to Apex types. It looks like the JSON has ...
7
votes
Any way to qualify a custom class to distinguish it from a property?
You should be explicit when referencing the fields or types. Like you said yourself, Apex is case insensitive, so it's extra important to use the class name when referencing inner classes or static ...
7
votes
illegal assignment from object to id Error?
So the field juncRec.PDCN__c is a Lookup field, (Consider it as a text/ID field)
where as in your loop pdcn is an object/record.(Not a text field)
In your code
juncRec.PDCN__c = pdcn;
What you are ...
7
votes
Accepted
Variable not visible
If you don't specify a setter, you cannot set a variable's value. It is forever read-only, even to the class it is contained in. final is sufficient to make sure it cannot be modified later, but you'...
7
votes
System.StringException: Unexpected end of expression
cron expressions have 6 or 7 parts, and you've only included five.
From the Apex Scheduler documentation (emphasis mine)
The System.Schedule method takes three arguments: a name for the job, an ...
7
votes
Lightning Web Component (LWC) Class Definition Syntax
The navigation API uses JavaScript Mixins!
Mixin – is a generic object-oriented programming term: a class that contains methods for other classes.
Some other languages allow multiple inheritance. ...
7
votes
Getting a formula validation error, can anybody spot where I am off?
Your last IF block has no value_if_false.
What you have
IF (
ts2__Job__c.Days_Search_Open__c >= 91,
"91+",
)
What you need
IF (
ts2__Job__c.Days_Search_Open__c >= 91,
&...
7
votes
Accepted
Illegal assignment from List<Location> to List<System.Location>
This error actually crops up any time FSL is enabled in an org. There is a System type called Location, and also a Schema type called Location. The latter is what you query for, but the former is the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
compile-error × 278apex × 209
trigger × 38
soql × 27
unit-test × 19
visualforce × 16
formula × 16
error × 13
list × 10
batch × 8
query × 8
json × 8
formula-field × 8
controller × 7
deployment × 6
apexrest × 6
javascript × 5
validation-rule × 5
map × 5
string × 5
constructor × 5
lightning-web-components × 4
email × 4
managed-package × 4
visual-workflow × 4