• SteveOB
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies

Hello,

 

I have developed a trigger and tested successfully in the sandbox environment. Now I would like to deploy into production however, I ran into some issues providing the sufficient trigger code coverage needed in order to promote. I tried creating a public class where a static testmethod for the trigger is defined, but although the class saves without errors, my trigger is still unable to be promoted. Any help in writing the correct testmethod for my trigger would be greatly appreciated. Thanks in advance.

 

--Here is my trigger:

Trigger ClientHandOffUpdate on Client_Hand_Off__c(after insert, after update)
{
Client_Hand_Off__c[] CHOs = Trigger.new;
 
     for(Client_Hand_Off__c CHO:CHOs){

        Contract_Order_Line_Item__c[] updateCOLI = [SELECT Name FROM Contract_Order_Line_Item__c LIMIT 100];
            if (updateCOLI.size()>0)
            {
                for(Integer i = 0; i < updateCOLI.size(); i++)
                {
                    updateCOLI[i].Client_Hand_Off__c = null;
                    update updateCOLI;
                }
            } 
    }
 
    for(Client_Hand_Off__c CHO:CHOs){
 
        if (CHO.Contract_Order__c!= null){
 
        string ContactOrder = CHO.Contract_Order__c;

        Contract_Order_Line_Item__c[] updateCOLI = [SELECT Name FROM Contract_Order_Line_Item__c WHERE Contract_Order__r.Id = :ContactOrder LIMIT 100];
            if (updateCOLI.size()>0)
            {
                for(Integer i = 0; i < updateCOLI.size(); i++)
                {
                    updateCOLI[i].Client_Hand_Off__c = CHO.Id;
                    update updateCOLI;
                }
            }
        }   
    }
}

 

 

--Here is my Attempted Testmethod:

 

public with sharing class CHOtriggerUnitTest {
  
  public static testmethod void testClientHandOffTrigger()
    {
    
          Account acct = new Account(name='test account', Type='Prospect');
          insert acct;
          
          Contract_Order__c CO = new Contract_Order__c(Account__c=acct.Id,State_Fips__c = '01 AL');
          insert CO;
           
          Client_Hand_Off__c[] CHOstoCreate = new Client_Hand_Off__c[]{};
          for(Integer x=0; x<200;x++){
              Client_Hand_Off__c CHOS = new Client_Hand_Off__c(Client_Name__c=acct.Id,Contract_Order__c=CO.Id,Client_Personality__C ='Test Client Hand Off Form');
              insert CHOstoCreate;
          }
           
   }   

}

 

Hello,

 

I tested the following code in Sandbox and it worked perfectly fine. Granted that the sandbox environment tends to ignore some Failures and Warnings that would otherwise be flagged when deploying to production. Which is exactly what I think is happening now when I try to deploy this code. Any help or suggestions on what i might be missing in this code would be greatly appreciated.

 

Code is as follows:

*********************

public class BUG_RelatedBug
{
    public static testmethod void test1()
    {
        BUG_RelatedBug obj = new BUG_RelatedBug();
        
        SFDC_Bug__c objBug = new SFDC_Bug__c();
        objBug.Problem__c = 'testBug';
        insert objBug;
        objBug.Problem__c= 'test';
                   
        SFDC_Related_Bug__c objRelatedBug = new SFDC_Related_Bug__c();
        objRelatedBug.SFDC_Bug__c = objBug.Id;
        insert objRelatedBug;
        
        obj.allBugs = objBug.Id;
        obj.bugId = System.currentPageReference().getParameters().get('id');
        obj.SaveAll();
        obj.goBack();
    }
    
    public BUG_RelatedBug()
    {
       try
       {
           bugId = System.currentPageReference().getParameters().get('id');
           bugName = [SELECT Name FROM SFDC_Bug__c WHERE SFDC_Bug__c.Id=: bugId LIMIT 1].Name;
       }
       catch(Exception ex)
       {
           // DO NOTHING
       }
    }
    
