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

Help with Illegal assignment error!!
Hi.
I am having a Map
Map<String,Set<Id>> testmap= new map<String,Set<Id>>();
and values which i am giving to map are as below.
if(testmap.containsKey(text)){
testmap.get(text).add(u.id);
}else{
testmap.put(text,new Set<Id>{u.id})
}
Now i want to collect id value and assign it to a field on account and update it.But When i use values from map method,i am getting below error.
Illegal assignment from List<Set<Id>> to Id
for(account acc:trigger.new){
acc.customtextfield__c =testmap.values();
}
I understand my mistake that i am assigning Map value to list.Could you please guide how can i solve this?
I am having a Map
Map<String,Set<Id>> testmap= new map<String,Set<Id>>();
and values which i am giving to map are as below.
if(testmap.containsKey(text)){
testmap.get(text).add(u.id);
}else{
testmap.put(text,new Set<Id>{u.id})
}
Now i want to collect id value and assign it to a field on account and update it.But When i use values from map method,i am getting below error.
Illegal assignment from List<Set<Id>> to Id
for(account acc:trigger.new){
acc.customtextfield__c =testmap.values();
}
I understand my mistake that i am assigning Map value to list.Could you please guide how can i solve this?
Can you please add another iterative for loop to break the Set values and add to this field, as below.
Please mark this as the best answer if it has answered your question.
Thanks,
Rohit Alladi
'Loop variable must be of type Set<Id>' for line below
for(id idset:testmap.values()){
}
Please mark this as the best answer if it has answered your question.
Thanks,
Rohit Alladi
its not acc.customtextfield__c
its customlookup field.
so i am having Illegal assignment from Set<Id> to Id error now.
linda
so send me your coad and also tell me you are requirment clearly thats not clear first of all you have to know that we can map onlysame variable type fields
Thanks
Yea.I agree.
All my rest code works fine.Just that i am having a Map<String,set<id>> i am trying to get map.values() and assign to a lookup field on account then update account in my trigger.
And above is that part of code which i am having issue with.
Hope you could please take a look at above code and guide me .
Thank you.
You could save only one id value into the lookup field created, incase if you would want to store all the id values from a set, please create a text field and reference that.
Thanks,
Rohit Alladi
So do you mean i have to create a custom text field which will save id.then query that field and assign to my custom lookup field.?
Could you please be little more clear Rohit.???
Its like i am updating a object lookup field by fetching it in map.I am using map as i am comparing other fields and doing some data check and then saving in map with id.
So here's the thing, if you would want to create a lookup field and want the user to navigate to that record on a click , then you will be able to save only one id value into it.
But, as per code i see you are wanting to save more than one value into that field, i.e. you will be needing a bigger field (customtext field) to incorporate all the values from the map into this .
All the logic is totally based on the requirement you have.
1 value into a field vs many values into a field.
Hope that helps.
Thanks,
Rohit Alladi
If you would want to save only one account value, please use it this way.
Hope this finds your answer.
Thanks,
Rohit Alladi