function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Praetorian65Praetorian65 

Running an apex script

I have an apex script (ReadLicenses) that updates SF objects from my external db using a static Read() method. Is it possible to have a button somewhere that can activate the script or atleast schedule it to run?
mikefmikef
I am not sure when but scheduled Apex is coming, in the meantime if you want to create a button you can.

The easiest way would be to create a visualforce page with the button and have a custom controller that holds the method which the button calls.
This method would just call your static read() method.

There are how to's on the wiki, but this will get you started.

Code:
public class MyController{
   public PageReference callMe(){
      ClassName.Read();
      return null;
   }
}

Code:
<apex:page controller="MyController" showHeader="false" sidebar="false" standardStylesheets="true" >

   <apex:form >
      <apex:outputPanel id="buttons" layout="block" styleClass="buttons">
         <apex:commandButton value="Run Read" action="{!callMe}" />
      </apex:outputPanel>
   </apex:form>

</apex:page>

If you want you can report back to the page what sobjects you processed and the like.
It's up to you how you want to go about this.

Hope this points you in the right direction.