function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
HI,
Try the below code snippet as reference:
global class OwnerReassignment implements Database.Batchable<sObject>
{
String query;
String email;
Id toUserId;
Id fromUserId;
global database.querylocator start(Database.BatchableContext BC)
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope)
List<Account> accns = new List<Account>();
for(sObject s : scope)
Account a = (Account)s;
if(a.Ownerid==fromUserId)
a.Ownerid=toUserId;
accns.add(a);
update accns;
global void finish(Database.BatchableContext BC)
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {email});
mail.setReplyTo('batch@acme.com');
mail.setSenderDisplayName('Batch Processing');
mail.setSubject('Batch Process Completed');
mail.setPlainTextBody('Batch Process has completed');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
Calling through System Debug Log
//user u=[select id,name from user where profile.name='system administrator'];
//system.debug('@@@@@@@@@' +u.name);
//user u2=[select id,name from user where profile.name='Standard User'];
//system.debug('########' +u2.name);
id st='00590000000eb7c';
OwnerReassignment reassign = new OwnerReassignment();
reassign.query='SELECT Id, Name, Ownerid FROM Account WHERE ownerid=\'' + st + '\'';
reassign.email='main.hu.9a@gmail.com';
reassign.fromUserId = '00590000000eb7c';
reassign.toUserId = '00590000000eb7w';
ID batchprocessid = Database.executeBatch(reassign);
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
can you please help me with my scenario....just overview in your code..please
HI,
Try the below code snippet as reference:
global class OwnerReassignment implements Database.Batchable<sObject>
{
String query;
String email;
Id toUserId;
Id fromUserId;
global database.querylocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope)
{
List<Account> accns = new List<Account>();
for(sObject s : scope)
{
Account a = (Account)s;
if(a.Ownerid==fromUserId)
{
a.Ownerid=toUserId;
accns.add(a);
}
}
update accns;
}
global void finish(Database.BatchableContext BC)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {email});
mail.setReplyTo('batch@acme.com');
mail.setSenderDisplayName('Batch Processing');
mail.setSubject('Batch Process Completed');
mail.setPlainTextBody('Batch Process has completed');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Calling through System Debug Log
//user u=[select id,name from user where profile.name='system administrator'];
//system.debug('@@@@@@@@@' +u.name);
//user u2=[select id,name from user where profile.name='Standard User'];
//system.debug('########' +u2.name);
id st='00590000000eb7c';
OwnerReassignment reassign = new OwnerReassignment();
reassign.query='SELECT Id, Name, Ownerid FROM Account WHERE ownerid=\'' + st + '\'';
reassign.email='main.hu.9a@gmail.com';
reassign.fromUserId = '00590000000eb7c';
reassign.toUserId = '00590000000eb7w';
ID batchprocessid = Database.executeBatch(reassign);
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
can you please help me with my scenario....just overview in your code..please