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
suji srinivasansuji 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
AnkaiahAnkaiah (Salesforce Developers) 
Hi Suji,

Can you share your code, how you were fetching standard fields?

Thanks!!
suji srinivasansuji srinivasan
Hi Ankaiah, I am able to fetch the standard fields data from one to another org through named credential. but unable to fetch custom field Technical skill__c. In standard fields i need  your suggestion to fetch parent id , ownerid values from one org to another org.

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