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
pvandepvande 

Trigger Help - "Miss firing on boolean checkbox"

My trigger is too agressive and I am hoping that you can help.

Goal:  Update the boolean Move_to_ProductionP__c (on Project__c) if the following criteria are true:  o.Move_to_Production__c = True and o.RecordTypeId == '012a0000001FqTn'
Problem:  The trigger updates the boolean field Move_to_Production__c on the custom Project object (this is desired)  but it also updates the boolean field on  the Opportunity field Move_to_Production__c as True upon creation of an opportunity, which is not a desired outcome.

Here is my code.  I would appreciate any help from the experts!  Thanks in advance for looking.

trigger MoveToProduction on Opportunity (before insert, before update) {   

List<ID> ProjIds = New List<ID>();   

for(Opportunity o : Trigger.new){
 if(o.Move_to_Production__c = true && o.RecordTypeId == '012a0000001FqTn')
{       ProjIds.add(o.Project__c);    
 }
  }   
List<Project__c> ProjList = [SELECT id, Move_to_ProductionP__c FROM Project__c WHERE id in :ProjIds];   for(integer i = 0 ; i < ProjList.size(); i++){     
ProjList[i].Move_to_ProductionP__c = true;     
  }
update ProjList;
}
 
Best Answer chosen by pvande
Chris  ByromChris Byrom
It is this line that is the problem.

 if(o.Move_to_Production__c = true && o.RecordTypeId == '012a0000001FqTn')

You are setting the o.Move_to_Production__c field to true instead of testing its value. Change the single = to ==.

All Answers

Chris  ByromChris Byrom
It is this line that is the problem.

 if(o.Move_to_Production__c = true && o.RecordTypeId == '012a0000001FqTn')

You are setting the o.Move_to_Production__c field to true instead of testing its value. Change the single = to ==.
This was selected as the best answer
Kondal KonthamKondal Kontham
trigger MoveToProduction on Opportunity (before insert, before update) {   

List<ID> ProjIds = New List<ID>();   

for(Opportunity o : Trigger.new){
        if(o.Move_to_Production__c = true && o.RecordTypeId == '012a0000001FqTn'){              
                 ProjIds.add(o.Project__c);    
          }
}   
List<Project__c> ProjList = new List<Project__c>();   
for(Project__c p : [SELECT id, Move_to_ProductionP__c FROM Project__c WHERE id in :ProjIds]){     
             p.Move_to_ProductionP__c = true;
              ProjList.add(p);    
}
update ProjList;
}
Could you please try the above/

Thanks
 
pvandepvande
Thank you Chris!