Skip to main content
Pam Vandekerkhove (xx) ha preguntado en #Apex
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;

}

 
3 respuestas
  1. 23 jun 2016, 15:03
    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 ==.