[SalesForce] Debug Database.getQueryLocator(query);

I want to see the result which Database.getQueryLocator(query) is returning in 'open execute anonymous window' so how to debug to see the result coming in that.

global database.querylocator start(Database.BatchableContext BC)
{
    return Database.getQueryLocator(query);
}

Best Answer

Just simply run this query in anonymous window and you will get the result. Check code sample below.

string query = 'Select id from account';
system.debug(Database.getQueryLocator(query));
//add code to display the result.
Database.QueryLocator q = Database.getQueryLocator(s);
// Get an iterator
Database.QueryLocatorIterator it =  q.iterator();

// Iterate over the records
while (it.hasNext())
{
    Account a = (Account)it.next();
    System.debug(a);
}

Replace query with your query string.

Related Topic