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 

SOQL syntax

hi Friends in this trigger "Variable does not exist: list at line 53 column 9" error is showing.please help with this. and another thing if i want to fetch the date from createdBy field then what will be the syntax for SOQL & if i want to fetch picklist into a text field then what will be thye soql syntax.



trigger RevenueWithoutST on Revenue__c (after insert, before update) {
    List<SCSCHAMPS__Appointment__c> appList;
    List<Revenue__c> revlist;
    Revenue__c r= new Revenue__c();
    string eCode;
    date salaryDate;
    string category;
    string type;
    for(Revenue__c rev:Trigger.new)
    {
        eCode=rev.ECode__c;
        salaryDate=rev.Salary_Processed_Month__c;
        category=rev.InvoiceCategory__c;
        type=rev.Invoice_Type__c;
        
        if(eCode!=null)
        {
           appList =[select AvvasECode__c,Name_of_the_Candidate__c,Client_Name__c,Date_of_Onboarding__c,
                    Last_Working_Date__c,Location__c from SCSCHAMPS__Appointment__c where AvvasECode__c=: rev.ECode__c] ;
            
            for(SCSCHAMPS__Appointment__c app : appList)
            {
                r.Talent_Name__c= app.Name_of_the_Candidate__c;
                
            }
            
        }
        if(eCode!=null && category=='individual' && salaryDate!=null && type=='Time& Material' )
        {
            List<Invoice__c> InvList;
            Invoice__c inv= new Invoice__c();
            InvList=[select id,Name,Emp_Code__c,Invoice_Category__c,
                     Sub_Total__c from Invoice__c where Emp_Code__c=: rev.ECode__c
                       ];
                FOR(Invoice__c inc : InvList)
                {
                    r.Revenue_Without_ST__c=inc.Sub_Total__c;
                }
                
        }
        else if(eCode!=null && category=='consolidated')
        {
            List<Invoice_Line_Item__c> ILineList;
            Invoice_Line_Item__c iline=new Invoice_Line_Item__c();
            ILineList=[select id,Name,Employee_Code__c,Total__c
                       from Invoice_Line_Item__c where Employee_Code__c=:rev.ECode__c ];
            for(Invoice_Line_Item__c IL : ILineList)
            {
              r.Revenue_Without_ST__c=IL.Total__c;  
            }
        }
        
        list.add(rev);
        
        
    }
    update revlist;

}
PavanKPavanK
Please refer below corrected code

trigger RevenueWithoutST on Revenue__c (after insert, before update) {
    List<SCSCHAMPS__Appointment__c> appList;
    List<Revenue__c> revlist;
    Revenue__c r= new Revenue__c();
    string eCode;
    date salaryDate;
    string category;
    string type;
    for(Revenue__c rev:Trigger.new)
    {
        eCode=rev.ECode__c;
        salaryDate=rev.Salary_Processed_Month__c;
        category=rev.InvoiceCategory__c;
        type=rev.Invoice_Type__c;
        
        if(eCode!=null)
        {
           appList =[select AvvasECode__c,Name_of_the_Candidate__c,Client_Name__c,Date_of_Onboarding__c,
                    Last_Working_Date__c,Location__c from SCSCHAMPS__Appointment__c where AvvasECode__c=: rev.ECode__c] ;
            
            for(SCSCHAMPS__Appointment__c app : appList)
            {
                r.Talent_Name__c= app.Name_of_the_Candidate__c;
                
            }
            
        }
        if(eCode!=null && category=='individual' && salaryDate!=null && type=='Time& Material' )
        {
            List<Invoice__c> InvList;
            Invoice__c inv= new Invoice__c();
            InvList=[select id,Name,Emp_Code__c,Invoice_Category__c,
                     Sub_Total__c from Invoice__c where Emp_Code__c=: rev.ECode__c
                       ];
                FOR(Invoice__c inc : InvList)
                {
                    r.Revenue_Without_ST__c=inc.Sub_Total__c;
                }
                
        }
        else if(eCode!=null && category=='consolidated')
        {
            List<Invoice_Line_Item__c> ILineList;
            Invoice_Line_Item__c iline=new Invoice_Line_Item__c();
            ILineList=[select id,Name,Employee_Code__c,Total__c
                       from Invoice_Line_Item__c where Employee_Code__c=:rev.ECode__c ];
            for(Invoice_Line_Item__c IL : ILineList)
            {
              r.Revenue_Without_ST__c=IL.Total__c;  
            }
        }
        
        revlist.add(rev);
        
        
    }
    update revlist;

}
On line 53 list was typed insted of 'revlist'
 
PavanKPavanK
Answer to your other question

if you want date from createdby then simply add 'createddate,' in your query.

Same applicable for picklist, just add api name of picklist and it will extract data in text format.

Please mark answer as best if it helped to resolve your query.
chiranjib routchiranjib rout
thank u. now the trigger is saved but whenever i am creating a record on revenue object "Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger RevenueWithoutST caused an unexpected exception, contact your administrator: RevenueWithoutST: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.RevenueWithoutST: line 53, column 1" is showing. any suggesetions to avoid it?..
Anant Kumar DevAnant Kumar Dev
Solution for this error is : You need to instantiate revlist with new keyword before use.
Ex : revlist = new List<Revenue__c>();

But I don't think this trigger will do any thing. You have written SOQL inside Trigger.New iteration and assign queried data into Revenue__c's object 'r' and at the end of code you have written revlist.add(rev); and trying to update revlist that is meaning less.

If you are trying to populate data for some field in triggerd object than you can use Before Insert/Update trigger.

Hope this will help you.

Plese let me know, if you have any queries.