You need to sign in to do that
Don't have an account?

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
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
Error: Compile Error: Variable does not exist: PS.total_check__c at line 11 column 7
Error: Compile Error: Expression cannot be assigned at line -1 column -1
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 .....
Error: Compile Error: Expression cannot be assigned at line -1 column -1
the "total_check__c" is a formula check box field
I received this error:
Error: Compile Error: Field is not writeable: Project_Setting__c.total_check__c at line 7 column 9
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);
}
}