0
    global class BatchUpdateEnrollmentState implements Database.Batchable < sObject > , Database.AllowsCallouts, Database.Stateful {
        public String query;

        global Database.QueryLocator start(Database.BatchableContext BC) {
            query = 'SELECT Contact__c,Id,Program_Type__c,RecordtypeId,Communication_Options__c,Prescriber_Site__c,Prescriber__c,Treatment_Location__c,Treatment_Location_Staff__c,TC_Patient_ID__c,Product_Savings_Programs__c,Product__c,Mail_Check_Site__c,Current_Payment_Type__c,Instant_Savings_ID__c  FROM Patient_Savings_Program__c WHERE Instant_Savings_ID__c != null ' + Label.batchLimitEnrollment;
           System.debug('query '+query);
                           System.debug('query123 '+Database.getQueryLocator(query));

            return Database.getQueryLocator(query);

        }

Here Label.batchLimitEnrollment is the custom labels having values like this:-

AND Instant_Savings_ID__c IN ('62538115409', 
'62538095109', 
'62538123909', 
'62538132309', 
'62538136909', 
'62538158309', 
'62538108809', 
'62538163109', 
'62538165909', 
'62538170709', 
'62538173409', 
'62538175209', 
'62538180009', 
'62538182809', 
'62538080309' 
)   

I am stuck in Label.batchLimitEnrollment filter criteria due to which the query is failing. Error:--- **Have removed the previous error but now the query result on debug I am getting like this. just focus on the last part of the query ,that is what creating the problem ,the closing bracket is not coming now. query:- SELECT Contact__c,Id,Program_Type__c,RecordtypeId,Communication_Options__c,Prescriber_Site__c,Prescriber__c,Treatment_Location__c,Treatment_Location_Staff__c,TC_Patient_ID__c,Product_Savings_Programs__c,Product__c,Mail_Check_Site__c,Current_Payment_Type__c,Instant_Savings_ID__c FROM Patient_Savings_Program__c WHERE Instant_Savings_ID__c != null AND Instant_Savings_ID__c IN ('62538115409',

  • In what way are you stuck? What specific error message do you receive or what negative behavior do you see? (Please make an edit to add these details to your question). – David Reed Aug 13 '18 at 11:18
  • @David...yeah have updated the question with the error message – vineet Aug 13 '18 at 11:35
  • @David.... hope now u cud help me out with the updated issue – vineet Aug 13 '18 at 11:44
  • Vineet, let's focus on one issue at a time to help the community be able to find you an answer. Right now it looks like you are not working with a test class, like your title says, but you do have an error message. Can you add that error message to your question? The debug log by itself is not necessarily enough to clarify the issue. – David Reed Aug 13 '18 at 12:47
1

Assuming your tests are creating the Patient_Savings_Program__c objects, I suggest you add a separate contructor for use in the tests. You then build the string to match the test data and pass that into the batchable:

public class BatchUpdateEnrollmentState implements Database.Batchable < sObject > , Database.AllowsCallouts, Database.Stateful {

    private String queryTerm;

    public BatchUpdateEnrollmentState() {
        this(Label.batchLimitEnrollment);
    }

    @TestVisible
    private BatchUpdateEnrollmentState(String queryTerm) {
        this.queryTerm = queryTerm;
    }

    public Database.QueryLocator start(Database.BatchableContext BC) {

        String term = Test.isRunningTest() ? Label.batchLimitEnrollment;
        String query = ''
                + 'SELECT Contact__c,Id,Program_Type__c,RecordtypeId,Communication_Options__c,Prescriber_Site__c,Prescriber__c,Treatment_Location__c,Treatment_Location_Staff__c,TC_Patient_ID__c,Product_Savings_Programs__c,Product__c,Mail_Check_Site__c,Current_Payment_Type__c,Instant_Savings_ID__c '
                + 'FROM Patient_Savings_Program__c '
                + 'WHERE Instant_Savings_ID__c != null ' + queryTerm;
        System.debug('query ' + query);
        return Database.getQueryLocator(query);
    }

    ...
}

from the tests:

String queryTerm = ...;
Test.startTest();
Database.executeBatch(new BatchUpdateEnrollmentState(queryTerm));
Test.stopTest();

Or a cleaner approach would be to use a list custom setting for the Instant_Savings_ID values rather than a label as that can be modified in a test to match the test data.

| improve this answer | |
  • hi Keith ....might be ur solution is correct but at this stage we cant change class code. – vineet Aug 13 '18 at 11:34
  • @vineet Well if the class isn't testable you will have to. But I see you've added an error to the question so the answer you are looking for now may be different. – Keith C Aug 13 '18 at 11:38
  • @Keith....thnx for the response.....hope now the issue is resolvable...thoughts..please? – vineet Aug 13 '18 at 11:44
  • i have updated the error message...kindly help. – vineet Aug 13 '18 at 11:45
  • @vineet See what happens when you remove the line breaks from the label. – Keith C Aug 13 '18 at 12:12

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.