+ Start a Discussion
sushanth s 2sushanth s 2 

guide me to develop a Batch job?


      i have developed a apex class for connecting with the third party but now i'm going to write a batch job on that anyone guide me to developa batch job.i have look into some examples but completely not understood.

this is my class :

global with sharing class Service {
    global static void getIncident(String subject){  
        Http http = new Http();
        HttpRequest req =  new HttpRequest();
        HttpResponse res = new HttpResponse();
        string text = subject;
        req.setHeader('Content-Type', 'application/json');
        String username = 'admin';
        String password = 'xxxxxx';
        Blob headerValue = Blob.valueOf(username + ':' + password);
        String authorizationHeader = 'BASIC ' +
        req.setHeader('Authorization', authorizationHeader);
        res = http.send(req);
        System.debug('jsonrResult :' + res.getBody());
        Deserialization.ResponseResult result = (Deserialization.ResponseResult)JSON.deserialize(res.getBody(),     Deserialization.ResponseResult.class);
        System.debug('Results == :' + result );
        List<Case> casesToUpsert = new List<Case>();        
        for(Deserialization d : theresult.result ){
                Case c = new Case();
                c.Priority = d.impact;
                c.Status = d.incident_state;
                c.Subject = d.short_description;
                c.ServiceNowId__c = d.sys_id;
                c.Origin = d.contact_type;
        system.debug('Cases to UPsert ::: ' +casesToUpsert);
            Database.upsert(casesToUpsert,false) ;

if it is possible develop batch job on that for better understanding

Thanks In Advance
Neha Patil 20Neha Patil 20
Hi Sushanth,

You can simply try to schedule this apex class with the help of an another apex class by implementing the schedulable interface something like this:
global class scheduledBatchable implements Schedulable {
   global void execute(SchedulableContext sc) {
      Service b = new Service(); 
Further you can go to setup-->Apex classes --> click on button--> schedule apex and this will allow you to schedule and execute you batch as and when needed

Let me know if this helps and mark it as best answer if this resolves your query