You need to sign in to do that
Don't have an account?
Matt Webber 20
Batch class retrieving sObject row but not querying requested field
Hi all,
I'm working on this class mainly for my own development. There's likely to be a simpler declarative solution but I'm trying to solve the problem with code.
My error message is this:
First error: SObject row was retrieved via SOQL without querying the requested field: SBQQ__Quote__c.SBQQ__Opportunity2__r
Here's my code:
public class UpdateQuotesWithInactiveSalesUser implements Database.Batchable<sObject> {
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('SELECT SBQQ__SalesRep__c, Id FROM SBQQ__Quote__c WHERE SBQQ__SalesRep__r.IsActive = FALSE AND (SBQQ__Quote__c.SBQQ__Opportunity2__r.StageName = \'Needs Analysis\' OR SBQQ__Quote__c.SBQQ__Opportunity2__r.StageName = \'Proposal\' OR SBQQ__Quote__c.SBQQ__Opportunity2__r.StageName = \'Proposal Sent\' OR SBQQ__Quote__c.SBQQ__Opportunity2__r.StageName = \'Negotiation\')');
}
public void execute(Database.BatchableContext BC, list<SBQQ__Quote__c> quotesWithInactiveSalesRep){
//only 50000 lines can be returned from the SOQL query
//Loop through those quotes and set SalesRep to match whoever is Opportunity Owner
for(SBQQ__Quote__c quote: quotesWithInactiveSalesRep){
quote.SBQQ__SalesRep__c = quote.SBQQ__Opportunity2__r.OwnerId;
}
update quotesWithInactiveSalesRep;
}
public void finish(Database.BatchableContext BC){
//you need to update the list not the variable or the class
//Run a DML update statement, now all quote records in the list will have sales rep updated to be the same as the //opportunity owner
}
//single update and single query so should avoid governor limits
//gov limit you're most likely to hit is the maximum CPU time - that can depend how much automation you have on //the quote object because that affects the calculation
}
What I'm trying to do:
I want to update all quotes where the user in the sales rep field on quote is inactive and update that field to be whoever is the owner of the related opportunity. But only if the opportunity can be worked so only if the related opp is at the stages named in the query (not closed won or closed lost).
Currently I'm just seeing that error message in the Apex Jobs and my test quote that meets the conditions isn't being updated (and still has the inactive user in the sales rep field).
Sorry for the long message, this is my first time using this site. Thanks very much in advance for any help I can get with this.
Best wishes,
Matt
I'm working on this class mainly for my own development. There's likely to be a simpler declarative solution but I'm trying to solve the problem with code.
My error message is this:
First error: SObject row was retrieved via SOQL without querying the requested field: SBQQ__Quote__c.SBQQ__Opportunity2__r
Here's my code:
public class UpdateQuotesWithInactiveSalesUser implements Database.Batchable<sObject> {
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('SELECT SBQQ__SalesRep__c, Id FROM SBQQ__Quote__c WHERE SBQQ__SalesRep__r.IsActive = FALSE AND (SBQQ__Quote__c.SBQQ__Opportunity2__r.StageName = \'Needs Analysis\' OR SBQQ__Quote__c.SBQQ__Opportunity2__r.StageName = \'Proposal\' OR SBQQ__Quote__c.SBQQ__Opportunity2__r.StageName = \'Proposal Sent\' OR SBQQ__Quote__c.SBQQ__Opportunity2__r.StageName = \'Negotiation\')');
}
public void execute(Database.BatchableContext BC, list<SBQQ__Quote__c> quotesWithInactiveSalesRep){
//only 50000 lines can be returned from the SOQL query
//Loop through those quotes and set SalesRep to match whoever is Opportunity Owner
for(SBQQ__Quote__c quote: quotesWithInactiveSalesRep){
quote.SBQQ__SalesRep__c = quote.SBQQ__Opportunity2__r.OwnerId;
}
update quotesWithInactiveSalesRep;
}
public void finish(Database.BatchableContext BC){
//you need to update the list not the variable or the class
//Run a DML update statement, now all quote records in the list will have sales rep updated to be the same as the //opportunity owner
}
//single update and single query so should avoid governor limits
//gov limit you're most likely to hit is the maximum CPU time - that can depend how much automation you have on //the quote object because that affects the calculation
}
What I'm trying to do:
I want to update all quotes where the user in the sales rep field on quote is inactive and update that field to be whoever is the owner of the related opportunity. But only if the opportunity can be worked so only if the related opp is at the stages named in the query (not closed won or closed lost).
Currently I'm just seeing that error message in the Apex Jobs and my test quote that meets the conditions isn't being updated (and still has the inactive user in the sales rep field).
Sorry for the long message, this is my first time using this site. Thanks very much in advance for any help I can get with this.
Best wishes,
Matt
you need to add the SBQQ__Opportunity2__r.OwnerId field in the query.
Modify the retun query like below. If this helps, Please mark it as best answer.
THanks!!
All Answers
you need to add the SBQQ__Opportunity2__r.OwnerId field in the query.
Modify the retun query like below. If this helps, Please mark it as best answer.
THanks!!