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
SFDC kidsSFDC kids 

Test CLass failure on production

Hi Team,

My test class is workig fine in send box 90% code, coverage but i deployed on production then this class fails. i am not getting what exact issue. 

Please help
Best Answer chosen by SFDC kids
mukesh guptamukesh gupta
Hi,

This type of situation raised when,
you use see all data = true in test class the your test class will execute on execting record according to sandbox, but if you deploy this code on production then your test call may be fails because your sandbox record differents compare to your production org, so please create new record for test class.

So please check and try to follow salesforce best practices

seeAllData: Using this annotation isTest(seeAllData=true) you will be able to access the records in your organization.If you are fetching records from the database in your test class, then set this annotation value to true. There is few object like ‘opportunityLineItem’ for which we cannot create test data so to test with ‘opportunityLineItem’ we need to access this object records from our salesforce org so in that case, we will set the value of seeAllData to true.
But if you are inserting test records for an object and then you want to query them in your test class, in that case, you need to setup seeAllData to false. Otherwise, test class will not get executed.

if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 

All Answers

mukesh guptamukesh gupta
Hi,

This type of situation raised when,
you use see all data = true in test class the your test class will execute on execting record according to sandbox, but if you deploy this code on production then your test call may be fails because your sandbox record differents compare to your production org, so please create new record for test class.

So please check and try to follow salesforce best practices

seeAllData: Using this annotation isTest(seeAllData=true) you will be able to access the records in your organization.If you are fetching records from the database in your test class, then set this annotation value to true. There is few object like ‘opportunityLineItem’ for which we cannot create test data so to test with ‘opportunityLineItem’ we need to access this object records from our salesforce org so in that case, we will set the value of seeAllData to true.
But if you are inserting test records for an object and then you want to query them in your test class, in that case, you need to setup seeAllData to false. Otherwise, test class will not get executed.

if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 
This was selected as the best answer
SFDC kidsSFDC kids
Thanks mukesh ,

Same issue found and now resolved