• Kevin Rutledge 4
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I am trying to use an Apex trigger to post billings and apply a cash receipt. I get the error, "Variable does not exist:bill" (it is on the 4th line from the bottom and in bold).
Does anyone have any suggestions?

trigger AcctSeed_CreateiDonateBilling on Opportunity (after insert,after update) {
    for (Opportunity Oppty : Trigger.New){
        IF(Oppty.I_Donate__c == TRUE && Oppty.StageName == 'Pledged'){
   
    // Create billing records to post and unpost
    
    AcctSeed__Billing__c[] billings = new List <AcctSeed__Billing__c> ();
        billings.add(
            new AcctSeed__Billing__c(
                AcctSeed__Date__c = System.today(),
                AcctSeed__Customer__c = Oppty.AccountId,
                AcctSeed__Status__c = 'Approved',
                AcctSeed__Due_Date2__c = System.today() + 30,
                AcctSeed__Opportunity__c = Oppty.Id
                )
            );

    insert billings;

    // Create billing line records to post and unpost
    AcctSeed__Billing_Line__c[] bLines = new List <AcctSeed__Billing_Line__c> ();
    AcctSeed__GL_Account__c glAccount = [Select Id From AcctSeed__GL_Account__c limit 1];
    
    for (AcctSeed__Billing__c bill : billings) {
        AcctSeed__Billing_Line__c objBillingLine = new AcctSeed__Billing_Line__c();
        objBillingLine.AcctSeed__Billing__c = bill.id;
        objBillingLine.AcctSeed__Date__c = System.today();
        objBillingLine.AcctSeed__Rate__c = Oppty.Amount;
        objBillingLine.AcctSeed__Hours_Units__c = 1;
        objBillingLine.AcctSeed__Revenue_GL_Account__c = glAccount.Id;
        bLines.add(objBillingLine);
        }
    
    insert bLines;
        
    // Call the post billings service
    AcctSeed.PostResult[] postResults = AcctSeed.BillingPostService.postBillings(billings);
    
    //Create Cash Receipt for Payment
    //   AcctSeed__Cash_Receipt__c[] CashRcpt = new List <AcctSeed__Cash_Receipt__c> ();
        AcctSeed__Cash_Receipt__c objCashReceipt = new AcctSeed__Cash_Receipt__c();
        objCashReceipt.AcctSeed__Amount__c = Oppty.Amount;
        objCashReceipt.AcctSeed__Account__c = Oppty.AccountId;
        objCashReceipt.AcctSeed__Payment_Reference__c = 'iDonate Pledge';
        objCashReceipt.AcctSeed__Receipt_Date__c = System.today();
         insert objCashReceipt;
     I have this Apex trigger but I keep getting an error       
            
        AcctSeed__Billing_Cash_Receipt__c     objBCR = new AcctSeed__Billing_Cash_Receipt__c();
        objBCR.AcctSeed__Billing__c = bill.id;
        objBCR.AcctSeed__Cash_Receipt__c = objCashReceipt.id;
        objBCR.AcctSeed__Applied_Amount__c = objCashReceipt.AcctSeed__Amount__c;
        insert objBCR;