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
chiranjib routchiranjib rout 

please help with this trigger

hi guys,
I am trying to work on this trigger but unable to find the error. there are 2 objects invoice & revenue.if revenue object fields(salary=regular,salary processed=today & invoice type=time & material) and invoice object fields(categlory=individual, billing calendar=today & type= time& material) & both the objects ecode & emp codeare equal then RevenueWithoutST(REVENUE OBJECT) = subtotal(invoice object).

trigger subtotal on Revenue__c (after insert,before update ) {
    List<Revenue__c> Revenue__c = New List<Revenue__c>();
    Set<Id>ECode = New Set<Id>();
    For(Revenue__c Rev : Trigger.New)
     Revenue__c.ECode__c == Invoice__c.Emp_Code__c   
    }

    List<Revenue__c> RevList = [Select Id,Salary_Processed_month__c,Invoice_Type__c from Revenue__c where id =: ECode];
{Revenue__c r = new Revenue__c();
 Invoice__c inv =new Invoice__c();
        For(r.Salary_Type__c=='Regular'&&inv.Invoice_Category__c== 'Individual')
        
            If(inv.Billing_Calendar__c== system.today()&& inv.Type_of_Invoices__c=='Time & Material' && r.Salary_Processed_month__c==system.today()
               && r.Invoice_Type__c=='Time & Material')           
            {
                r.Revenue_without_ST__c =inv.Sub_Total__c;
            }
             else
            {
                r.Revenue_without_ST__c =11;
            }
 
                
          
Update RevList;
              
            }
           
        
    

           
    


 
Stefan AbramiukStefan Abramiuk
Hi chiranjib,
I'm sorry but probably there was some issue with pasting your code. Currently it's not compiling at all. Can you paste it once again with code tags?
Anyway please tell what probles do you have with this trigger.
chiranjib routchiranjib rout
trigger subtotal on Invoice__c (after insert,before update )
 {
    List<Revenue__c> Rev = New List<Revenue__c>();
    Set<Id>ECode = New Set<Id>();
    For(Revenue__c R : Trigger.New)
     Revenue__c.ECode__c = Invoice__c.Emp_Code__c;

    List<Revenue__c> RevList = [Select Id,Salary_Type__c,Salary_Processed_month__c,Invoice_Type__c from Revenue__c where id =: ECode];
    {
    Revenue__c r = new Revenue__c();
     Invoice__c inv =new Invoice__c();
       
        
            If(r.Salary_Type__c='Regular'&& inv.Invoice_Category__c='Individual'&& inv.Billing_Calendar__c== system.today()&& inv.Type_of_Invoices__c=='Time & Material' && r.Salary_Processed_month__c==system.today()
               && r.Invoice_Type__c=='Time & Material')           
            {
                r.Revenue_without_ST__c =inv.Sub_Total__c;
            }
            else
            {
                r.Revenue_without_ST__c =11;
            }
 
                
          
                Update RevList;
              
            }}
okay i have uploaded the code again. can u compile it now? actually i am unable to set the relation between ecode & empcode of both the objects i think. Can you suggest anything?
 
JeffreyStevensJeffreyStevens
Ya - that won't compile - you've got some issues.
The FOR statement on line #5 needs to have a { right after the ).

If you do that - it might compile and execute - as long as you're only updating one record at a time.  But then you've got more issues.  The SOQL that you're doing on line#8 will fail when the trigger is stress tested.  Remember, triggers can be called with up-to 200 records.  So, in this case - you're doing a SOQL inside of a loop, and the limit of 100 SOQL's would be reached.