0

Good day everyone. I am trying to sync my salesforce data and xero data. I want to get all xero contacts and save it to salesforce accounts. What I did is that I query the xero data by page. The problem I have at the moment is that I encounter this error. Too many callouts: 1 . I dont know what I am doing wrong but here is some part of my code.

public with sharing class BatchSyncXeroToSalesforce implements Database.batchable<XeroContact>, Database.Stateful 
{ 

  public List<XeroContact> res = new List<XeroContact>();
    public Integer PAGE {get;set;}

    public BatchSyncXeroToSalesforce(Integer thePage) {
        PAGE = thePage;
    }

  public Iterable<XeroContact> start(Database.batchableContext batchableContext) { 
        // the below code is the callout to xero where I use the page number as parameter
        res = XeroAccountingApi.getContactByPage(PAGE);
        return res;
  }

  public void execute(Database.BatchableContext batchableContext, List<XeroContact> scope)  {
    // this is where I process the data from xero
  }

  public void finish(Database.BatchableContext bc) {

    //system.debug('mJobId : '+jobID);
    if(res.size() > 0) {
      Integer x = PAGE+1;
      BatchSyncXeroToSalesforce b = new BatchSyncXeroToSalesforce(x); 
      database.executebatch(b,1);   
    }

  }

}

Please help ... thank you...

1 Answer 1

0

please add "Database.allowscallouts" on Interface.

public with sharing class BatchSyncXeroToSalesforce implements Database.batchable < XeroContact >, Database.Stateful,Database.allowscallouts {

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.