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
Sunny GSunny G 

HOW TO DEPLOY.. TRIGGER AND TEST CLASS TO PRODUCTION

Hi,

 

Please help me with one trigger and class.. like i have the following trigger:

 

   

trigger updaterequestowner on Pre_Sales_Request__c​ (before insert)
{

 

       Profile auth_profile = [select id from prof​ile where name='HS_StandardUser_Presales'];       ​   
       Id v_User = UserInfo.GetProfileId();
      for(Pre_Sales_Request__c ob : Trigger.new)
        {          
            if(v_User !=  auth_profile.Id)       
                {
                   ob.Request_Owner__c =  Userinfo​.getUserId(); 
                }
        }                           
}

 

 

 

and i have the following test class :

 

 

 

@isTest

private class TriggerTests {
            
    public static testmethod void testTrigger() {
       Pre_Sales_Request__c psrc=new Pre_Sales_R​equest__c( name = 'a' );
       insert psrc;
       psrc.name = 'b';
       update psrc;  

    }
}

 

  

 

am i missing anything in trigger or test class?? Also, please let me know when i tried deploying these i always get an error somthing like "minimum 1% code coverage is required for the trigger" although it covers 100% in sandbox...

SargeSarge

Hi Sunny,

 

   You have use "runAs" system method in your test method to test the trigger which involves checking for current user's attributes.  Check this link for the documentation for runAs in unit testing.

  Also in unit tests perform dml operations that will meet the condition of the trigger to execute. Like for this trigger change the user in runAs which is not associated to the profile "HS_StandardUser_Presales" and then perform dml. The trigger will chck for the current user's profile and decides whether it has to assign current user to  Request_Owner field or not.

 

 Hope this helps.