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
ApexNewb2012ApexNewb2012 

Error Code but NO ID Cannot_Update_Current_Lead in XML response

HEllo I was wwondering how i can get my XML response from Salesforce to Include the Id where it errors out?

 

I get the Id when it is a success for each success but not for errors? I am running my process through Pervasive..

Jaffer Ali.Jaffer Ali.

Database.SaveResult hold Ids only when records process successfully.It is really strange but there is a work around for this problem. According to salesforce documentation the order of list which is passed to the DML operation would be same in the response.So you can see my sample code below to solve this issue.

 

   Database.SaveResult [] accountsProcessed =  Database.update (listActToUpdate,false);
                              for (Database.SaveResult result : accountsProcessed) {
                                  Integer index =0;
                                  System.Debug('*********Result'+result);
                                    if (!result.isSuccess()) {
                                        string error='';
                                        Database.Error[] errs = result.getErrors();
                                        for(Database.Error err : errs){
                                            error+= err.getMessage();
                                        }

                                        // because result.getId return null in case of error but according to salesforce order of records in save result is same as passed in parameter so I am using another technique
                                        Trigger.newMap.get(mapOfAccountIdWithContId.get(listActToUpdate[index].Id)).addError(error);
                                    }
                                    index++;
                               }

ApexNewb2012ApexNewb2012
But how would I use this to get the Id in my XML? I am new to Developing and any guidance to where to find how to get this would be appreciated. No really looking for it to be done for me, more looking to be taught to fish. ======================================================== This e-mail message is intended only for the personal use of the recipient(s) named above. If you are not an intended recipient, you may not review, copy or distribute this message. If you have received this communication in error, please notify the sender immediately by e-mail and delete the original message. ========================================================
Jaffer Ali.Jaffer Ali.

See Dom.Document in apex to see how add value in XML . Not sure but might be it would help.