• TechRemoteHub
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
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
Hi there:

I am really new to this big Salesforce world. One of the requirement for us is to create Salesforce entites remotely from our WordPress site. The only way I can think of right now is to use JavaScript.

Can anyone please tell me how to do it using REST API? I found some documentation on https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit. However I am not sure how to approach here. What values do I need to supply for var clientId , var redirectUri and var proxyUrl? Is there any other way?

Any help will be much appreciated.

Thanks
Anindya

How to capture details of any person from web and it should directly go in to account in salesforce like web-to-Lead?