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
ckellieckellie 

If, then statements not returningt he correct results

I am trying to clone checkbox values, but my code is turning all my checkbox field value to true even if they should be false. How do I solve this? Here is my code:

 

trigger OldOpportunityLink on Opportunity (before insert) {

    Set<Id> Ids = new Set<Id>();
    for (Opportunity oppo: Trigger.new){
    System.debug('**** 0 Ids id : '+oppo.id);
    
            Ids.add(oppo.Id);
     System.debug('**** 1 oppo id : '+oppo.id);
     
     }
    
    for(Opportunity unity: Trigger.new) {

       unity.Original_Opportunity__c = unity.Current_Opportunity_Id__c;
    
    List<Opportunity> o =new List <Opportunity>([select id, ps__c,Original_Opportunity__r.ps__c
        from Opportunity limit 1]);
    
        if (o[0].ps__c = true){
                unity.ps__c = true;
                }else if
            (o[0].ps__c = false){
                unity.ps__c = false;
                }
        if (o[0].ais__c = true){
                unity.ais__c = true;
                }else if
            (o[0].ais__c = false){
                unity.ais__c = false;
                }  
        if (o[0].potato__c = true){
                unity.potato__c = true;
                }else if
            (o[0].potato__c = false){
                unity.potato__c = false;
                }
        if (o[0].Farmco__c = true){
                unity.Farmco__c = true;
                }else if
            (o[0].Farmco__c = false){
                unity.Farmco__c = false;
                }                    
        if (o[0].Service_Contract__c = true){
                unity.Service_Contract__c = true;
                }else if
            (o[0].Service_Contract__c = false){
                unity.Service_Contract__c = false;
                }                    
        if (o[0].Processed_Fruit_Veg__c = true){
                unity.Processed_Fruit_Veg__c = true;
                }else if
            (o[0].Processed_Fruit_Veg__c = false){
                unity.Processed_Fruit_Veg__c = false;
                }                    
        if (o[0].Project_System_Eng__c = true){
                unity.Project_System_Eng__c = true;
                }else if
            (o[0].Project_System_Eng__c = false){
                unity.Project_System_Eng__c = false;
                }
        if (o[0].Freshline__c = true){
                unity.Freshline__c = true;
                }else if
                
            (o[0].Freshline__c = false){
                unity.Freshline__c = false;
                }                    
        if (o[0].Pharma__c = true){
                unity.Pharma__c = true;
                }else if
            (o[0].Pharma__c = false){
                unity.Pharma__c = false;
                }                    
        if (o[0].Misc_Other__c = true){
                unity.Misc_Other__c = true;
                }else if
            (o[0].Misc_Other__c = false){
                unity.Misc_Other__c = false;
                }                    
        if (o[0].ISG__c = true){
                unity.ISG__c = true;
                }else if
            (o[0].ISG__c = false){
                unity.ISG__c = false;
                }                    
        if (o[0].Spare_Parts__c = true){
                unity.Spare_Parts__c = true;
                }else if
            (o[0].Spare_Parts__c = false){
                unity.Spare_Parts__c = false;
                }                    
        if (o[0].Thermal_Systems__c = true){
                unity.Thermal_Systems__c = true;
                }else if
            (o[0].Thermal_Systems__c = false){
                unity.Thermal_Systems__c = false;
                }                    
        if (o[0].Upgrade__c = true){
                unity.Upgrade__c = true;
                }else if
            (o[0].Upgrade__c = false){
                unity.Upgrade__c = false;
                }                    
    }
}

 

 

Thanks,

ckellie

Best Answer chosen by Admin (Salesforce Developers) 
gotherthanthougotherthanthou

Tests for equality use ==.

All Answers

gotherthanthougotherthanthou

Tests for equality use ==.

This was selected as the best answer
ckellieckellie

Thank you for the tip. This has solved the problem.

ckellie