You need to sign in to do that
Don't have an account?
pavan kumar 1864
i have written a batch class but when i try to execute the error is - SObject row was retrieved via SOQL without querying the requested field: Opportunity.AccountId---showing up -please guide
public class batchjobassignment implements Database.batchable<sObject>
{
public Database.querylocator start(Database.batchablecontext bc)
{
string s= 'select id from opportunity where StageName = \'Closed Won\'';
return (Database.getquerylocator(s));
// system.debug(s);
}
public void execute(Database.batchablecontext bc,list<opportunity>opp)
{ set<id>oppid = new set<id>();
for(opportunity op : opp)
{
oppid.add(op.accountid);
}
list<account> acc = [select id, name, Latest_owner__c,(select id, OwnerId from Opportunities) from account where id in :oppid];
list<account>acountnew = new list<account>();
for(account aa : acc)
{
for(opportunity oo : aa.Opportunities){
aa.Latest_owner__c = oo.OwnerId;
acountnew.add(aa);
}
}
update acountnew;
}
public void finish(Database.batchablecontext bc){
}
}
{
public Database.querylocator start(Database.batchablecontext bc)
{
string s= 'select id from opportunity where StageName = \'Closed Won\'';
return (Database.getquerylocator(s));
// system.debug(s);
}
public void execute(Database.batchablecontext bc,list<opportunity>opp)
{ set<id>oppid = new set<id>();
for(opportunity op : opp)
{
oppid.add(op.accountid);
}
list<account> acc = [select id, name, Latest_owner__c,(select id, OwnerId from Opportunities) from account where id in :oppid];
list<account>acountnew = new list<account>();
for(account aa : acc)
{
for(opportunity oo : aa.Opportunities){
aa.Latest_owner__c = oo.OwnerId;
acountnew.add(aa);
}
}
update acountnew;
}
public void finish(Database.batchablecontext bc){
}
}
Try Below Code Added AccountId in Query Which Is In Bold Please Mark It As Best Answer If It Helps
Thank You!
All Answers
You are using oppid.add(op.accountid);
Please inculde accountId in your query as field.
Something similar
string s= 'select id,accountId from opportunity where StageName = \'Closed Won\'';
If it helps please mark it as best answer
Thank
Try Below Code Added AccountId in Query Which Is In Bold Please Mark It As Best Answer If It Helps
Thank You!
Check this code it will help you. If you find your Solution then mark this as the best answer.
Thank you!
Regards
Suraj Tripathi