• Michael Villegas
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
Hello!

Any time I attempt to schedule the following Apex Class on any frequency via either UI or Dev Console, it'll run once and then be removed from the Scheduled Jobs. 

global class CompositeProjectImportScheduler implements Schedulable
{
  global void execute(SchedulableContext sc) 
  {
      Set<Id> setApexClassId = new Set<Id>();
        for(ApexClass apexClassDetails : [Select Id, Name from ApexClass 
          where Name = 'BatchCompositeProjectProcessor'])
        {
          setApexClassId.add(apexClassDetails.id);
        }
        
        List<AsyncApexJob> lstJobs = [Select Id, Status, ApexClassID
        from AsyncApexJob where 
        (Status = 'Queued' OR Status = 'Processing' OR
         Status = 'Preparing') and ApexClassID IN: setApexClassId];

      // Make sure there are no current batch jobs running
        //
        if(lstJobs == null || lstJobs.size() == 0)
      {
            // Start the EO CP import processor batch job which will process any records 
            // that are 'readyforprocessing'.
            //
        eo2.BatchCompositeProjectProcessor BCP = new eo2.BatchCompositeProjectProcessor();
          Database.executeBatch(BCP,1);
      }
      else
      {
        system.debug('CP import batch job already in progress, please wait for the current batch job to complete.');
      }
        
        // Clean up the current scheduled job so that another can be started again later.
        //
        system.abortJob(sc.getTriggerID());
  }
    
    // Call this from your trigger to create a scheduled job which will start the CP import 
    // processor batch job
    //
    public static void scheduleProcessing()
    {
        ApexClass apexClassDetails = [Select Id, Name from ApexClass
            where Name = 'CompositeProjectImportScheduler'];

        List<AsyncApexJob> lstJobs = [Select Id, Status, ApexClassID
            from AsyncApexJob where
            (Status = 'Queued' OR Status = 'Processing' OR
             Status = 'Preparing' OR Status = '') and ApexClassID =: apexClassDetails.Id];

        // Make sure there isn't already a scheduled job.  Salesforce will only allow one 
        // scheduled job for a given class so this ensures that only one batch job is 
        // started.
        //
        if(lstJobs.size() == 0)
        {
            // Schedule job to execute one minute in the future
            //
            Datetime schedulerTime = Datetime.now().addMinutes(1);
            String strScheduleTime = '0 ' + schedulerTime.minute() + ' ' +
                schedulerTime.hour() + ' ' + schedulerTime.day() + ' '+
                schedulerTime.month() + ' ? '+ schedulerTime.year();

            CompositeProjectImportScheduler scheduler = new CompositeProjectImportScheduler();
            System.schedule('Process CP records', strScheduleTime, scheduler);
        }
        else
        {
            System.debug('CP import scheduled job already pending.');
        }
    }
    
}


My Dev Console attempts
------------------------------------------------------------------------------------
first attempt
------------------------------------------------------------------------------------

System.schedule('HourlyRun', '0 0 * * * ?', new CompositeProjectImportScheduler() );

------------------------------------------------------------------------------------
second attempt
------------------------------------------------------------------------------------
CompositeProjectImportScheduler reminder = new CompositeProjectImportScheduler();
String sch = '0 0 * * * ?';
String jobID = System.schedule('HourlyRun2', sch, reminder);


Any advice would be most appreciated!

Thanks!


Michael
Hello!

Attempting a script that allows the user to pick values freely with the exception of 3 values. If the users selects any of the 3 defined values, restrict the user from make any further revisions to the picklist. 

Below is my current attempt, this works to keep the user from selecting the 3 defined values per their user role, however I'm trying to allow them to select the value but then "lock" the value once it has been selected. Does this scenerio sound feasible via validation rule? 

AND((CONTAINS($UserRole.Name,'Contractor')), 
OR(ISPICKVAL(eo2__Project_Status__c, 'Work Complete') 
,ISPICKVAL(eo2__Project_Status__c, 'Batched') 
,ISPICKVAL(eo2__Project_Status__c, 'Incentive Authorized') 
))

Any help would be appreciated!

Thanks!

Michael
Hello!

Attempting a script that allows the user to pick values freely with the exception of 3 values. If the users selects any of the 3 defined values, restrict the user from make any further revisions to the picklist. 

Below is my current attempt, this works to keep the user from selecting the 3 defined values per their user role, however I'm trying to allow them to select the value but then "lock" the value once it has been selected. Does this scenerio sound feasible via validation rule? 

