1

I have a small peice of code I'm trying to deploy into production instance from a sandbox. Before deployment code coverage is 79%, I get an error saying it wont deploy because code coverage is 74%. Is it safe to assume the code I'm deploying is bringing down the coverage and therefore won't deploy?

Code Coverage Error

My Web Service class is:

global class ClientAllocation {

WebService static List<Account> getAccount()
{
    string strQuery = 'select Name, CASESAFE_ID__c, Production_environment__c, External_Identifier__c, Member_Web_URL__c, Administration__c, Pensions__c, Broking__c, Helpdesk__c, Helpdesk_Email__c, Helpdesk_Number__c, Account_Owner_Name__c, Darwin_Support_Associate__c, Selection_Window_Open_Month__c from tableName WHERE Type = Client';
    List<Account> sobjList = Database.query(strQuery);

    return sobjList;
    }

}

and my test class is:

@isTest
public class ClientAllocationTest{
public static @isTest void sampleTestMethod(){
    list<Account> alist = ClientAllocation.getAccount();
    // system.assert();
    }
}

Can anyone identify any improvements that can be made to get this deployed? Obviously my code coverage isn't sufficient so the test class maybe?

Much appreciated

2
  • 1
    there is a problem with your test class. first try to remove this error and may be you complete the deployment. Also check that code coverage is still 79% because in apex test code coverage sometimes it display old code coverage. Aug 14, 2015 at 8:52
  • 1
    Thanks, I appreciate that but what is wrong with it? I don't understand what the error is and how to change it Aug 14, 2015 at 9:36

2 Answers 2

1

There is another problem with your test class as you can see in error log. In your strQuery you need to provide ' characters in WHERE clause because you are using a string to check Type field.

It should look like this

select Name, CASESAFE_ID__c, Production_environment__c, External_Identifier__c, Member_Web_URL__c, Administration__c, Pensions__c, Broking__c, Helpdesk__c, Helpdesk_Email__c, Helpdesk_Number__c, Account_Owner_Name__c, Darwin_Support_Associate__c, Selection_Window_Open_Month__c from tableName__c WHERE Type = \'Client\''
3
  • 1
    This is great advice, however since changing that I am now getting a different error: ClientAllocationTest.sampleTestMethod(), Details: System.QueryException: sObject type 'tableName' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. Class.ClientAllocation.getAccount: line 6, column 1 Class.ClientAllocationTest.sampleTestMethod: line 4, column 1 Aug 14, 2015 at 9:37
  • What is the name of the object are you using in your query? I did not noticed it first but as somebody else mentioned if your object is named tableName in your query it should be tableName__c. You can check exact API name of your object from Setup -> Create -> Objects - > Your Object - > API Name. This is what you should write after FROM clause. I've updated my answer accordingly.
    – tugce
    Aug 14, 2015 at 11:53
  • Its just the Account object which is a standard object therefore no need for __c. Think the error is a red herring Aug 14, 2015 at 15:44
0

Please confirm the real data which is covering the code is making your code coverage less.

Make the data in org accordingly and try

3
  • Hi Arun, what does that mean? "confirm the real data which the code is making your coverage less" ? Does that mean what set of data is it looking at? Aug 14, 2015 at 15:46
  • Yes. Meant what set of data is it looking at.
    – Arun SFDC
    Aug 15, 2015 at 16:03
  • Its just a set of fields on the account object Aug 17, 2015 at 8:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .