0

I have a class and a test method. When trying to deploy I get the following error Test failure

This is the class:

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 WHERE Type = Client';
    List<Account> sobjList = Database.query(strQuery);

    return sobjList;
    }

}

and this is the test class:

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

Can anyone explain/help me understand why this error is showing. Not sure why it doesn't like the WHERE function. We have an existing function that uses this in.

Many thanks,

4

You miss the FROM part in the query. It expects FROM when it arrives at the WHERE.

2

You didn't specify Table_name in your query... use from TableName

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';
1

Your query is missing:

from Account

hence the syntax error.

You would be better off using static SOQL so that the compiler checks the query for you i.e.:

WebService static List<Account> getAccount()
    return [select Name, CASESAFE_ID__c, ...];
}

Dynamic SOQL (representing the SOQL in a string) is only needed where you want to change the structure of the query according to some logic. Static SOQL can handle the vast majority of query requirements. Both allow Apex variables to be bound into the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.