You need to sign in to do that
Don't have an account?
Vinay Salve
Create an Apex class that uses Batch Apex to update Lead records.
Hi Team,
While doing the Create an Apex class that uses Batch Apex to update Lead records, Kindly assist.
I have used the following code for Lead Processor, however I got the error in Line One - Declarations can only have one scope
global public class LeadProcessor implements Database.Batchable<sObject>
{
global integer count = 0;
global Database.QueryLocator start(Database.BatchableContext bc)
{
return Database.getQueryLocator('SELECT Id, LeadSource from Lead');
}
global void execute (Database.BatchableContext bc, List<Lead> l_1st)
{
List<Lead> l_1st_new = new List<Lead>();
for(lead l : l_1st)
{
l.leadsource = 'Dreamforce';
l_1st_new.add(1);
count += 1;
}
update l_1st_new;
}
global void finish(Database.BatchableContext bc)
{
system.debug('count =' + count);
}
}
I have used the following code for Lead Processor Test, however I got the error in Line 19 - Method does not exist or incorrect signature: void executeBatch(LeadProcessor) from the type Database
@IsTest
public class LeadProcessorTest {
@IsTest
public static void testit()
{
List<lead> l_1st = new List<lead>();
for(integer i=0; i<200; i++)
{
Lead l = new lead();
l.LastName = 'name' + i;
l.company = 'company';
l.status = 'Random Status';
l_1st.add(l);
}
insert l_1st;
Test.startTest();
LeadProcessor lp = new LeadProcessor();
Id batchId = Database.executeBatch(lp);
Test.stopTest();
}
}
Thanks
Vinay Kumar Salve
While doing the Create an Apex class that uses Batch Apex to update Lead records, Kindly assist.
I have used the following code for Lead Processor, however I got the error in Line One - Declarations can only have one scope
global public class LeadProcessor implements Database.Batchable<sObject>
{
global integer count = 0;
global Database.QueryLocator start(Database.BatchableContext bc)
{
return Database.getQueryLocator('SELECT Id, LeadSource from Lead');
}
global void execute (Database.BatchableContext bc, List<Lead> l_1st)
{
List<Lead> l_1st_new = new List<Lead>();
for(lead l : l_1st)
{
l.leadsource = 'Dreamforce';
l_1st_new.add(1);
count += 1;
}
update l_1st_new;
}
global void finish(Database.BatchableContext bc)
{
system.debug('count =' + count);
}
}
I have used the following code for Lead Processor Test, however I got the error in Line 19 - Method does not exist or incorrect signature: void executeBatch(LeadProcessor) from the type Database
@IsTest
public class LeadProcessorTest {
@IsTest
public static void testit()
{
List<lead> l_1st = new List<lead>();
for(integer i=0; i<200; i++)
{
Lead l = new lead();
l.LastName = 'name' + i;
l.company = 'company';
l.status = 'Random Status';
l_1st.add(l);
}
insert l_1st;
Test.startTest();
LeadProcessor lp = new LeadProcessor();
Id batchId = Database.executeBatch(lp);
Test.stopTest();
}
}
Thanks
Vinay Kumar Salve
This issue is now sorted, I figured it out,thanks
All Answers
Moreover, I get the following error - The Apex class does not appear using a QueryLocator to in the start method. in Check Challenge
Request you to kindly assist,
Thanks
Vinay Kumar Salve
This issue is now sorted, I figured it out,thanks