+ Start a Discussion
Zach AckermanZach Ackerman 

trigger works when it is only one if statement. does not work when i add the second.


trigger PlanPackageNames on Plan__c (Before Insert,Before Update)
{
    for (Plan__c Plan : Trigger.new)
    {
        IF(Plan.Armada_Plan_Package_Name__c=='Diamond'&&
        Plan.Sum_of_Benefits__c==90000)
          {Plan.Name= 'Ultimate Health'+' '+'Diamond';
    {
          IF(Plan.Armada_Plan_Package_Name__c=='Diamond'&&
        Plan.Sum_of_Benefits__c!=90000)
          {Plan.Name= 'Ultimate Health'+' '+'Modified'+'Diamond';
      
        }
     }  
   }
   }
   }
Best Answer chosen by Zach Ackerman
sfdcMonkey.comsfdcMonkey.com
hi Zach
try this onces
trigger PlanPackageNames on Plan__c (Before Insert,Before Update){
    for (Plan__c Plan : Trigger.new){
        IF(Plan.Armada_Plan_Package_Name__c == 'Diamond' &&
        Plan.Sum_of_Benefits__c == 90000){
		Plan.Name= 'Ultimate Health'+' '+'Diamond';
    
	   }
          IF(Plan.Armada_Plan_Package_Name__c=='Diamond'&&
        Plan.Sum_of_Benefits__c!=90000){
		Plan.Name= 'Ultimate Health'+' '+'Modified'+'Diamond';
      
        }
     }  
   }
i hop it helps you
Mark it best answer if it helps you THanks :)
 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi Zach
try this onces
trigger PlanPackageNames on Plan__c (Before Insert,Before Update){
    for (Plan__c Plan : Trigger.new){
        IF(Plan.Armada_Plan_Package_Name__c == 'Diamond' &&
        Plan.Sum_of_Benefits__c == 90000){
		Plan.Name= 'Ultimate Health'+' '+'Diamond';
    
	   }
          IF(Plan.Armada_Plan_Package_Name__c=='Diamond'&&
        Plan.Sum_of_Benefits__c!=90000){
		Plan.Name= 'Ultimate Health'+' '+'Modified'+'Diamond';
      
        }
     }  
   }
i hop it helps you
Mark it best answer if it helps you THanks :)
 
This was selected as the best answer
sfdcMonkey.comsfdcMonkey.com
its happens because your if block not properly closed
Zach AckermanZach Ackerman
One more question. As I continue to build out the different scenarios (if statements) how can i keep my code coverage high? Here is my test class currently. 

@isTest

public class PlanPackageNamesTest
{

      static testMethod void myUnitTest()
     
    {
        Plan__c plan = new Plan__c();
        plan.Name='Ultimate Health Diamond';
        plan.Product_Name__c='UH';
        plan.Carrier_Vendor__c='Transamerica';
        plan.Services_Phone_Number__c='1-855-943-4595';
        plan.annual_single_maximum__c=100;
        plan.annual_family_maximum__c=100;
        plan.vision__c=100;
        plan.dental__c=100;
        plan.RX__c=100;
        plan.Counseling__c=100;
        plan.wellness__c=100;
        plan.medical_equipment__c=100;
        plan.executive_physical__c=100;
        plan.medical_expense_coverage__c='All 213 Eligible';
        plan.armada_plan_package_name__c='Diamond';
        plan.Policy_Group_Number__c='111';
        plan.Plan_Division__c='000A';
        
        
        
        insert plan;
        update plan;
        
     

        
        }
        
        
    }
sfdcMonkey.comsfdcMonkey.com
@isTest

public class PlanPackageNamesTest
{

      static testMethod void myUnitTest()
     
    {
        Plan__c plan = new Plan__c();
        plan.Name='Ultimate Health Diamond';
        plan.Product_Name__c='UH';
        plan.Carrier_Vendor__c='Transamerica';
        plan.Services_Phone_Number__c='1-855-943-4595';
        plan.annual_single_maximum__c=100;
        plan.annual_family_maximum__c=100;
        plan.vision__c=100;
        plan.dental__c=100;
        plan.RX__c=100;
        plan.Counseling__c=100;
        plan.wellness__c=100;
        plan.medical_equipment__c=100;
        plan.executive_physical__c=100;
        plan.medical_expense_coverage__c='All 213 Eligible';
        plan.armada_plan_package_name__c='Diamond';
        plan.Policy_Group_Number__c='111';
        plan.Plan_Division__c='000A';
		plan.Sum_of_Benefits__c = 90000;
      
        insert plan;
		Plan.Sum_of_Benefits__c = 10000;
        update plan;
        
     

        
        }
Try it :)
Thanks
 
Zach AckermanZach Ackerman
plan.Sum_of_Benefits__c is a formula field. Should i just remove that field?
Zach AckermanZach Ackerman
Annual_Single_Maximum__c+Annual_Family_Maximum__c+ Dental__c+ Counseling__c+ Medical_Equipment__c+ Executive_Physical__c + Wellness__c + RX__c + Vision__c
Zach AckermanZach Ackerman
I'm not sure i understand. The formula field is the sum of the following fields.  plan.Sum_of_benefits__c=Annual_Single_Maximum__c+Annual_Family_Maximum__c+ Dental__c+ Counseling__c+ Medical_Equipment__c+ Executive_Physical__c + Wellness__c + RX__c + Vision__c. What would i need to do?

 
sfdcMonkey.comsfdcMonkey.com
@isTest

public class PlanPackageNamesTest
{

      static testMethod void myUnitTest()
     
    {
        Plan__c plan = new Plan__c();
        plan.Name='Ultimate Health Diamond';
        plan.Product_Name__c='UH';
        plan.Carrier_Vendor__c='Transamerica';
        plan.Services_Phone_Number__c='1-855-943-4595';
        plan.annual_single_maximum__c=100;
        plan.annual_family_maximum__c=100;
        plan.vision__c=100;
        plan.dental__c=100;
        plan.RX__c=100;
        plan.Counseling__c=100;
        plan.wellness__c=100;
        plan.medical_equipment__c=100;
        plan.executive_physical__c=100;
        plan.medical_expense_coverage__c='All 213 Eligible';
        plan.armada_plan_package_name__c='Diamond';
        plan.Policy_Group_Number__c='111';
        plan.Plan_Division__c='000A';
	
        insert plan;
		plan.RX__c=89200;   // now total Sum_of_Benefits__c is equal to 90000
        update plan;
        
     

        
        }
now your trigger code 100% cover :)
Thanks
 
Zach AckermanZach Ackerman
Thanks that worked, but I'm at 52%