You need to sign in to do that
Don't have an account?
sumit d
error in batch :- too many callouts
hi All,
my batch is given below:-
public class BatchZendeskToSalesforce implements Database.Batchable<sObject>{
public Database.querylocator start(Database.BatchableContext BC){
string query;
query = 'SELECT Id, Name,url__c,External_Id__c,'+
'Group_Id__c,Shared_Tickets__c,'+
'Shared_Comments__c,phone,Domain_Name__c,Notes__c,'+
'Payroll_Vault__c,Zendesk_Id__c,Details__c ' +
'FROM Account ';
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<Account> Accounts){
Set<Id> accountIds = new Set<Id>();
for( Account acc : Accounts ){
accountIds.add( acc.Id );
}
getAccounts();
}
public static List<Account> getAccounts(){
HttpRequest req = new HttpRequest();
req.setMethod( 'GET' );
String username = 'kevin@sfdcconsultants.com';
String password = '45j2JpHB^qy*';
Blob headerValue = Blob.valueOf( username + ':' + password );
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode( headerValue );
req.setHeader( 'Authorization', authorizationHeader );
req.setHeader( 'Content-Type', 'application/json' );
req.setEndpoint( 'https://timerack.zendesk.com/api/v2/organizations.json' );
Http binding = new Http();
HttpResponse res = binding.send( req );
Map<String, Object> results = ( Map<String, Object> )JSON.deserializeUntyped( res.getBody() );
List<Object> lstOrganizations = ( List<Object> )results.get( 'organizations' );
List<Map<String, Object>> customerAtt = new List< Map< String, Object >>();
for ( Object customer : lstOrganizations ) {
Map<String, Object> customerAttributes = ( Map< String, Object >)customer;
customerAtt.add( customerAttributes );
}
List< Account > listAccountToUpsert = new List< Account >();
for( Map< String, Object> attMap : customerAtt ){
Account acc = new Account();
String fullName = String.valueOf( attMap.get( 'name' ));
/* if( fullName.split(' ').size() > 1 ){
ct.FirstName = fullName.substring( 0, fullName.indexOf(' ') );
ct.LastName = fullName.substring( fullName.indexOf(' ') + 1 );
}else{
ct.LastName = fullName;
}*/
//ct.email = String.valueOf( attMap.get( 'email' ));
acc.url__c = String.valueOf( attMap.get( 'url' ));
acc.External_Id__c = String.valueOf( attMap.get( 'external_id' ));
acc.Group_Id__c = String.valueOf( attMap.get( 'group_id' ));
acc.Shared_Tickets__c = Boolean.valueOf( attMap.get( 'shared_tickets' ));
acc.Shared_Comments__c = Boolean.valueOf( attMap.get( 'shared_comments' ));
acc.phone = String.valueOf( attMap.get( 'phone' ));
acc.Domain_Name__c = String.valueOf( attMap.get( 'domain_names' ));
acc.Notes__c = String.valueOf( attMap.get( 'notes' ));
acc.Payroll_Vault__c = String.valueOf(attMap.get('payroll_vault'));
acc.Zendesk_Id__c = String.valueOf( attMap.get( 'id' ));
acc.Details__c = String.valueOf(attMap.get('details'));
//ct.Zendesk_Parent_Organisation_Id__c = String.valueOf( attMap.get( 'organization_id' ));
listAccountToUpsert.add(acc);
/*if(ct.Name == 'testBC'){
System.assert(false, listAccountToUpsert);
}*/
}
return listAccountToUpsert;
}
public void finish(Database.BatchableContext BC){
}
}
when i run the batch its showing me error:- too many callouts
how to solve this error?
Any suggestions?
my batch is given below:-
public class BatchZendeskToSalesforce implements Database.Batchable<sObject>{
public Database.querylocator start(Database.BatchableContext BC){
string query;
query = 'SELECT Id, Name,url__c,External_Id__c,'+
'Group_Id__c,Shared_Tickets__c,'+
'Shared_Comments__c,phone,Domain_Name__c,Notes__c,'+
'Payroll_Vault__c,Zendesk_Id__c,Details__c ' +
'FROM Account ';
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<Account> Accounts){
Set<Id> accountIds = new Set<Id>();
for( Account acc : Accounts ){
accountIds.add( acc.Id );
}
getAccounts();
}
public static List<Account> getAccounts(){
HttpRequest req = new HttpRequest();
req.setMethod( 'GET' );
String username = 'kevin@sfdcconsultants.com';
String password = '45j2JpHB^qy*';
Blob headerValue = Blob.valueOf( username + ':' + password );
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode( headerValue );
req.setHeader( 'Authorization', authorizationHeader );
req.setHeader( 'Content-Type', 'application/json' );
req.setEndpoint( 'https://timerack.zendesk.com/api/v2/organizations.json' );
Http binding = new Http();
HttpResponse res = binding.send( req );
Map<String, Object> results = ( Map<String, Object> )JSON.deserializeUntyped( res.getBody() );
List<Object> lstOrganizations = ( List<Object> )results.get( 'organizations' );
List<Map<String, Object>> customerAtt = new List< Map< String, Object >>();
for ( Object customer : lstOrganizations ) {
Map<String, Object> customerAttributes = ( Map< String, Object >)customer;
customerAtt.add( customerAttributes );
}
List< Account > listAccountToUpsert = new List< Account >();
for( Map< String, Object> attMap : customerAtt ){
Account acc = new Account();
String fullName = String.valueOf( attMap.get( 'name' ));
/* if( fullName.split(' ').size() > 1 ){
ct.FirstName = fullName.substring( 0, fullName.indexOf(' ') );
ct.LastName = fullName.substring( fullName.indexOf(' ') + 1 );
}else{
ct.LastName = fullName;
}*/
//ct.email = String.valueOf( attMap.get( 'email' ));
acc.url__c = String.valueOf( attMap.get( 'url' ));
acc.External_Id__c = String.valueOf( attMap.get( 'external_id' ));
acc.Group_Id__c = String.valueOf( attMap.get( 'group_id' ));
acc.Shared_Tickets__c = Boolean.valueOf( attMap.get( 'shared_tickets' ));
acc.Shared_Comments__c = Boolean.valueOf( attMap.get( 'shared_comments' ));
acc.phone = String.valueOf( attMap.get( 'phone' ));
acc.Domain_Name__c = String.valueOf( attMap.get( 'domain_names' ));
acc.Notes__c = String.valueOf( attMap.get( 'notes' ));
acc.Payroll_Vault__c = String.valueOf(attMap.get('payroll_vault'));
acc.Zendesk_Id__c = String.valueOf( attMap.get( 'id' ));
acc.Details__c = String.valueOf(attMap.get('details'));
//ct.Zendesk_Parent_Organisation_Id__c = String.valueOf( attMap.get( 'organization_id' ));
listAccountToUpsert.add(acc);
/*if(ct.Name == 'testBC'){
System.assert(false, listAccountToUpsert);
}*/
}
return listAccountToUpsert;
}
public void finish(Database.BatchableContext BC){
}
}
when i run the batch its showing me error:- too many callouts
how to solve this error?
Any suggestions?
i have change the batch but it didnt create the zendesk Account on salesforce?
batch is given below:-
public class BatchZendeskToSalesforce implements Database.Batchable<sObject>,Database.AllowsCallouts, Database.Stateful{
public Database.querylocator start(Database.BatchableContext BC){
string query;
query = 'SELECT Id, Name,url__c,External_Id__c,'+
'Group_Id__c,Shared_Tickets__c,'+
'Shared_Comments__c,phone,Domain_Name__c,Notes__c,'+
'Payroll_Vault__c,Zendesk_Id__c,Details__c ' +
'FROM Account ';
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<Account> Accounts){
Set<Id> accountIds = new Set<Id>();
for( Account acc : Accounts ){
accountIds.add( acc.Id );
}
getAccounts();
}
public static List<Account> getAccounts(){
HttpRequest req = new HttpRequest();
req.setMethod( 'GET' );
String username = 'kevin@sfdcconsultants.com';
String password = '45j2JpHB^qy*';
Blob headerValue = Blob.valueOf( username + ':' + password );
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode( headerValue );
req.setHeader( 'Authorization', authorizationHeader );
req.setHeader( 'Content-Type', 'application/json' );
req.setEndpoint( 'https://timerack.zendesk.com/api/v2/organizations.json' );
Http binding = new Http();
HttpResponse res = binding.send( req );
Map<String, Object> results = ( Map<String, Object> )JSON.deserializeUntyped( res.getBody() );
List<Object> lstOrganizations = ( List<Object> )results.get( 'organizations' );
List<Map<String, Object>> customerAtt = new List< Map< String, Object >>();
for ( Object customer : lstOrganizations ) {
Map<String, Object> customerAttributes = ( Map< String, Object >)customer;
customerAtt.add( customerAttributes );
}
List< Account > listAccountToUpsert = new List< Account >();
for( Map< String, Object> attMap : customerAtt ){
Account acc = new Account();
String fullName = String.valueOf( attMap.get( 'name' ));
/* if( fullName.split(' ').size() > 1 ){
ct.FirstName = fullName.substring( 0, fullName.indexOf(' ') );
ct.LastName = fullName.substring( fullName.indexOf(' ') + 1 );
}else{
ct.LastName = fullName;
}*/
//ct.email = String.valueOf( attMap.get( 'email' ));
acc.url__c = String.valueOf( attMap.get( 'url' ));
acc.External_Id__c = String.valueOf( attMap.get( 'external_id' ));
acc.Group_Id__c = String.valueOf( attMap.get( 'group_id' ));
acc.Shared_Tickets__c = Boolean.valueOf( attMap.get( 'shared_tickets' ));
acc.Shared_Comments__c = Boolean.valueOf( attMap.get( 'shared_comments' ));
acc.phone = String.valueOf( attMap.get( 'phone' ));
acc.Domain_Name__c = String.valueOf( attMap.get( 'domain_names' ));
acc.Notes__c = String.valueOf( attMap.get( 'notes' ));
acc.Payroll_Vault__c = String.valueOf(attMap.get('payroll_vault'));
acc.Zendesk_Id__c = String.valueOf( attMap.get( 'id' ));
acc.Details__c = String.valueOf(attMap.get('details'));
//ct.Zendesk_Parent_Organisation_Id__c = String.valueOf( attMap.get( 'organization_id' ));
listAccountToUpsert.add(acc);
/*if(ct.Name == 'testBC'){
System.assert(false, listAccountToUpsert);
}*/
}
return listAccountToUpsert;
}
public void finish(Database.BatchableContext BC){
}
}
Any suggestions ?
how to solve it?
If you are scheduling the batch or calling from Apex, please specify the batch size as shown below.
Thanks,
Suresh Beniwal