You need to sign in to do that
Don't have an account?
anji punyamanthula
how to assign records to different users
I have 3 users i want to fetch 10 records from Account object and assign first 3 records to first user next 3 records 2nd user another 3 records to 3rd user and again it will go to 1st user to assign another record how to do that can any one help me in that.
my code is below
batch class:
global class Batch_Example_3 implements Database.Batchable<sobject>,Database.Stateful {
global Static Integer count;
global Database.QueryLocator Start(Database.BatchableContext bc){
String s='select name,ownerid from Account limit 10';
return database.getQueryLocator(s);
}
global void execute(Database.BatchableContext bc,List<Account> accs){
count=0;
List<User> myuser=[select id from user limit 3];
for(user u:myuser){
for(Account a:accs){
a.OwnerId=u.id;
count+=1;
update a;
}
}
//update accs;
}
global void finish(Database.BatchableContext bc){
}
}
execution:
Batch_Example_3 ba=new Batch_Example_3();
Id JobId=database.executeBatch(ba,1);
my code is below
batch class:
global class Batch_Example_3 implements Database.Batchable<sobject>,Database.Stateful {
global Static Integer count;
global Database.QueryLocator Start(Database.BatchableContext bc){
String s='select name,ownerid from Account limit 10';
return database.getQueryLocator(s);
}
global void execute(Database.BatchableContext bc,List<Account> accs){
count=0;
List<User> myuser=[select id from user limit 3];
for(user u:myuser){
for(Account a:accs){
a.OwnerId=u.id;
count+=1;
update a;
}
}
//update accs;
}
global void finish(Database.BatchableContext bc){
}
}
execution:
Batch_Example_3 ba=new Batch_Example_3();
Id JobId=database.executeBatch(ba,1);
Try something like this.
Thanks,
Gaurav
Skype: gaurav62990