• IR_Admin IR_Salesforce
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
I need to write a schedulable apex class that will update a custom field in the OpportunityLineItem object everyday.

I have this so far:

global class UpdateOLI Implements Schedulable {

    global void execute(SchedulableContext sc) {
        updateOLI();
    }

    public void updateOLI() {

        List<OpportunityLineItem> affected = [SELECT Id, Name 
                                     FROM OpportunityLineItem
                                     WHERE position_status__c <> Closed];

       // either do your logic actually here with a Message.SingleEmailMessage here, or just fire an update
       for(OpportunityLineItem thisOLI : affected) {
           // Some dummy field to trigger the workflow (gross huh!)
           thisOLI.Apex_Schedule__c = thisOLI.Apex_Schedule__c +1;
       }

      update affected;
    }
}

But have received this error: 
Apex script unhandled exception by user/organization: 

Scheduled job 'Update OLI' threw unhandled exception.

caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.Apex_Schedule__c

Class.UpdateOLI.updateOLI: line 15, column 1
Class.UpdateOLI.execute: line 4, column 1
 
I think I have an Apex Class that will update all Opportunities at night so that the workflows will run on them on a nightly basis. 

public class updateOpportunity {
    public static void checkUpdate(Opportunity[] objects){
        for(Opportunity obj: objects){
       
        }
    }
}

I need to write a test class so that I can move this over into production. Can someone please help me?
 
I need to write a schedulable apex class that will update a custom field in the OpportunityLineItem object everyday.

I have this so far:

global class UpdateOLI Implements Schedulable {

    global void execute(SchedulableContext sc) {
        updateOLI();
    }

    public void updateOLI() {

        List<OpportunityLineItem> affected = [SELECT Id, Name 
                                     FROM OpportunityLineItem
                                     WHERE position_status__c <> Closed];

       // either do your logic actually here with a Message.SingleEmailMessage here, or just fire an update
       for(OpportunityLineItem thisOLI : affected) {
           // Some dummy field to trigger the workflow (gross huh!)
           thisOLI.Apex_Schedule__c = thisOLI.Apex_Schedule__c +1;
       }

      update affected;
    }
}

But have received this error: 
Apex script unhandled exception by user/organization: 

Scheduled job 'Update OLI' threw unhandled exception.

caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: OpportunityLineItem.Apex_Schedule__c

Class.UpdateOLI.updateOLI: line 15, column 1
Class.UpdateOLI.execute: line 4, column 1
 
I think I have an Apex Class that will update all Opportunities at night so that the workflows will run on them on a nightly basis. 

public class updateOpportunity {
    public static void checkUpdate(Opportunity[] objects){
        for(Opportunity obj: objects){
       
        }
    }
}

I need to write a test class so that I can move this over into production. Can someone please help me?