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 

Prevent Rollup Summary filds changes from firing the trigger

Hi  Everyone, I have a trigger that updates the child records if there is a change on the parent record. my problem is if I change certain fields on the child records, it changes the value of the rollup summaty fields on the parent and fires the trigger. So I added the conditon like this to prevent that: 

if ((c.TCR_Total_Charts__c != oldProj.TCR_Total_Charts__c) || (c.TCR_Total_Delivered__c != oldProj.TCR_Total_Delivered__c) ||
        (c.TCR_Total_Scheduled__c != oldProj.TCR_Total_Scheduled__c)) {
            isExecute = TRUE;
        }
    }
    
    if(isExecute = false){


but now even if I change other  fields on the parent , it does not fire the trigger. Please help me if you know a solution for this. below is the whole trigger. 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_Charts__c from Project_Setting__c where Id In : ProjectIds];
    boolean isfalse = false;
    String userName = UserInfo.getUserName();
    string Profile = UserInfo.getprofileId();
    
    Boolean isExecute = false;
    
    for (Project_Setting__c c : Trigger.new) {
        Project_Setting__c oldProj = Trigger.oldMap.get(c.ID);
        if ((c.TCR_Total_Charts__c != oldProj.TCR_Total_Charts__c) || (c.TCR_Total_Delivered__c != oldProj.TCR_Total_Delivered__c) ||
        (c.TCR_Total_Scheduled__c != oldProj.TCR_Total_Scheduled__c)) {
            isExecute = TRUE;
        }
    }
    
    if(isExecute = false){
        if(userName != 'arash' && profile != 'xxxxx' && profile != 'xxxxx' && profile != 'xxxx'){ 
            for(Project_Setting__c PS : Trigger.new){
                if (PS.Total_Charts__c < 2000) {
                    ProjectIds.add(PS.id);
                    isfalse = true;  
                }
                else{
                    ProjectSettings_ChartsBatchClass pro = new ProjectSettings_ChartsBatchClass(); 
                    database.executebatch(pro,2000);
                }
            } 
            if ( isfalse ){
                projectSettingsChartClass.ProjectMethods(ProjectIds);
            }
        }
    }
}
Best Answer chosen by Arash Teimoupoor
apex_keenapex_keen
You've used following statement. 
if(isExecute = false){

There is a single '=' . you should be using '==' to compare. I don't think, it will go inside if statement

All Answers

apex_keenapex_keen
By Trigger not firing -do you mean batch job not getting queued up ? Are you sure, your trigger won't add more than 5 batch jobs at a time, as statements are written within loop?

DId you put debug statements to verify?
apex_keenapex_keen
You've used following statement. 
if(isExecute = false){

There is a single '=' . you should be using '==' to compare. I don't think, it will go inside if statement
This was selected as the best answer
Arash TeimoupoorArash Teimoupoor
Thanks a lot , It worked.  :)