简体   繁体   English

无法将Salesforce Apex地图列入清单

[英]unable to get Salesforce Apex map to list

seeing strange behaviour that I cannot see a solution for. 看到我看不到解决方案的奇怪行为。 Any suggestions appreciated. 任何建议赞赏。 I have a map that is definitely populated with a key-value pair. 我有一张明确填充了键值对的地图。 I then try to pass the map value to a list per provided map method prior to updating. 然后,我尝试在更新之前将映射值传递给每个提供的映射方法的列表。 Immediately I do this, for some reason I lose the values on the record just passed to list, and in turn cannot update it. 我立即执行此操作,由于某种原因,我丢失了刚刚传递给列表的记录上的值,反过来无法更新它。 Code and debug log follow; 代码和调试日志如下;

code (debug lines removed): 代码(调试行已删除):

if(!posMap.isEmpty()){
   List<Position__c> posUpdates = new List<Position__c>();
   posUpdates = posMap.values();
   update posUpdates;
}

debug log: 调试日志:

    USER_DEBUG|[403]|DEBUG|posUpdate record -->Position__c:{Affiliation_Final__c=a03N0000000mQEKIA2, Position_Type__c=Warden, Id=a07N0000000iA6lIAE}
11:21:17.825 (825365000)|SYSTEM_METHOD_EXIT|[403]|System.debug(ANY)
11:21:17.825 (825386000)|SYSTEM_METHOD_ENTRY|[404]|String.valueOf(Object)
11:21:17.825 (825402000)|SYSTEM_METHOD_EXIT|[404]|String.valueOf(Object)
11:21:17.825 (825413000)|SYSTEM_METHOD_ENTRY|[404]|System.debug(ANY)
11:21:17.825 (825418000)|USER_DEBUG|[404]|DEBUG|id ->null
11:21:17.825 (825422000)|SYSTEM_METHOD_EXIT|[404]|System.debug(ANY)
11:21:17.825 (825439000)|SYSTEM_METHOD_ENTRY|[405]|String.valueOf(Object)
11:21:17.825 (825453000)|SYSTEM_METHOD_EXIT|[405]|String.valueOf(Object)
11:21:17.825 (825464000)|SYSTEM_METHOD_ENTRY|[405]|System.debug(ANY)
11:21:17.825 (825468000)|USER_DEBUG|[405]|DEBUG|Affiliation_Final__c ->null
11:21:17.825 (825472000)|SYSTEM_METHOD_EXIT|[405]|System.debug(ANY)
11:21:17.825 (825516000)|DML_BEGIN|[406]|Op:Update|Type:Position__c|Rows:2
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

The error indicates that the records you have in posMap have not been retrieved from or inserted into the database. 该错误表示尚未从数据库中检索或插入posMap中的记录。

An upsert operation will insert those which are not in the database yet and update those that are. upsert操作将插入尚未存在于数据库中的那些并更新那些。

upsert posMap.values();

If the records exist in the data base try update posMap.values(); 如果记录存在于数据库中,请尝试update posMap.values(); its not necessary check if map is empty, else change update to insert or upsert 不必检查map是否为空,否则将update更改为insert或upsert

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM