• Marshal Miller 7
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
It is happening on the Fee__c object but the query results are very low around 5-10 so I dont understand why I get this error. I am new to Apex so I could really use some professional advice.
trigger PortalInvoice on Task (before insert) {
    
    List<Invoice__c> I = new list<Invoice__c>();
    List<Fee__c> FeeList = [SELECT Fee_Amount__c, Fee_Description__c, Comment1__c, Transaction_Key__c, Comment2__c FROM Fee__c WHERE Transaction_Date__c = TODAY AND Financial_Account__r.Fee_Method__c = 'I-Invoice'
                                         AND (NOT Transaction_Code__c LIKE '5592%')
                                         AND (NOT Transaction_Code__c LIKE '6492-22%')
                                         AND (NOT Transaction_Code__c LIKE '6492-20%')
                                         AND (NOT Transaction_Code__c LIKE '6492-21%')
                                         AND (NOT Transaction_Code__c LIKE '6492-01%')
                                         AND (NOT Transaction_Code__c LIKE '6492-03%')
                                         AND (NOT Transaction_Code__c LIKE '4492%') ];
	
	Decimal amountValue = 0.00;
	If(!FeeList.isEmpty()){
	amountValue = FeeList[0].Fee_Amount__c;
    }
    For(Task Tk : Trigger.new){
        if(Trigger.isInsert){
        
        if(Tk.Subject == 'Invoice Sent' && Tk.Status == 'Completed' && Tk.Type == 'Email' && FeeList.size() > 0){
        Invoice__c INV = new Invoice__c();
            INV.Amount__c = amountValue;
            INV.Comments__c = Tk.Description;
            INV.Financial_Account__c = Tk.Whatid;
            INV.Invoice_Date__c = Date.today();
            I.add(INV);
            for(Fee__c F : FeeList){
                Inv.Fee_Description__c = String.valueOf(F.Fee_Description__c);
                Inv.Transaction_Number__c = F.Transaction_Key__c;
                INV.Billing_Notes__c = F.Comment1__c + ', ' + F.Comment2__c;
            }
        }
                      
                
        }

     insert I;
        Update I;
        
     
   }

}