Skip to main content
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 ...
sfdcfox's user avatar
  • 497k
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 ...
Daniel Ballinger's user avatar
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<...
sfdcfox's user avatar
  • 497k
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=...
Lance Shi's user avatar
  • 13k
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() ...
Derek F's user avatar
  • 62.7k
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....
sfdcfox's user avatar
  • 497k
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....
Derek F's user avatar
  • 62.7k
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()); ...
Gauge Boson's user avatar
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(...
sfdcfox's user avatar
  • 497k
3 votes
Accepted

Problems implementing comparable class

As the error says, you need to return an Integer. There is no such thing as an Integer field in Salesforce. All Number fields return a Double even if they have 0 trailing digits. Also, use public, ...
Adrian Larson's user avatar
  • 151k
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 ...
Adrian Larson's user avatar
  • 151k
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)...
Adrian Larson's user avatar
  • 151k
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 ...
Derek F's user avatar
  • 62.7k
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 ...
RubenDG's user avatar
  • 8,762
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 ...
BritishBoyinDC's user avatar
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 ...
Alexey Yezhkov's user avatar
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 ...
Daniel Ballinger's user avatar
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(...
Eric's user avatar
  • 54.2k

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