    public PageReference saveAll()
    {
        list<String> SplitBugArr = allBugs.split(',');
        list<SFDC_Related_Bug__c> listRelatedBug = new list<SFDC_Related_Bug__c>();
        if(SplitBugArr.size() > 0)
        {
            for(Integer i = 0; i < SplitBugArr.size(); i++)
            {
                SFDC_Related_Bug__c ObjRelatedBug = new SFDC_Related_Bug__c();
                ObjRelatedBug.SFDC_Bug__c = bugId;
                ObjRelatedBug.SFDC_Bug_Num__c = SplitBugArr[i];                       
                listRelatedBug.add(ObjRelatedBug);
                
                SFDC_Related_Bug__c ObjRelatedBug2 = new SFDC_Related_Bug__c();
                ObjRelatedBug2.SFDC_Bug__c = SplitBugArr[i];
                ObjRelatedBug2.SFDC_Bug_Num__c = bugId;                       
                listRelatedBug.add(ObjRelatedBug2);
                
                SFDC_Bug__c[] UpdateBug = [SELECT Name FROM SFDC_Bug__c WHERE SFDC_Bug__c.Id=: bugId LIMIT 1];
                if (UpdateBug.size()>0)
                {UpdateBug[0].Status__c = 'Pending - BUG';
                update UpdateBug;
                }
                               
               
            }
            
        }
        if(listRelatedBug.size() > 0)
        {
            insert listRelatedBug;
        }
        return goBack();
    }
    
   public pageReference goBack()
   {
       PageReference pageRef = new PageReference('/'+bugId);
       pageRef.setRedirect(true);
       return pageRef;
   }
    
    
    
    public string bugId
    {
        set
        {
            bugId = value;
        }
        get
        {
            return bugId;
        }
    }
    public string bugName
    {
        set
        {
            bugName = value;
        }
        get
        {
            return bugName;
        }
    }
     public string allBugs
     {
        set
        {
           allBugs = value;
        }
        get
        {
           return allBugs;
        }

     }
     
}

****************

 

I get the following Error Message:

 

"System.DmlException:Insert Failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [SFDC_Bug__c]: [SFDC_Bug__c]"

 

 

Thanks in Advance.

Hello,

 

I have developed a trigger and tested successfully in the sandbox environment. Now I would like to deploy into production however, I ran into some issues providing the sufficient trigger code coverage needed in order to promote. I tried creating a public class where a static testmethod for the trigger is defined, but although the class saves without errors, my trigger is still unable to be promoted. Any help in writing the correct testmethod for my trigger would be greatly appreciated. Thanks in advance.

 

--Here is my trigger:

Trigger ClientHandOffUpdate on Client_Hand_Off__c(after insert, after update)
{
Client_Hand_Off__c[] CHOs = Trigger.new;
 
     for(Client_Hand_Off__c CHO:CHOs){

        Contract_Order_Line_Item__c[] updateCOLI = [SELECT Name FROM Contract_Order_Line_Item__c LIMIT 100];
            if (updateCOLI.size()>0)
            {
                for(Integer i = 0; i < updateCOLI.size(); i++)
                {
                    updateCOLI[i].Client_Hand_Off__c = null;
                    update updateCOLI;
                }
            } 
    }
 
    for(Client_Hand_Off__c CHO:CHOs){
 
        if (CHO.Contract_Order__c!= null){
 
        string ContactOrder = CHO.Contract_Order__c;

        Contract_Order_Line_Item__c[] updateCOLI = [SELECT Name FROM Contract_Order_Line_Item__c WHERE Contract_Order__r.Id = :ContactOrder LIMIT 100];
            if (updateCOLI.size()>0)
            {
                for(Integer i = 0; i < updateCOLI.size(); i++)
                {
                    updateCOLI[i].Client_Hand_Off__c = CHO.Id;
                    update updateCOLI;
                }
            }
        }   
    }
}

 

 

--Here is my Attempted Testmethod:

 

