0

Below is my apex method where I'm updating Account_Transfer__c Records

 private static void linkPoliciesAndHandleApprovalFlds(
    List<string> selectedPoliciesSet,
    Account_Transfer__c accTrans,
    Office__c toOffice,
    Office__c fromOffice
) {
    Map<Id, Account_Transfer__c> AcctransMap = new Map<Id, Account_Transfer__c>(); 
    String districtAccountCode = '';
    List<Policy__c> selectedPolicies = new List<Policy__c>(
        [
            SELECT
                Id,
                District_Acct_code__c,
                Account_Transfer__c,
                Plan_Code__c
            FROM Policy__c
            WHERE ID IN :selectedPoliciesSet
        ]
    );
    List<Account_Transfer_Policy__c> accTransferPolicy = new List<Account_Transfer_Policy__c>();
    for (Policy__c pol : selectedPolicies) {
        Account_Transfer_Policy__c atp = new Account_Transfer_Policy__c();
        atp.Account_Transfer__c = accTrans.Id;
        atp.Policy__c = pol.Id;
        accTransferPolicy.add(atp);
        accTrans = new Account_Transfer__c();
        
    }
    

    

    accTrans.District_To__c = districtAccountCode;
    AcctransMap.put(accTrans.id, accTrans);
    
    update AcctransMap.values();
    
    insert accTransferPolicy;
    
    Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
    req.setObjectId(accTrans.Id);
    req.setSubmitterId(UserInfo.getUserId());
    Approval.process(req);
    
}

Now this code isn't throwing me any errors but in the record page, I'm getting the error as

System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

I am using Map here to get the ids of Account Transfer records and using them to update by calling map.values(). I'm wondering why it is mentioning that Ids are not specified in the update call.

Can anyone please suggest if there is anything missing

2 Answers 2

0

update call requires salesforce id in your code you are creating a new instance of Account_Transfer__c by calling

accTrans = new Account_Transfer__c();

As this is not still added to database it doen't have Salesforce Id. you can use insert here instead of update.

Second option is to use upsert which will handle if it needs to update existing record or insert new record based on Salesforce record id [by default(you can specify External Id as well)]

so use

    insert AcctransMap.values();

or

    upsert AcctransMap.values();
0
accTrans = new Account_Transfer__c();

This line here is overwriting the parameter that was passed in. When you put it in the map, you end up with:

{ null => Account_Transfer__c{} }

That is, an key with a null Id pointing to an empty record that can't be updated.

3
  • Is there any way to pass these ids to Approval.ProcessSubmitRequest
    – SK_112
    Jun 16, 2020 at 5:38
  • @SK_112 You literally deleted the Id from memory because of the first line of code I mentioned. You need to not do that.
    – sfdcfox
    Jun 16, 2020 at 11:06
  • Even when I delete the above mentioned line, I am still getting the same error. It is happening with the map which is not passing ids in the update call. Am I missing anything here?
    – SK_112
    Jun 17, 2020 at 5:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .