+ Start a Discussion
Lisa HorneLisa Horne 

Apex Error Help!

I have this apex trigger but getting the following error when trying to delete contract product from an opportunity.  Could someone please let me know what I need to fix so I can delete contract products?

trigger Contract_Product_Delete_Update_Accounts_and_Contracts on Contract_Product__c (after delete) 
{  
  system.debug('DELETE TRIGGER FIRSTRUN VARIABLE: ' + Account_Contract_Update_Class.FirstRun);
  if(Account_Contract_Update_Class.FirstRun == true)
  {
    Account_Contract_Update_Class.FirstRun = false;
    system.debug('CONTRACT PRODUCT DELETE TRIGGER!!!!');
    String ObjectDMLType ='ContractProductDelete';
    set<ID> TheseAccountIDs = new set<id>(); //Set of Account IDs that have Contract Products. 
                        //These Accounts Need to be updated by checking All their active Contract Products
    set<id> TheseContractIDs = new set<id>();                      
    list<string> Products = new list<string>();
    for(Contract_Product__c cp : trigger.old)
    {
      TheseAccountIds.add(cp.Account__c);  
      TheseContractIds.add(cp.Contract__c);  
      Products.add(string.valueof(cp.Product_Family__c));
    }    
    system.debug('Number of Products removed: ' + trigger.old.size());  
    system.debug('These are the accounts that will be updated: ' + TheseAccountIds);
    system.debug('These are Products being deleted: ' + Products);    
    
    //Update the Contract
    Account_Contract_Update_Class.UpdateContracts(TheseContractIDs, ObjectDMLType);  
    //Update the Account
    Account_Contract_Update_Class.UpdateAccounts(TheseAccountIDs, ObjectDMLType);
  }
//last brackett
}


 

ERROR I am getting:
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger Contract_Product_Delete_Update_Accounts_and_Contracts caused an unexpected exception, contact your administrator: Contract_Product_Delete_Update_Accounts_and_Contracts: execution of AfterDelete caused by: System.QueryException: No such column 'BillingAddress' on entity 'Contract'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.: Class.Account_Contract_Update_Class.UpdateContracts: line 238, column 1". 

Click here to return to the previous page.
 

Best Answer chosen by Lisa Horne
SaranSaran
Ya Lisa Sure!

Mail me @ sarantech55@gmail.com

Thanks!

All Answers

SaranSaran
HI Lisa,

The issue is while updating contract record. It will be easy to identify if the you upload your class Account_Contract_Update_class

Thanks
Lisa HorneLisa Horne
Thanks for answering Saran. The code for Account_Contract_Update_class is to large to post here.  Could I email it to you?

Lisa
SaranSaran
Ya Lisa Sure!

Mail me @ sarantech55@gmail.com

Thanks!
This was selected as the best answer
Lisa HorneLisa Horne
Thanks Saran!  You are the best!!