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
Hariom kankerwal 7Hariom kankerwal 7 

Class Update_Currency must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>) and global methods do not support parameter type of List<Opportunity>

Hi All
I keep getting the following compile error: Class Update_Currency must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)
and global methods do not support parameter type of List<Opportunity>

FYI, here is my class code
global class Update_Currency implements Database.Batchable<Sobject>{
        global String apiKey;
    global Update_Currency(string apiKey){
        this.apiKey=apiKey;
    }   
      global Database.QueryLocator start(Database.BatchableContext bc){
       String query = 'select Id, Amount, INRValue__c from Opportunity';
       return Database.getQueryLocator(query);
      }
        global void execute(Database.BatchableContext bc, List<Opportunity> optyList){
        Http p = new Http();
        HttpREquest request = new HttpRequest();
        string endPoint = 'http://api.currencylayer.com/live';
        endPoint=endpoint+'access_key='+apiKey;
        endPoint=endPoint+'&currencies=INR&source=USD&format=1';
        request.setEndpoint(endpoint);
        request.setMethod('GET');
        HttpREsponse responce = p.send(request);
        String jsonString= response.getBody();
        System.JSONParser jp=JSON.createParser(jsonString);
        Decimal inrValue;
        while(jp.getText()!=null){
            if(jp.getText()=='USDINR'){
                jp.nextToken();
                inrValue=(Decimal)jp.getDecimalValue();
            }
        }
        for(Opporttunity op:optyList){
            op.INRValue__c = 'Rs'+(op.amount*inrValue);
        }
            update optyList;}
    global void finish(Database.BatchableContext bc){
        AsyncApexJob job =[select id,Status from AsyncApexjJob where Id =:bc.getJobId()];
        Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
        string[] toadd=new string []{'hariom.sfdc@gmail.com'};
        msg.setToAddresses(toAdd);
        msg.setSubject('Intergration First Programm');
        msg.setPlainTextBody('Batch operation Processed :'+job.status);
        Messaging.Email[] emails = new Messaging.Email[]{msg};
        Messaging.sendEmail(emails);    
    }               

}


Please assist. Thanks

 
GovindarajGovindaraj
Hi Hariom,

Remember to mention Allowcallouts=true on batch context then you can do callout in batch job
global class  BatchName implements Database.Batchable<sObject>, Database.AllowsCallouts {

}
Please let us know if this helps

Thanks,
Govindaraj.S
Hariom kankerwal 7Hariom kankerwal 7
Hi Govindaraj,
Code updated . while executing thru anonymous window 

String apiKey ='5d35e4d851ea10c97a4621db93d9bc32';
Update_Currency op = new Update_Currency(apikey);
Database.executeBatch(op,5);
i am getting below error.

Line: 2, Column: 27
Constructor not defined: [Opty_Currency_Update].<Constructor>(String)
Please assist.Thanks