Skip to main content
Miriam Caldwell (MassMutual) 님이 #Apex에 질문했습니다
Hi, 

I'm very new to APEX so please bear with me.  I have 2 different map strings objects and I'm trying to concatenate them using the map method .putAll, however it's replacing instead of concatenating.   

if(aresp.getBody() != null ||  bresp.getBody() != null ){

                Map<String, Object> aretVal;

                Map<String, Object> bretVal;

                if(aresp.getBody() != null)

                {

                    System.Debug('****** raw a Response: ' + aresp.getBody());

                    aretVal = (Map<String, Object>) JSON.deserializeUntyped(aresp.getBody());

                }

                System.Debug('****** aretVal: ' + aretVal.size());

                System.Debug('****** aretVal: ' + aretVal);

                if(bresp.getBody() != null)

                {

                    System.Debug('****** raw b Response: ' + bresp.getBody());

                    bretVal = (Map<String, Object>) JSON.deserializeUntyped(bresp.getBody());

                    System.Debug('****** bretVal: ' + bretVal.size());

                    System.Debug('****** bretVal: ' + bretVal);

                }

                

                if(!bretVal.isEmpty())

                    aretVal.putAll(bretVal);

putAll(sobjectArray)

Adds the list of sObject records to a map declared as Map<ID, sObject> or Map<String, sObject>.
답변 6개
  1. 2025년 5월 12일 오후 1:01

     Hi Miriam, 

     If putAll() isn't combining as expected, double-check that both maps are initialized and contain compatible key types. I’ve seen this trip up many early Apex learners. For mapping visuals or grouping, we've found

    Mango Map simplifies many workflows. 

0/9000