Hot answers tagged

8 votes
Accepted

How can I extend the `Set` class?

No, it is not possible to extend a class if it is not abstract or virtual. Unlike in Java in Apex all classes are final by default. But you can use "composition (over inheritance)" and write ...
7 votes

No viable alternative at character " "

Double quotes " are not used for SOQL query to specify a filtered value in conditional expression. You can use single quotes with escaping \'. Take a look at Quoted String Escape Sequences public ...
6 votes

How can I extend the `Set` class?

No, it is not possible to do this through extending (inheritance) or implementing (interfaces). We'd need generics/templates in the type system, and Apex doesn't provide that. You can make a class ...
  • 50.6k
4 votes
Accepted

Error on Trigger: Method does not exist or incorrect signature: void CheckPreviousYearEntryByPhoneNumber(list) from type FreeWaterSchemeClass

Apex allows you to overload methods, which means they all have the same name but take different parameters. "Different" in this case means either a different number of parameters and/or ...
  • 2,317
4 votes
Accepted

Checking Equality in Lists of Apex Classes

I recommend you also implement hashCode per the contract in Java Object for hashCode that includes: If two objects are equal according to the equals(Object) method, then calling the hashCode method ...
  • 131k
4 votes
Accepted

What is the best practice regarding organizing Apex code

This is a feature that the community has wanted since at least 2009. The ability to organize your code metadata in to folders. It can make finding and managing code easier. Of course, this is only ...
  • 445k
4 votes

Create an reactive auxiliary class in the LWC component

Unfortunately, an internal state mutation will not be observed by the LWC engine, even though the code uses @track decorator on a complex object (e.g. an instance of the custom UserData class). But ...
4 votes

Lombok for Salesforce Apex

Illuminated Cloud (paid plugin for IntelliJ) has live templates for Apex and Lightning Web Components to help save time. Likewise, you can create your own live templates for IntelliJ if desired. There'...
3 votes
Accepted

Throw Error on Two Record Merge

You've outlined the problem well In before delete trigger, you have access to the child records but no MasterRecordId for the merging operation In after delete trigger, the child records have already ...
3 votes

covering test class if condition for a variable defined in method

I suspect that this is mostly an issue of how you've chosen to share your code (i.e. what you've shared with us is not your actual code, and you've made some mistakes in trying to obfuscate your code),...
  • 50.6k
3 votes

Is there any way we can identify the insertion/updation of record is happened through UI or not

As you are already using Apex, you can make use of Quiddity. As you can see in the docs, a ENUM value of VF will state that the "Execution event is triggered by a Visualforce page". System....
  • 4,819
2 votes

Update field using Apex

The method you're looking for is System.now() but you'll also need to loop over your collection (List<Quality>) to update each of the records: public class populateQualityAge { public ...
  • 3,704
2 votes

Enable Map type to hold Integer, String, Boolean, Map, List... objects? (But not generic Object)

For cases beyond what can be supported with JSON.deserialize, consider using JSON.deserializeUntyped. This mode is slightly more complicated, as it returns an Object that can be a List<Object> (...
  • 445k
2 votes
Accepted

Why isValid is true but failed to deploy with error 'Dependent class is invalid and needs recompilation'?

Often this error is introduced when you forget to include new fields in your deployment package. However, it can be introduced with a code only change. A very simple example to illustrate is as ...
  • 144k
2 votes
Accepted

Trigger to compare records in different Objects not working as expected

You should never query the entire database (a SOQL with no filters and no LIMIT). In addition, keep in mind that standard Set<String> is case sensitive, so it is typical that you'd want to ...
  • 445k
2 votes

Whats wrong with my Apex Class? It throws ERROR Please reference your WSDL or the describe call for the appropriate names

If you want to query the parent object field in SOQL you should use __r . Can you change you query as below and try. SELECT id,Name,Customer__r.Name FROM Room__c
2 votes

Illegal assignment from List<String> to List<Order> (4:21)",

The error tells you exactly what is wrong, as does the documentation on the String.split method. It returns List<String>, not List<Order>. Incorrect List<Order> values = myString....
  • 144k
2 votes

Coin Change program in apex

From a brief glance, it looks like the primary issue is that your List<Integer> last is initialized with the coins in the wrong order. (+edit: After more work, this isn't the issue. The ...
  • 50.6k
1 vote
Accepted

How to handle and get duplicate values after receiving the duplicate value error message

Database.DuplicateError is only for Duplicate Rules. Instead, you can check getStatusCode on the error and compare it with StatusCode.DUPLICATE_VALUE. However, that still won't tell you which record ...
  • 445k
1 vote

CPU Time limit exception inside trigger

Your code has a lot of logic bugs in it. resultMapMPAT should be a plain old Set, Trigger.new can't be used in an after delete trigger, you should never truncate 18-character ID values like that (it's ...
  • 445k
1 vote
Accepted

use method() from other apex classes into the VF page

The only alternative I know of is using a controller extension. Either build your method() in the controller extension, or refer it from the controller extension if it's already present in some other ...
1 vote

in test class should pass lastweek is not equal to currentweek

The fact that you can't cover that code indicates you have a logic bug in your code. It literally cannot be covered in a unit test, because of this code: if(Test.isRunningTest()){ ...
  • 445k
1 vote
Accepted

Apex Class CallOut

First of all, have you considered using an External Service, instead? External Services allow you to make direct API calls to other servers without any direct Apex code. Set up an Authorization ...
  • 445k
1 vote
Accepted

Apex Test Class Fetching Article Details

In general, tests follow the "AAA" pattern Arrange, by creating/inserting your test data Act, by calling the one method you want to test Assert, by gathering the results of running the ...
  • 50.6k
1 vote

Help with Parent-Child relationship in apex class

Values like RecordType.DeveloperName are actually static field references used for dynamic Apex. You need to use the variable name you used (c) to access a record's data. In addition, parent and child ...
  • 445k
1 vote

Whats wrong with my Apex Class? It throws ERROR Please reference your WSDL or the describe call for the appropriate names

Nicely the error message tells you what's wrong. As per the other answer you need to change Customer__c custom field name to Customer__r in order to then access a field from that related object, as in ...
  • 28.7k
1 vote

How to delete a class from production using destructiveChanges.xml

Or just run the sfdx force:source:delete in your prod org :) e.g. sfdx force:source:delete --sourcepath force-app/main/default/classes/classToDelete.cls --noprompt -l RunLocalTests -u PROD
1 vote
Accepted

Pointers on writing test class for ApexPages.StandardController Controller

I will recommend you to start using trailhead to learn about test classes https://trailhead.salesforce.com/modules/apex_testing Also please check below post https://developer.salesforce.com/docs/...

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