You need to sign in to do that
Don't have an account?
nilesh walke
hey guys i am new in apex batch class . now i want to create a account record and hence 1 contact record must be create using batch apex
Here my code i want code in minimum lines
public class Demo3 implements Database.Batchable<SObject> {
public Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator('Select id, name, phone, (select id, name,phone from contacts)from account');
}
public void execute(Database.BatchableContext BC,List<Account> Acclist){
set<id> AccIds = New set<id>();
for(Account Acc:Acclist){
AccIds.add(Acc.id);
}
map<Id,Account> Acct = new map<id,Account>(Acclist);
for(Account AC:Acclist){
if(Acct.get(AC.id).Contacts.size()>0){
AC.adderror('ERROR');
}
}
}
public void finish(Database.BatchableContext BC){
}
public class Demo3 implements Database.Batchable<SObject> {
public Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator('Select id, name, phone, (select id, name,phone from contacts)from account');
}
public void execute(Database.BatchableContext BC,List<Account> Acclist){
set<id> AccIds = New set<id>();
for(Account Acc:Acclist){
AccIds.add(Acc.id);
}
map<Id,Account> Acct = new map<id,Account>(Acclist);
for(Account AC:Acclist){
if(Acct.get(AC.id).Contacts.size()>0){
AC.adderror('ERROR');
}
}
}
public void finish(Database.BatchableContext BC){
}
You can take reference from this below code.
Batch Trigger:- Batch Apex In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.
Thanks and Regards
Suraj Tripathi.