• Rajesh Dangat 9
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi 
I have created one batch class that contains the following code. I want to write one logic for sandbox and one for production.   
ObjectPermissions[] objectPermissionsArray = [SELECT Id,sObjectType,parentid FROM ObjectPermissions WHERE ParentId In '...'];    
  Organization org = [select Id, IsSandbox from Organization limit 1];  
 if(org.IsSandbox || test.isRunningTest()) {    //   sandbox code
 } 
else {
 // production code }

 In test class code coverage the else block is showing in red color. and code coverage is 78%. Same happen with following condition.    
if(!objectPermissionsArray.IsEmpty()){
     code
 }else{ code } 


  Test class 
  {  test.starttest();   
       database.executeBatch(new BatchJobname());       
  test.stoptest();
  }