AND((CONTAINS($UserRole.Name,'Contractor')), 
OR(ISPICKVAL(eo2__Project_Status__c, 'Work Complete') 
,ISPICKVAL(eo2__Project_Status__c, 'Batched') 
,ISPICKVAL(eo2__Project_Status__c, 'Incentive Authorized') 
))

Any help would be appreciated!

Thanks!

Michael
Hello!

Any time I attempt to schedule the following Apex Class on any frequency via either UI or Dev Console, it'll run once and then be removed from the Scheduled Jobs. 

global class CompositeProjectImportScheduler implements Schedulable
{
  global void execute(SchedulableContext sc) 
  {
      Set<Id> setApexClassId = new Set<Id>();
        for(ApexClass apexClassDetails : [Select Id, Name from ApexClass 
          where Name = 'BatchCompositeProjectProcessor'])
        {
          setApexClassId.add(apexClassDetails.id);
        }
        
        List<AsyncApexJob> lstJobs = [Select Id, Status, ApexClassID
        from AsyncApexJob where 
        (Status = 'Queued' OR Status = 'Processing' OR
         Status = 'Preparing') and ApexClassID IN: setApexClassId];

      // Make sure there are no current batch jobs running
        //
        if(lstJobs == null || lstJobs.size() == 0)
      {
            // Start the EO CP import processor batch job which will process any records 
            // that are 'readyforprocessing'.
            //
        eo2.BatchCompositeProjectProcessor BCP = new eo2.BatchCompositeProjectProcessor();
          Database.executeBatch(BCP,1);
      }
      else
      {
        system.debug('CP import batch job already in progress, please wait for the current batch job to complete.');
      }
        
        // Clean up the current scheduled job so that another can be started again later.
        //
        system.abortJob(sc.getTriggerID());
  }
    
    // Call this from your trigger to create a scheduled job which will start the CP import 
    // processor batch job
    //
    public static void scheduleProcessing()
    {
        ApexClass apexClassDetails = [Select Id, Name from ApexClass
            where Name = 'CompositeProjectImportScheduler'];

        List<AsyncApexJob> lstJobs = [Select Id, Status, ApexClassID
            from AsyncApexJob where
            (Status = 'Queued' OR Status = 'Processing' OR
             Status = 'Preparing' OR Status = '') and ApexClassID =: apexClassDetails.Id];

        // Make sure there isn't already a scheduled job.  Salesforce will only allow one 
        // scheduled job for a given class so this ensures that only one batch job is 
        // started.
        //
        if(lstJobs.size() == 0)
        {
            // Schedule job to execute one minute in the future
            //
            Datetime schedulerTime = Datetime.now().addMinutes(1);
            String strScheduleTime = '0 ' + schedulerTime.minute() + ' ' +
                schedulerTime.hour() + ' ' + schedulerTime.day() + ' '+
                schedulerTime.month() + ' ? '+ schedulerTime.year();

            CompositeProjectImportScheduler scheduler = new CompositeProjectImportScheduler();
            System.schedule('Process CP records', strScheduleTime, scheduler);
        }
        else
        {
            System.debug('CP import scheduled job already pending.');
        }
    }
    
}


My Dev Console attempts
------------------------------------------------------------------------------------
first attempt
------------------------------------------------------------------------------------

System.schedule('HourlyRun', '0 0 * * * ?', new CompositeProjectImportScheduler() );

------------------------------------------------------------------------------------
second attempt
------------------------------------------------------------------------------------
CompositeProjectImportScheduler reminder = new CompositeProjectImportScheduler();
String sch = '0 0 * * * ?';
String jobID = System.schedule('HourlyRun2', sch, reminder);


Any advice would be most appreciated!

Thanks!


Michael
Hello!

Attempting a script that allows the user to pick values freely with the exception of 3 values. If the users selects any of the 3 defined values, restrict the user from make any further revisions to the picklist. 

Below is my current attempt, this works to keep the user from selecting the 3 defined values per their user role, however I'm trying to allow them to select the value but then "lock" the value once it has been selected. Does this scenerio sound feasible via validation rule? 

AND((CONTAINS($UserRole.Name,'Contractor')), 
OR(ISPICKVAL(eo2__Project_Status__c, 'Work Complete') 
,ISPICKVAL(eo2__Project_Status__c, 'Batched') 
,ISPICKVAL(eo2__Project_Status__c, 'Incentive Authorized') 
))

Any help would be appreciated!

Thanks!

Michael