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
Arash TeimoupoorArash Teimoupoor 

trigger to call a batch class or a future class

Hi, I am trying to write a trigger to call a btach class if a check box is true, otherwise call the future class. but IDK what is wrong with my code I can't save it. please advise. here is my code:

trigger ProjectSettings_ChartsTrigger on Project_Setting__c (After Insert,After Update){
    
    List<id> ProjectIds = new list<id>();
    List<Project_Setting__c > prj = [select Id, total_check__c from Project_Setting__c where Id In : ProjectIds];
    for(Project_Setting__c PS : Trigger.new){
    if (Project_Setting__c.total_check__c = true) {
      ProjectIds.add(PS.id);   
    }
    ProjectSettings_ChartsBatchClass pro = new ProjectSettings_ChartsBatchClass(); 
              database.executebatch(pro,2000);
} if (Project_Setting__c.total_check__c = false){
     projectSettingsChartClass.ProjectMethods(ProjectIds);
    }
    

Thanks
Arash TeimoupoorArash Teimoupoor
Balaji, I receive this error when I do that:

Error: Compile Error: Variable does not exist: PS.total_check__c at line 11 column 7
Arash TeimoupoorArash Teimoupoor
but in a way that I have written it (the first post) I receive the following error:


Error: Compile Error: Expression cannot be assigned at line -1 column -1
 
Vishnu VaishnavVishnu Vaishnav
Hi Arash,

Here is modified code..

trigger ProjectSettings_ChartsTrigger on Project_Setting__c (After Insert,After Update){
    List<id> ProjectIds = new list<id>();
    List<Project_Setting__c > prj = [select Id, total_check__c from Project_Setting__c where Id In : ProjectIds];
    boolean isfalse = false;
    for(Project_Setting__c PS : Trigger.new){
        if (Project_Setting__c.total_check__c = true) {
            ProjectIds.add(PS.id);
            isfalse = true;  
        }
        else{
            ProjectSettings_ChartsBatchClass pro = new ProjectSettings_ChartsBatchClass(); 
            database.executebatch(pro,2000);
        }
    } 
    if ( isfalse ){
        projectSettingsChartClass.ProjectMethods(ProjectIds);
    }
}

:::======================================================================:::
Qusetion Solved ? then mark as best answer to make helpful to others .....
Arash TeimoupoorArash Teimoupoor
Vishnu, thanks for your reply, I received this error when I used your code:

Error: Compile Error: Expression cannot be assigned at line -1 column -1
Arash TeimoupoorArash Teimoupoor
Balaji,

the "total_check__c" is a formula check box field 
 
Arash TeimoupoorArash Teimoupoor
Balaji, 

I received this error:
Error: Compile Error: Field is not writeable: Project_Setting__c.total_check__c at line 7 column 9
Arash TeimoupoorArash Teimoupoor
Balaji and Vishnu
Instead of total_check I used a roll summary field, now I can save the code in any of your ways, but none of them call the classes, it is now like this:

Balaji code:

trigger ProjectSettings_ChartsTrigger on Project_Setting__c (After Insert,After Update){
    
    List<id> ProjectIds = new list<id>();
    List<Id> ProjectIdsWithFlaseCheck=new List<ID>();
    List<Project_Setting__c > prj = [select Id, Total_Charts__c from Project_Setting__c where Id In : ProjectIds];
    for(Project_Setting__c PS : Trigger.new){
    if (PS.Total_Charts__c > 50000) {
      ProjectIds.add(PS.id);   
    }else{
    ProjectIdsWithFlaseCheck.add(PS.id);
    }
    
    
    ProjectSettings_ChartsBatchClass pro = new ProjectSettings_ChartsBatchClass(); 
              database.executebatch(pro,2000);
}
if (ProjectIdsWithFlaseCheck != Null){
     projectSettingsChartClass.ProjectMethods(ProjectIdsWithFlaseCheck);
    }
    
    }




Vishnu Code:

trigger ProjectSettings_ChartsTrigger on Project_Setting__c (After Insert,After Update){
    List<id> ProjectIds = new list<id>();
    List<Project_Setting__c > prj = [select Id, Total_Charts__c from Project_Setting__c where Id In : ProjectIds];
    boolean isfalse = false;
    for(Project_Setting__c PS : Trigger.new){
        if (PS.Total_Charts__c > 50000) {
            ProjectIds.add(PS.id);
            isfalse = true;  
        }
        else{
            ProjectSettings_ChartsBatchClass pro = new ProjectSettings_ChartsBatchClass(); 
            database.executebatch(pro,2000);
        }
    } 
    if ( isfalse ){
        projectSettingsChartClass.ProjectMethods(ProjectIds);
    }
}