You need to sign in to do that
Don't have an account?
Cindy GUILLET
Remove duplicates in a string
Hello,
I have a flow which add informations from children records of cases.
In the text field I obtain : 1.5.663,1.5.458,1.5.663,1.4.985
I need to remove duplicates in order to display : 1.5.663,1.5.458,1.4.985
I wrote a trigger based on what I found on many forums but I'm new on Apex and I can't figure it out.
trigger Trg_Case on Case (after update) {
For(Case myCase: Trigger.new){
if(myCase.ChildrenVersions__c != null && (myCase.ChildrenVersions__c).contains(',')){
string reports = myCase.ChildrenVersions__c;
List<String> l = new List<String>(new Set<String>(reports.split(',')));
String uniqueReports = String.join(l, ',');
}
}
}
Thanks for your answers
I have a flow which add informations from children records of cases.
In the text field I obtain : 1.5.663,1.5.458,1.5.663,1.4.985
I need to remove duplicates in order to display : 1.5.663,1.5.458,1.4.985
I wrote a trigger based on what I found on many forums but I'm new on Apex and I can't figure it out.
trigger Trg_Case on Case (after update) {
For(Case myCase: Trigger.new){
if(myCase.ChildrenVersions__c != null && (myCase.ChildrenVersions__c).contains(',')){
string reports = myCase.ChildrenVersions__c;
List<String> l = new List<String>(new Set<String>(reports.split(',')));
String uniqueReports = String.join(l, ',');
}
}
}
Thanks for your answers
Try the following code it may be helpful for you and it working fine in my ORG:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
All Answers
Try the following code it may be helpful for you and it working fine in my ORG:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
Please try below and let me know if that works:
Try below code in your trigger to remove duplicate values of a String it works fine:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
thank you for your help !
I used Deepali code and it works.
Final code :
public class ReplaceDuplicate {
public static void getTemplate() {
String str = '1.5.663,1.5.458,1.5.663,1.4.985';
List<String> duplicateRemoveList = new List<String>(new Set<String>(str.split(',')));
String uniquestr = String.join(duplicateRemoveList, ',');
System.debug('uniquestr'+uniquestr);
}
}