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
GhanesanGhanesan 

Can we use seealldata=true for production?

i have used seealldata=true for my test class below, its cover 100% and no failure. my question here is can we use seealldata= true for production deployement too? When i remove the sealldata=true in test class, code coverage is 100% but having 130+ failure. see below screenshot. 

Batch Apex:

global class EmailBounceBatchApex implements Database.Batchable<sobject>{
    global Database.QueryLocator start(Database.BatchableContext bc) {
        string query = 'SELECT Id,Name from Lead where EmailBouncedDate!=Null AND EmailBouncedReason!=Null';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext bc, List<Lead> Scope) {
        for(Lead l:Scope){
            
                l.Status = 'Disqualified';
                l.Reason_for__c = 'Inadequate Data';
                
           }
            update scope;
    
    }
    global void finish(Database.BatchableContext bc) {
                }
}

TestClass:

@isTest
public class EmailBounceBatchApexTest {
    Public Static testmethod void BounceTest() {      
        Lead testLead = new Lead();
        testLead.LastName = 'Test';
        testLead.Company ='ABC';
        testLead.Email='trd@gmail.com';
        testLead.Phone='1234567890';
        insert testLead;
   
        testLead.EmailBouncedDate = system.today();
        testLead.EmailBouncedReason ='email address was not valid';
        update testLead;
        
       Campaign camp1 = new Campaign();
        camp1.Name = 'Test Campaign 1';
        camp1.IsActive = True;
        insert camp1;
      
      CampaignMember testMember = new CampaignMember(LeadId =testLead.Id, CampaignId =camp1.id, Status = 'Sent');
        insert testMember;
        EmailBounceBatchApex bc = new EmailBounceBatchApex();
        database.executeBatch(bc);
            
        }
}



User-added image
Best Answer chosen by Ghanesan
AnkaiahAnkaiah (Salesforce Developers) 
Hi Ganesan,

As per salesforce recomandations and test best practices we should not use seeAllData=true in the test test classes.

As per my understanding, you were running all the test classes in the production and as a result some of the classes were getting failed.

If you were tring to deploy only the batch class then use the run specified test classes option to deploy your changes.

Refer the below link.
https://www.greytrix.com/blogs/salesforce/2016/09/07/deployment-options-for-changeset/

If this helps, Please mark it as best answer.

Thanks!!