You need to sign in to do that
Don't have an account?
sales@myvarma
batch apex1
global class updatesaccount implements
Database.Batchable<sObject>, Database.Stateful
{
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'SELECT ID, Phone, ' +
'Fax, (SELECT ID, Phone, ' +
'Fax FROM Contacts) FROM Account ' +
'Where Industry = \'Construction\''
);
}
global void execute(Database.BatchableContext bc, List<Account> scope ){
List<Contact> contacts = new List<Contact>();
for (Account account : scope) {
for (Contact contact : account.contacts) {
contact.Phone = account.Phone;
contact.Fax = account.Fax;
contacts.add(contact);
recordsProcessed = recordsProcessed + 1;
}
}
update contacts;
}
global void finish(Database.BatchableContext bc){
System.debug(recordsProcessed + ' records processed. pradeepvarma');
AsyncApexJob job = [SELECT Id, Status, NumberOfErrors,
JobItemsProcessed,
TotalJobItems, CreatedBy.Email
FROM AsyncApexJob
WHERE Id = :bc.getJobId()];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'pradeep.gunturi@gmail.com'};
mail.setSubject('Match Merge Batch ');
mail.setPlainTextBody('hi pradeep batchapex completed');
mail.setToAddresses(toAddresses);
List<Messaging.SendEmailResult> sendRes = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }, true);
}
}
i want copy phone and fax of account whos industry is construction
but when ever we create new contact its sshowing whats problem in prgrm
Database.Batchable<sObject>, Database.Stateful
{
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'SELECT ID, Phone, ' +
'Fax, (SELECT ID, Phone, ' +
'Fax FROM Contacts) FROM Account ' +
'Where Industry = \'Construction\''
);
}
global void execute(Database.BatchableContext bc, List<Account> scope ){
List<Contact> contacts = new List<Contact>();
for (Account account : scope) {
for (Contact contact : account.contacts) {
contact.Phone = account.Phone;
contact.Fax = account.Fax;
contacts.add(contact);
recordsProcessed = recordsProcessed + 1;
}
}
update contacts;
}
global void finish(Database.BatchableContext bc){
System.debug(recordsProcessed + ' records processed. pradeepvarma');
AsyncApexJob job = [SELECT Id, Status, NumberOfErrors,
JobItemsProcessed,
TotalJobItems, CreatedBy.Email
FROM AsyncApexJob
WHERE Id = :bc.getJobId()];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'pradeep.gunturi@gmail.com'};
mail.setSubject('Match Merge Batch ');
mail.setPlainTextBody('hi pradeep batchapex completed');
mail.setToAddresses(toAddresses);
List<Messaging.SendEmailResult> sendRes = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }, true);
}
}
i want copy phone and fax of account whos industry is construction
but when ever we create new contact its sshowing whats problem in prgrm
You can use this class. it will work for you.
If you have any query please let me know.
If it solves your problem then mark as a best answer.
Thanks,
Arvind Kumar
All Answers
Please use this class. it will work for you.
If you have any query please let me know.
If it solves your problem then mark as a best answer.
Thanks,
Arvind Kumar
You can use this class. it will work for you.
If you have any query please let me know.
If it solves your problem then mark as a best answer.
Thanks,
Arvind Kumar