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
sksfdc221sksfdc221 

Error: Id not specified in the update call

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.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
surojit Mondalsurojit Mondal
Hi,

You are Updating AcctransMap.values(), which is basically referring accTrans variable and throwing DMLexception. Because, to update any record you have to mention that record Id in accTrans variable. like accTrans.id = SFDC id Account_Transfer__c rec.

Update your code with the above changes and let me know if it works for you.

Regards,
Surojit
 
sksfdc221sksfdc221

@Surojit, below is my complete code.
 

public static list<Account_Transfer__c> insertAccountTransfer(
        Account_Transfer__c accTrans,
        List<string> selectedPoliciesSet,
        string selPolicies,
        Office__c toOffice,
        Office__c fromOffice,
        User selectedUser
    ) {    
       List<Account_Transfer__c> AccountTransfersList = new List<Account_Transfer__c>();
	List<AggregateResult> PolList = [Select District_Acct_Code__c from Policy__c WHERE ID IN :selectedPoliciesSet GROUP BY District_Acct_Code__c];
        try {
            Account_Transfer__c acTran = New Account_Transfer__c();
				for(AggregateResult ar : PolList) { 
            
            acTran = accTrans;
            acTran.Owner_for_Reporting__c = UserInfo.getUserId();
            
            acTran.Submitted_Date__c = Date.today();
				AccountTransfersList.add(acTran );
				}
				insert AccountTransfersList; 
            if (selPolicies != null) {
                List<string> selPols = new List<string>();
                selPols = selPolicies.split(',');
                linkPoliciesAndHandleApprovalFlds(
                    selPols,
                    accTrans,
                    toOffice,
                    fromOffice,
                    selectedUser
                );
            }
			
            return AccountTransfersList; 
        } catch (Exception e) {
            throw new AuraHandledException(
                'Error in Client Request Transfer****' +
                e.getMessage() +
                'at ' +
                e.getLineNumber()
            );
        }
    }
    // Client Requested

   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.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);
    
}
 

I am inserting Account_Transfer__c records in my insertAccountTransfer method and later updating them in linkPoliciesAndHandleApprovalFlds. 

The issue here is that, I could not able to update the records which are inserted in the first method.
Could you please help me with this.

surojit Mondalsurojit Mondal
Hi,

Can you set a debug log to get the Account_Transfer__c  Id after line: 67
System.debug('accTrans.Id::'+accTrans.Id);
​​​​​​
It shuould be null and for the same you are receiving the error. Please check and let me know what you receive in the apexlog

Regards,
Surojit