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
Roshan singh 21Roshan singh 21 

How to consume third party rest api in salesforce to store data in custom object

Hi, all please help me save response in a custom object.

I have written my code and able to display record in the Visualforce page from rest API endpoint.
please help me to store data in  Custom object  test__c

Wrapper class
global class Issuerwrap {
public String issuername{get;set;}
public String issuerBankdirName{get;set;}
public String ProcessorName{get;set;}
public String SubprocessorName{get;set;}
}

Controller
public class IssuerCalloutcontroller {
public List<Issuerwrap> IssuerWrapperList{get;set;}
public List<Issuerwrap> getperformcallout(){
IssuerWrapperList= new List<Issuerwrap>();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('https://************End-point *****************');
req.setMethod('GET');
res = http.send(req);
if(res.getstatusCode() == 200 && res.getbody() != null){
IssuerWrapperList=(List<Issuerwrap>)json.deserialize(res.getbody(),List<Issuerwrap>.class);
}
return IssuerWrapperList;
}
}

VF Page

<apex:page controller="IssuerCalloutcontroller" title="JSON table" readonly="true" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!performcallout}" var="wrap" width="100%">
<!--<apex:column headerValue="Select">
<apex:inputCheckbox value="{!wrap.isSelected}"/>
</apex:column>-->
<apex:column headerValue="Name" value="{!wrap.issuername}"/>
<apex:column headerValue="BankdirName" value="{!wrap.issuerBankdirName}"/>
<apex:column headerValue="ProcessorName" value="{!wrap.ProcessorName}"/>
<apex:column headerValue="SubprocessorName" value="{!wrap.SubprocessorName}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

it's very urgent please help me.
Thanks in advance
Rajesh Varma MudunuriRajesh Varma Mudunuri
Hi,
Please go through the below link this might help you.
https://opfocus.com/json-deserialization-techniques-in-salesforce/
Thanks
Roshan singh 21Roshan singh 21
how to save response( IssuerWrapperList ) in a custom object test__c 
v varaprasadv varaprasad
Hi Roshan,

Plase check once following snippet of code : 

 
public class IssuerCalloutcontroller {
public List<Issuerwrap> IssuerWrapperList{get;set;}
public static List<Issuerwrap> getperformcallout(){
IssuerWrapperList= new List<Issuerwrap>();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('https://************End-point *****************');
req.setMethod('GET');
res = http.send(req);
if(res.getstatusCode() == 200 && res.getbody() != null){
IssuerWrapperList=(List<Issuerwrap>)json.deserialize(res.getbody(),List<Issuerwrap>.class);()
saveReponce(IssuerWrapperList);
}
return IssuerWrapperList;
}
}



public static void saveReponce(list<Issuerwrap> IssuerWrapperList){
list<test__c> acclIst = new list<test__c>();
for(Issuerwrap wrp : IssuerWrapperList){
test__c  acc = new test__c ();
acc.name = wrp.issuername;
acc.phone = wrp.issuerBankdirName;
acc.rating = wrp.ProcessorName;
acc.test__c number = wrp.SubprocessorName;
  acclIst.add(acc); 

}

if(acclIst.size() > 0){
  insert acclIst;
}
}

Note: If we can specify readonly= "true" in VF. we cannot do DML operations on the controller.so please remove it.

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com

 
Roshan singh 21Roshan singh 21
Thanks,v varaprasad 

I am getting an error when I am saving this controller  " IssuerWrapperList variable is not declared"

Please help me.