function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NishaCNishaC 

Problem in Map

hii

i have a problem with mapping 

i am using map<id,Decimal> mapgrandParentsCounts = new map<id,Decimal>() 

for SERVICE__c object

when using for loop

i want to get all the values of service object for that ID

for(id gpAcc : mapgrandParentsCounts.keyset()) {

}

 

but here i am getting only the decimal value

i want service NAME, CITY,ADDRESS from this for loop

 

any HELP ??

liron169liron169
Don't sure I understand how the SERVICE__c object relate to your map.
Is the ID in the map is for SERVICE__c.

however your map contain only decimal value for each ID so this is what you get.

maybe your map should be:
Map<ID, SERVICE__c) servID_servObj_map=new Map<ID, SERIVEC__C>();

and in the loop:
for(id gpAcc : mapgrandParentsCounts.keyset()) {
servID_servObj_map.get(gpAcc).NAME;
servID_servObj_map.get(gpAcc).CITY;
servID_servObj_map.get(gpAcc).ADDRESS ;
}

NishaCNishaC

this map is in for loop of service object

for(Service__c srobj: servicelist){

           if(mapgrandParentsCounts.containskey(sr.Customer__r.Grand_Parent_Account__c){

           }

}

 

it is showing the  correct result but now i want that when i use for loop of this map

then i want to show name,city and address of this 

for(id gpAcc : mapgrandParentsCounts.keyset()) {

how can i get name,city from this map

 

any idea?

liron169liron169
Again, your map contain ID --> Decimal values.
It doesn't contain NAME/CITY/ADDRESS, so you can't get them from the map.

You should create other/another map that contain ID-->Object as I wrote in the previous message