You need to sign in to do that
Don't have an account?
updating object value in Maps
Hi , iam new to SFDC and came to know u gus here help a lot. i have been facing this problem since three days.
Iam here trying to update Map value
Map<Id,Object> objMap=new Map<Id,Object>([select id,A,B from Object]);
for(Id tkId: taskIds)
{
objMap.get(Trigger.newMap.get(tkId).whatId).A='Hi' ;
}
update objMap;
this is giving me the error. same kind of thing working for lists. but not for maps.
can u help me out here by looping thru the map and update one of the obejct values.
Note: Trigger.newMap.get(tkId).whatId gives me the Id in Map
thanku.... rock with force........
Hi Steve,
finally i am able to search in google with ur piece of advice. i found related code at
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_shopping_cart_example_code.htm.
according to my requirement, i have written my code like this. It worked
Map<Id,Application> appMap=new MapMap<Id,Application>([select id,Status from Application]);
List<Application> appList=[select id,Status from Application];
for(Application app:appList)
{
app.Status='Submit';
appMap.put(app.Id,app);
}
update appMap.values();
Thanku so much
All Answers
Well, I don't know about your code since you've only posted snippets, however the "update" statement expects a List<SObject> as an argument, not a Map.
So, if you have a map and you want to extract the values of the map for update. The "values()" method pulls all of the values from a Map and makes a List which you can then feed into the update statement.
update objMap.values();
Best, Steve.
Hi Steve, thanks for ur help.
I have
Map<Id,Application> appMap=new Map<Id,Application>([select id,Name,Status from Application]);
Here Application is an Object . Status is the field of Application. Now I have to update Status field for all set of Task Ids. I have taskIds with me.
Task ids are some of Trigger ids. So, iam using trigger.newMap down here
appMap.get(Trigger.newMap.get(ids).whatId) gives the Id of appMap.
for(Id ids: TaskIds)
{
appMap.get(Trigger.newMap.get(ids).whatId).Status='Submit'; // Status is picklist field.
}
Can u give me the piece of code bocz i have no idea how to use map.values(). I couldnt find about it anywhere in google
Hi Steve,
finally i am able to search in google with ur piece of advice. i found related code at
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_shopping_cart_example_code.htm.
according to my requirement, i have written my code like this. It worked
Map<Id,Application> appMap=new MapMap<Id,Application>([select id,Status from Application]);
List<Application> appList=[select id,Status from Application];
for(Application app:appList)
{
app.Status='Submit';
appMap.put(app.Id,app);
}
update appMap.values();
Thanku so much
Thank you!