You need to sign in to do that
Don't have an account?
xNamelessonex
SOQL Code coverage in Test Classes
I have read some posts on the forum, which use this as a demonstration of how to create good code coverage. http://amitsalesforce.blogspot.mx/2015/06/best-practice-for-test-classes-sample.html
I am using the Force.com Developer console, and when running tests the code coverage goes up to 40% or less, sometimes changing by 2%. The code not covered, according to the console has the following format:
I am using the Force.com Developer console, and when running tests the code coverage goes up to 40% or less, sometimes changing by 2%. The code not covered, according to the console has the following format:
if(Database.countQuery('SELECT count() FROM User WHERE User.Id = \''+ Object.variable+'\'') > 0) usr.add(Database.query('SELECT Id,Email FROM User WHERE User.Id = \''+ Object.variable +'\''));Now how do have to code this from the test perspective? I have created SObjects accordingly in the test class, but even if I do, the console does not increase the code coverage for the class intended to be set in production.
if you don't want to create instance of SObject, change your SObject methods to Static.
sample code here:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm
Good Luck!
All Answers
try to post your whole code and test code, and let's discuss from there...
However when deploying it to production it still claims the code coverage is below the 75% required. Does anyone know of any way of doing unit tests with SOQL queries that do not require creating instances of every single SObject intended to be tested?
if you don't want to create instance of SObject, change your SObject methods to Static.
sample code here:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm
Good Luck!