-3

I am doing a query from a field in custom settings. And updating the leads Here is my apex code

public with sharing class textInputsConsecond implements Schedulable   { 
    public list<Lead>  quo{get;set;}


    public void execute(SchedulableContext ctx){ 
        Group u = [
            SELECT
                Id,Name
            FROM Group
            WHERE Name = 'Unassigned Lead Retention' 
            Limit 1
        ];

        quo= Database.query(Lead__c.getInstance().Database_Query__c + 
        Lead__c.getInstance().Database_Query2__c);


        for(Lead ldt :quo){

            //Update those leads with new owner ID
            ldt.OwnerId = u.Id;

        }

        update quo;
    }
}

Here is how I am testing it -

@isTest
private class textInputsConsecondTest {
    @testSetup
    static void setup() {
        Group u = [
            SELECT
                Id,Name
            FROM Group
            WHERE Name = 'Unassigned Lead Retention'
            limit 1
        ];

        List<Lead> lstOfLead = new List<Lead>();
        for (Integer i = 1; i<= 200; i++) {
            Lead ld = new Lead(Company = 'Comp' +i,LastName = 'LN' + i, Status = 'Working');
            ld.OwnerId = u.Id ;
            lstofLead.add(ld);  
        }
        Insert lstOfLead;
    }
    static testmethod void testDailyLeadProcessorScheduledJob() {
        String sch = '0 5 12 * * ?';
        Test.startTest(); 
        String jobId = System.schedule('ScheduleApexText', sch, new 
        textInputsConsecond());    
    }
}

Getting this error everytime I Run my test

ClasstextInputsConsecondTest Method NametestDailyLeadProcessorScheduledJob Pass/Fail Fail Error Message System.QueryException: unexpected token: null null Stack Trace Class.textInputsConsecond.execute: line 7, column 1

  • 1
    How is this question different from this one? It is always advised to edit the original question and provide further updates, and not open a new one. – Jayant Das Feb 19 '19 at 17:12
1

Your test class must create and insert an instance of the Lead__c Custom Setting in your @testSetup method, supplying an appropriate query string to execute in your test.

Custom Settings are considered part of your organization's data and are not available to your unit tests. You must create the records required by your code under test.

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.