10
votes
Accepted
System.ListException: One or more of the items in this list is not Comparable
There's a subtle bug involved here, which I was able to replicate with the following execute anonymous:
interface MyInt extends Comparable {
}
class SuperC implements MyInt {
public Integer ...
5
votes
Apex equivalent of Java Comparator
As requested in the idea Support apex List sorting using a Comparator, the Winter '24 release brings a native Comparator interface and corresponding List sort method overload to work with it.
You can ...
4
votes
Accepted
Invalid Type for Comparable Implementation
CaseInfo is in the viewAllCaseCommentsActivitiesController class, so you need to use the fully-qualified name:
List<viewAllCaseCommentsActivitiesController.CaseInfo> caseList = new List<...
4
votes
SOQL Error in Compare Date
The issue you have got here is not just about comparing date fields, it is more about comparing two fields of the same record. Please refer to this post:
https://developer.salesforce.com/forums/?id=...
4
votes
Get most recent dates from a AggregateResult list by comparing
The compareTo() method of a class that implements the Comparable interface is not run when you add things to a list, it's run when you call .sort() on the list.
You also need to have compareTo() ...
4
votes
Efficiently sorting a list of Work Order records by a Sequence
As I've said ... at ... least ... four times, just because you have a for loop inside another for loop, does not automatically make this a Bad Thing. Feel free to read the answers for more information....
3
votes
Comparing Two Lists of Different Objects
Yep, using a map is the way to go here.
Any time that you find yourself doing something like this
for(item1 :collection 1){
for(item2 :collection 2){
if(item1.MyField__c == item2....
3
votes
Accepted
Efficiently sorting a list of Work Order records by a Sequence
Consider mapping all your WorkOrders/Wrappers by a combination key (i.e UniqueKey__c + '.'+ Work_Order_Sequence__c.leftPad(10, '0') ).
sort your combo key
list comboKey = new List(mapWO.keyset()); ...
3
votes
Accepted
Nested Compareable Methods on Wrapper Class
It's really no more complicated than a few extra if statements.
if(sActivityDate > wrap.sActivityDate) {
return 1;
}
if(sActivityDate < wrap.sActivityDate) {
return -1;
}
if(...
2
votes
Sorting of fields of custom object using comparable in a wrapper
Yes, you can add fields to compare when the child count is the same:
public Integer compareTo(Object instance)
{
PageFilter that = (PageFilter)instance;
if (that.totalCount == this.totalCount)...
2
votes
ERROR: Dynamic sorting in Wrapper class' column header
You should just do this sorting client side. There are plenty of solutions to this problem already out there. But the reason you're getting the error is you're basically trying to do:
String ...
1
vote
Sort List by multiple criteria
Yes it is.
The naive approach would be to simply nest if() statements inside the blocks where the previous criteria are equal.
e.g.
if(field1 < otherObject.field1) {
return -1;
} else if(field1 ...
1
vote
Accepted
Testclass for wrapper class implements Comparable and contentdocumentlink
In your test class you should set the current page via Test.setCurrentPage(page) method. Then you can add to the page the id of the record you're using in your test.
Replace DokuBox_6 D6 = new ...
1
vote
Comparing Two Lists of Different Objects
One other suggestion I'd add is that if you are mapping fields, you can Custom Metadata to make that more flexible. You can create a new MD object to store the mappings, and then have fields that ...
1
vote
Is there a way in process builder to check if a date is set and if so, if it is greater than something?
If both conditions are related to same field, then there is no sence to add them at all as any Opportunity will fit the "1 OR 2" criteria. You can use "No criteria—just execute the actions!" option ...
1
vote
Accepted
How can we sort based on the number of matched filtered
we're trying to search for 2 skills and 1 training from the table result above. The contact/employee record that has 2 skills should appear first before the the contact/employee record that has 1 ...
1
vote
Accepted
how to find the period between two periods date?
There is no way to achieve you goal as 25 is not between 5 and 25.
Or you could simply do this which would be best if the period changes for each records:
for(sObject rec : YOURRECORDS){
if(...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
comparable × 25apex × 20
wrapper-class × 11
sort × 7
visualforce × 4
soql × 3
map × 3
date × 3
unit-test × 2
list × 2
casting × 2
trigger × 1
process-builder × 1
controller × 1
contentversion × 1
custom-controller × 1
compile-error × 1
contentdocumentlink × 1
text × 1
inner-class × 1
boolean × 1