You need to sign in to do that
Don't have an account?
Galeeb SK
insert records through batch apex
Hai, i tried to insert records through batch apex but it can't ,tell me ,my code is
global class opportunityincrement implements database.batchable<sObject>{
global database.QueryLocator start(database.batchableContext bc){
string query='select id,Name,Job_Description__c,Max_Pay__c,Min_Pay__cfrom Position__c';
return database.getQueryLocator(query);
}
global void execute(database.batchableContext bc,list<Position__c>scope){
system.debug(scope+'bbbbbbbbbbbbbbbbbbb');
list<Position__c> oppty=new list<Position__c>();
for(Position__c opp:scope){
opp.Name='Test';
opp.Job_Description__c= 'Closed';
opp.Max_Pay__c= 10000;
opp.Min_Pay__c= 5000;
oppty.add(opp);
system.debug(oppty+'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
}
insert oppty;
}
global void finish(database.batchableContext bc){
}
}
global class opportunityincrement implements database.batchable<sObject>{
global database.QueryLocator start(database.batchableContext bc){
string query='select id,Name,Job_Description__c,Max_Pay__c,Min_Pay__cfrom Position__c';
return database.getQueryLocator(query);
}
global void execute(database.batchableContext bc,list<Position__c>scope){
system.debug(scope+'bbbbbbbbbbbbbbbbbbb');
list<Position__c> oppty=new list<Position__c>();
for(Position__c opp:scope){
opp.Name='Test';
opp.Job_Description__c= 'Closed';
opp.Max_Pay__c= 10000;
opp.Min_Pay__c= 5000;
oppty.add(opp);
system.debug(oppty+'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
}
insert oppty;
}
global void finish(database.batchableContext bc){
}
}
modify your code like this...
All Answers
modify your code like this...
But there are few things in Ram's code which can alos be modified.
Please update code as follows :
global class opportunityincrement implements database.batchable<sObject> {
global database.QueryLocator start(database.batchableContext bc){
string query='select id,Name,Job_Description__c,Max_Pay__c,Min_Pay__c from Position__c';
return database.getQueryLocator(query);
}
global void execute(database.batchableContext bc,list<Position__c> scope){
system.debug(scope+'bbbbbbbbbbbbbbbbbbb');
List<Position__c> oppty = new List<Position__c>();
for(Integer i=0 : i < scope.size() ; i++){
//dont use opp here...
Position__c c=new Position__c();
c.Name='Test';
c.Job_Description__c= 'Closed';
c.Max_Pay__c= 10000;
c.Min_Pay__c= 5000;
oppty.add(c);
}
insert oppty;
}
global void finish(database.batchableContext bc){
}
}
Let me know if you need more help on this.
Regards,
Abhishek
global class BatchAccounts implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id,Name FROM Account' ;
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> scope) {
List<Account> accList = new List<Account>();
for (integer i=1;i<6;i++)
{
Account anew= new Account(Name ='Account '+i);
anew.Type = 'Prospect';
accList.add(anew);
}
upsert accList;
}
global void finish(Database.BatchableContext BC) {
}
}
Can anyone help me with this?