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
Bhola VishwakarmaBhola Vishwakarma 

0% code coverage in production but 98 % in sandbox

this is my following code 

trigger BeforeUpdateGoalYears on Goal__c (before update) {
    for(Integer j = 0; trigger.new.size()>j; j++){
        for(Integer i = 0; trigger.old.size()>i; i++){
           if(trigger.old[i].id == trigger.new[j].id){
               if(!(trigger.old[i].Goal_Start_Year__c == trigger.new[j].Goal_Start_Year__c 
               && trigger.old[i].Goal_End_Year__c  == trigger.new[j].Goal_End_Year__c)){
                    trigger.new[j].moderately_aggressive_profile_years__c = null;
                    trigger.new[j].moderately_conservative_profile_years__c  = null;
                    trigger.new[j].aggressive_profile_years__c  = null;
                    trigger.new[j].conservative_profile_years__c  = null;
                    trigger.new[j].moderate_profile_years__c  = null;
               }
           }
       } 
    }
}

 

what will be the reson for that please help

ashish raiashish rai

Hello,

      Can you please upload the test method??????????

Bhola VishwakarmaBhola Vishwakarma

thanks!!!!!!!!!!!!!!  ashish 

 



       

gol=new Goal__c(Entity__c=acc.id, Goal_End_Year__c = '2024',Goal_Start_Year__c='2021',Inflation_Rate__c=6,SelectedGoalProfile__c=goalProfile2.id,Saving_type__c='Constant annuity - Progressive Risk Profile',
                                 Cost_of_Goal_Annual__c=5000000,Priority__c='High',Description__c='Marriage',goal_type__c='Marriage',
                                 aggressive_profile_years__c=3,Goal_Frequency__c=null,moderately_aggressive_profile_years__c=2, moderate_profile_years__c=2,
                                 moderately_conservative_profile_years__c=2,conservative_profile_years__c=1);
       insert gol;
       system.assertNotEquals(null,gol.id);

 this is the code of the test class  which excute the trriger  

your help will make a lot of good to me 


ashish raiashish rai

Hello,

     Can you tell me wats acc.id???? If it is account id than first of all insert an account inside your test method then pass that accunt id inside the desired field of Goal__c. Like this:

 

Account accnt=new account(name="test Account"); // You have to find the mandatory field before inserting a account.

insert accnt;

now pass this id like

gol=new gol__c(Entity__c=accnt.id,..................................... and other filds)

insert gol;

 

 

Think this will help you.

ashish raiashish rai

Hello,

     Never try to query inside the test method because it may be possible when you have written the query inside that org , you have the record related to that query but when you move that code from one org to another that record may not exsist. So my openion is when ever you need to query inside the test method its better  you insert such kind of records. I think you have made a query on profile also. So try to avoid that than you will get the desired coverage in production org also.