public with sharing class CHOtriggerUnitTest {
  
  public static testmethod void testClientHandOffTrigger()
    {
    
          Account acct = new Account(name='test account', Type='Prospect');
          insert acct;
          
          Contract_Order__c CO = new Contract_Order__c(Account__c=acct.Id,State_Fips__c = '01 AL');
          insert CO;
           
          Client_Hand_Off__c[] CHOstoCreate = new Client_Hand_Off__c[]{};
          for(Integer x=0; x<200;x++){
              Client_Hand_Off__c CHOS = new Client_Hand_Off__c(Client_Name__c=acct.Id,Contract_Order__c=CO.Id,Client_Personality__C ='Test Client Hand Off Form');
              insert CHOstoCreate;
          }
           
   }   

}

 

Hello,

 

I tested the following code in Sandbox and it worked perfectly fine. Granted that the sandbox environment tends to ignore some Failures and Warnings that would otherwise be flagged when deploying to production. Which is exactly what I think is happening now when I try to deploy this code. Any help or suggestions on what i might be missing in this code would be greatly appreciated.

 

Code is as follows:

*********************

public class BUG_RelatedBug
{
    public static testmethod void test1()
    {
        BUG_RelatedBug obj = new BUG_RelatedBug();
        
        SFDC_Bug__c objBug = new SFDC_Bug__c();
        objBug.Problem__c = 'testBug';
        insert objBug;
        objBug.Problem__c= 'test';
                   
        SFDC_Related_Bug__c objRelatedBug = new SFDC_Related_Bug__c();
        objRelatedBug.SFDC_Bug__c = objBug.Id;
        insert objRelatedBug;
        
        obj.allBugs = objBug.Id;
        obj.bugId = System.currentPageReference().getParameters().get('id');
        obj.SaveAll();
        obj.goBack();
    }
    
    public BUG_RelatedBug()
    {
       try
       {
           bugId = System.currentPageReference().getParameters().get('id');
           bugName = [SELECT Name FROM SFDC_Bug__c WHERE SFDC_Bug__c.Id=: bugId LIMIT 1].Name;
       }
       catch(Exception ex)
       {
           // DO NOTHING
       }
    }
    
    public PageReference saveAll()
    {
        list<String> SplitBugArr = allBugs.split(',');
        list<SFDC_Related_Bug__c> listRelatedBug = new list<SFDC_Related_Bug__c>();
        if(SplitBugArr.size() > 0)
        {
            for(Integer i = 0; i < SplitBugArr.size(); i++)
            {
                SFDC_Related_Bug__c ObjRelatedBug = new SFDC_Related_Bug__c();
                ObjRelatedBug.SFDC_Bug__c = bugId;
                ObjRelatedBug.SFDC_Bug_Num__c = SplitBugArr[i];                       
                listRelatedBug.add(ObjRelatedBug);
                
                SFDC_Related_Bug__c ObjRelatedBug2 = new SFDC_Related_Bug__c();
                ObjRelatedBug2.SFDC_Bug__c = SplitBugArr[i];
                ObjRelatedBug2.SFDC_Bug_Num__c = bugId;                       
                listRelatedBug.add(ObjRelatedBug2);
                
                SFDC_Bug__c[] UpdateBug = [SELECT Name FROM SFDC_Bug__c WHERE SFDC_Bug__c.Id=: bugId LIMIT 1];
                if (UpdateBug.size()>0)
                {UpdateBug[0].Status__c = 'Pending - BUG';
                update UpdateBug;
                }
                               
               
            }
            
        }
        if(listRelatedBug.size() > 0)
        {
            insert listRelatedBug;
        }
        return goBack();
    }
    
   public pageReference goBack()
   {
       PageReference pageRef = new PageReference('/'+bugId);
       pageRef.setRedirect(true);
       return pageRef;
   }
    
    
    
    public string bugId
    {
        set
        {
            bugId = value;
        }
        get
        {
            return bugId;
        }
    }
    public string bugName
    {
        set
        {
            bugName = value;
        }
        get
        {
            return bugName;
        }
    }
     public string allBugs
     {
        set
        {
           allBugs = value;
        }
        get
        {
           return allBugs;
        }

     }
     
}

****************

 

I get the following Error Message:

 

"System.DmlException:Insert Failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [SFDC_Bug__c]: [SFDC_Bug__c]"

 

 

Thanks in Advance.