You need to sign in to do that
Don't have an account?
SKT
Apex Error: Illegal assignment from List<String> to String
I have a requirement to fetch Contact Region from Contact and update the same on User.
Here is my logic:
now when i am trying to run the above logic, i am seeing this error:
Can anyone please let me know how to overcome this error?
Thanks!
Here is my logic:
list<user> user = [SELECT name,Region__c from User where isactive = true]; Set<string> str = new Set<string>(); for(user u1 : user){ str.add(u1.name); } List <Contact> Contact = [ select id,Salesforce_User__c,Contact_Region__r.name from contact where Contact_Region__c != null]; Map<id, list<String>> usertcMap = new Map<id, list<String>> (); for (Contact Contacts : Contact) { if(!usertcMap.containsKey(Contacts.Salesforce_User__c)) usertcMap.put(Contacts.Salesforce_User__c, new list<string>{Contacts.Contact_Region__r.name}); else usertcMap.get(Contacts.Salesforce_User__c).add(Contacts.Contact_Region__r.name); } list<User> userupdates = new list<user>(); for(User us : user){ if(usertcMap.containsKey(us.id)) { list<string> allProsList =usertcMap.get(us.id); us.Region__c = allProsList; userupdates.add(us); } } if(!userupdates.IsEmpty()) update userupdates;
now when i am trying to run the above logic, i am seeing this error:
Illegal assignment from List<String> to String
Can anyone please let me know how to overcome this error?
Thanks!
Hi SKT,
Please find the solution.
Please mark it as the Best If it helps you.
Thank You
All Answers
Try the below code :
Thanks,
Maharajan.C
Hi SKT,
Please find the solution.
Please mark it as the Best If it helps you.
Thank You
us.Region__c = String.join(allProsList,',');
Thanks,
Maharajan.C