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

Assigning an sobject to a map using .get
Hi
I am trying to use the following code for a bulkified trigger to roll up and update the number of course applications for each course. I then want to update each course with the aggregate value into the 'numberOfCourseApps' field. I'm pretty sure that I have the right syntax but get an error - incompatible key type eor Object for MAP.
Is this possible ? If not how can I then take the course ID and update the 'numberOfCourseApps' field
Map<course__c, Integer> coursesToassigntsMap = new Map<course__c, Integer>(); set<Id> courseIds = new Set<Id>(); for(Course_Application__c a: trigger.new){ courseIds.add(a.Id); } for (AggregateResult agr :[select count(id) idcount,course_del__c from Course_Application__c where course_del__r.Id in :CourseIds and status__c='Ordered'group by course_del__c]) { coursesToassigntsMap.put(agr.get('course_del__c'), integer.valueof(agr.get('idCount'))); }
i solved it with this
All Answers
Hello
What evere you have written the logic, it is perfectly right but the Map declaration is wrong.
First thing you need to understand , for map first we declare the key , then values,(for unique identification of records)
below is the right syntax for declaring a Map
but i wanted set the key as the object, each object has a value asssigned to it
i solved it with this