You need to sign in to do that
Don't have an account?
Harshal Katole 7
comparing two multiselectpicklist value
object = contact
multiselect picklist 1 = abc__c => values : 1,2,3,4,5,6,7
multiselect picklist 2 = xyz__c => values : 1,2,3,4,5,6,7
scenario : check both field value not same while creating a record. if its same then thrown error.
not working ?
public class checkdupcontact{
public static void invoke(list<contact> cc){
for(contact a : cc){
list<string> VarList1 = a.abc__c.split(';');
list<string> VarList2 = a.xyz__c.split(';');
set<string> VarSetAdd1 = VarSetAdd1.addAll(VarList1);
set<string> VarSetAdd2 = VarSetAdd2.addAll(VarList2);
if(VarSetAdd1.containsAll(VarSetAdd2)){
a.addError('error');
}
}
}
}
multiselect picklist 1 = abc__c => values : 1,2,3,4,5,6,7
multiselect picklist 2 = xyz__c => values : 1,2,3,4,5,6,7
scenario : check both field value not same while creating a record. if its same then thrown error.
not working ?
public class checkdupcontact{
public static void invoke(list<contact> cc){
for(contact a : cc){
list<string> VarList1 = a.abc__c.split(';');
list<string> VarList2 = a.xyz__c.split(';');
set<string> VarSetAdd1 = VarSetAdd1.addAll(VarList1);
set<string> VarSetAdd2 = VarSetAdd2.addAll(VarList2);
if(VarSetAdd1.containsAll(VarSetAdd2)){
a.addError('error');
}
}
}
}
Are u getting any error? Based on my understanding you will get the runtime error due to the below lines:
set<string> VarSetAdd1 = VarSetAdd1.addAll(VarList1);
set<string> VarSetAdd2 = VarSetAdd2.addAll(VarList2);
Please update the your code as below:
Thanks,
Maharajan.C
public class checkdupcontact2{
public static void invoke(list<contact> cc){
for(contact a : cc){
if( a.abc__c != null && a.xyz__c != null ){
list<string> VarList1 =a.abc__c.split(';');
list<string> VarList2 =a.xyz__c.split(';');
set<string> VarSetAdd1 = new set<string>();
VarSetAdd1.addAll(VarList1);
set<string> VarSetAdd2 = new set<string>();
VarSetAdd2.addAll(VarList2);
if(VarList1.contains(VarList2)){
a.addError('error');
}
}
}
}
}