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

Possible bug with Maps

Hi All,


Possible bug with Apex Maps.  Am seeing very strange and prohibitive behaviour - any comments welcome.


Code is as follows - idea is to take some map values to a list, then update them.  


In this example there is one record in the map - lets try to put it in a list then update it.


// update positions
	       List<Position__c> posUpdates = new List<Position__c>();
		posUpdates = posMap.Values();
		system.debug('posUpdate record -->'+posUpdates[0]);
		system.debug('id ->'+posUpdates[0].id);
		system.debug('Affiliation_Final__c >'+posUpdates[0].Affiliation_Final__c);
		update posUpdates;

 K - now what does the debug log show?


USER_DEBUG|[403]|DEBUG|posUpdate record -->Position__c:{Affiliation_Final__c=a03N0000000mQEKIA2 RecordTypeId=01290000000f9xxAAA, Position_Type__c=Junior Warden, Date_of_Installation__c=2013-03-12 00:00:00, Id=a07N0000000iA6lIAE }
11:21:17.825 (825418000)|USER_DEBUG|[404]|DEBUG|id ->null
11:21:17.825 (825468000)|USER_DEBUG|[405]|DEBUG|Affiliation_Final__c ->null
11:21:17.825 (825516000)|DML_BEGIN|[406]|Op:Update|Type:Position__c|Rows:1
11:21:17.826 (826821000)|DML_END|[406]
11:21:17.826 (826971000)|EXCEPTION_THROWN|[406]|System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified

 For some reason the value in the map doesnt make it to the list, and we then get obvious error ....


Any ideas anyone?





Can you post how you have declared posMap,I want to see the key and value for that.


Hiya Vinit.


Thanks for having a think about this one!


Map<id,Position__c> posMap = new Map<id,Position__c>(); // map of complete list of positions to process on approved lm record


Then -

in a loop I populate 

posMap.put(, pos);


Per the debug, there is definitely values in the value - but once I extract the value it is stripped of its attributes.



Can you also post the SOQL query that you use for querying the position object ( which you use in the for loop to get the id and postion object to be put in the Map)?





Absolutely - see the following 


for(Position__c pos : [Select, 
			From Position__c p ]){





This looks weird to me as well.I would suggest to make the debug log level to finest and then check the logs again to see somthing happened in betwen or not or if you have done enough debugging,I would suggest to contact salesforce support for this.


Thanks guys for your efforts to help me out here.


The problem remains unsolved, and looking into finest debug log I can get it is clear that there is some sort of corruption from map to list that means no params are accessible.


I'll take up with Salesforce support... totally weird!