You need to sign in to do that
Don't have an account?

How does one combine two lists, merge them, remove duplicates, and then sort in Apex?
In an Apex class, I'd like to take two lists of contacts, merge them, remove duplicate contacts, and then sort them? Any suggestions? Thanks.
Please try the code provided below :
Please let me know how this works for you, mark this as Solved if this helps you so that others can view it as a proper solution.
Thanks,
Apoorv
All Answers
Hope this helps
adding the above code at the end of previous block will give you a list again.
The example here sorts contacts by name. You can sort by other fields as well by implementing comparable interface. You can find more infornation in this link https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_list_sorting_sobject.htm
Thanks
Please try the code provided below :
Please let me know how this works for you, mark this as Solved if this helps you so that others can view it as a proper solution.
Thanks,
Apoorv