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

Test Class this error

one error is null id after insert


System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopAccounttoPayment: execution of AfterInsert caused by: System.StringException: Invalid id: Trigger.PopAccounttoPayment: line 16, column 42: 


trigger PopAccounttoPayment on Payment_Line__c (after insert) {
set<ID> setInvID = new set<ID>();

        for(Payment_Line__c Pml :{
                if(Pml.Invoice_BC__c != null || Pml.Invoice_BC__c != ''){
        Invoice_BC__c InvBC = new Invoice_BC__c();
        List<Invoice_BC__c> lstInvBC = [Select id,AccountID__c from Invoice_BC__c Where id in : setInvID];
            if(lstInvBC.size() != 0){
                InvBC = lstInvBC[0];
        if(InvBC.AccountID__c != null && InvBC.AccountID__c != ''){  
            Payment_Line__c pml =[0];   
            List<Payments__c> lstPm = new List<Payments__c>();
            Payments__c Pm = new Payments__c(id = pml.DocNo__c);
            Pm.AccountID__c = InvBC.AccountID__c;
            Update lstPm;

 Test class

private class TestPopAccounttoPayment{
    static testMethod void myTest() {
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      Opportunities__c objOpp = new Opportunities__c();
      objOpp.Account_Name__c = objAcc.Id;
      insert objOpp;
      Quotes__c objQuo = new Quotes__c();
      objQuo.Account_Name__c = objAcc.Id;
      objQuo.OpportunitiesID__c = objOpp.Id;
      insert objQuo;
      Sales_Order__c  objSOD = new Sales_Order__c();
      objSOD.Name = 'test4';
      objSOD.OpportunitiesID__c = objOpp.Id;
      objSOD.Quotes__c = objQuo.Id;
      insert objSOD;
      Invoice_BC__c  objInvBc = new Invoice_BC__c();
      objInvBc.Name = 'Test5';
      objInvBc.Sales_OrderID__c =;
      objInvBc.AccountID__c =;
      insert objInvBc;
      Payments__c objPay = new Payments__c();
      objPay.Name = 'Test2';
      objPay.Due_Date__c = System.Today();
      objPay.AccountID__c = objInvBc.AccountID__c;
      insert objPay;
      Payment_Line__c objPayLine = new Payment_Line__c();
      objPayLine.Name = 'Test3';
      objPayLine.DocNo__c =;
      objPayLine.Invoice_BC__c =;
      insert objPayLine;
      Payments__c objPay2 = new Payments__c();
      ApexPages.currentPage().getParameters().put('id', objPayLine.DocNo__c);
      objPay2.Name = 'Test2';
      objPay2.Due_Date__c = System.Today();
      objPay2.AccountID__c = objInvBc.AccountID__c;
      insert objPay2;
      update objPay2;

 thank you so much


is pml.Doc__c a lookup to Payment__c? If not, you are assigning the wrong recordtype to the id for Payment__c.


Yes pml.Doc__c is lookup Payment__c object. i want update Account after save payment line .


I don't see anything in your code off-hand, except it doesn't look like you are bulkifying so well ([0]).


Try putting in some debug statements to see what values you are getting for the ids.