You need to sign in to do that
Don't have an account?
suji srinivasan
how to fetch the custom fields in rest batch apex?
I am able to fetch the standard fields in rest batch Apex. but unable to fetch the custom fields .
Thanks in advance
Thanks in advance
Can you share your code, how you were fetching standard fields?
Thanks!!
global class RecruitmentCalloutBatch implements Database.Batchable<sObject>,Database.AllowsCallouts {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SelectId,Name,OwnerId,ParentId,Technical skill__c
,Phone,Fax,Website,Type,Industry,Description,NumberOfEmployees,AnnualRevenue from Account';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> Accrecords) {
HttpRequest req = new HttpRequest();
String accquery='select+Id,Name,OwnerId,ParentId,Technical skill__c
,Phone,Fax,Website,Type,Industry,Description,NumberOfEmployees,AnnualRevenue+from+Account';
req.setEndpoint('callout:Recruitmen/services/data/v49.0/query/?q='+accquery);
req.setMethod('GET');
Http http = new Http();
HTTPResponse resp = http.send(req);
//This response will have all the data records in json structure
system.debug('Body:'+resp.getBody());
AccountDataWrapper resWrapper = (AccountDataWrapper)JSON.deserialize(resp.getBody(),AccountDataWrapper.class);
List<Account> newAccounts = new List<Account>();
for(AccountDataWrapper.Records eachRec :resWrapper.records){
Account acc = new Account();
acc.ExternalAccId__c=eachRec.Id;
acc.Name = eachRec.Name;
acc.OwnerId=eachRec.OwnerId;
acc.ParentId = eachRec.ParentId;
acc.Technical skill__c=eachRec.Technical skill__c;
acc.Phone =eachRec.Phone;
acc.Fax =eachRec.Fax ;
acc.Website =eachRec.Website;
acc.Type =eachRec.Type;
acc.Industry =eachRec.Industry;
acc.Description =eachRec.Description;
acc.NumberOfEmployees =eachRec.NumberOfEmployees;
acc.AnnualRevenue =eachRec.AnnualRevenue;
//acc.BillingAddress =eachRec.BillingAddress;
//acc.ShippingAddress =eachRec.ShippingAddress;
//acc.CreatedById =eachRec.CreatedById;
//acc.LastModifiedById =eachRec.LastModifiedById;
newAccounts.add(acc);
}
upsert newAccounts;
}
global void finish(Database.BatchableContext BC){
}
}
-------------
public class AccountDataWrapper {
public Integer totalSize;
public Boolean done;
public List<Records> records;
public class Attributes {
public String type;
public String url;
}
public class Records {
public Attributes attributes;
public String Id;
public String Name;
public String OwnerId;
public String ParentId;
public String Phone;
public String Fax ;
public String Website;
public String Type;
public String Industry;
public String Description;
public Integer NumberOfEmployees;
public Integer AnnualRevenue;
public String Technical skill__c;
}
public static AccountDataWrapper parse(String json) {
return (AccountDataWrapper) System.JSON.deserialize(json, AccountDataWrapper.class);
}
}
Thanks in advance