You need to sign in to do that
Don't have an account?

i am not able to post my all records from custom object to thrid party api please help
This class is working fine it feteches data from Opportunity_Prod_Batch_Record__c (custom object ) and stored the records in third party api but in my custom object having lost of records but when i run this class manually then it is taking randamly only one record i need all the records to post in third party api how can i achive this please help..............
public class Flr_Insert_Records {
Public static void Insert_Records(){
/* Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPData');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
//request.setHeader('Content-Type','multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
//request.setHeader('Authorization','Bearer '+ AuthorizationToken);*/
List<Opportunity_Prod_Batch_Record__c> oppbatch=[select Edition_Name__c,Opportunity_Id__c,Opportunity_Name__c,Opportunity_Stage__c,Stand_No__c,Banner_name__c
from Opportunity_Prod_Batch_Record__c ];
system.debug('oppbatch List query '+oppbatch);
// system.debug('Query after serialization '+json.serialize(oppbatch));
OppWrapper oppwrappervar=new OppWrapper(oppbatch[0].Edition_Name__c,oppbatch[0].Opportunity_Id__c,oppbatch[0].Opportunity_Name__c,
oppbatch[0].Opportunity_Stage__c,oppbatch[0].Stand_No__c,oppbatch[0].Banner_name__c);
string jsonbody=Json.serialize(oppwrappervar);
system.debug('Json body---->'+jsonbody);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPD');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
//request.setHeader('Content-Type','multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
//request.setHeader('Authorization','Bearer '+ AuthorizationToken);
//request.setBody('[{ "RecordId": "456","RecordName": "moosa traders pvt ltd / The Big 5 Construct Egypt 2018 / / 093061123", "EventName": "a2JD0000001ns6uMAA U", "RecordStage": "Test Stage Amjad","BannerName": "Test Banner Amjad","StandNo": "Test Stand Amjad"}]');
request.setBody('['+jsonbody+']');
HttpResponse response = http.send(request);
system.debug('Response body '+ response.getBody());
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
public class OppWrapper
{
public String EventName {get;set;}
public String RecordId {get;set;}
public String RecordName {get;set;}
public String RecordStage {get;set;}
public String StandNo {get;set;}
public String BannerName {get;set;}
public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String StandNo,String BannerName)
{
this.EventName =EventName;
this.RecordId =RecordId;
this.RecordName =RecordName;
this.RecordStage=RecordStage;
this.StandNo=StandNo;
this.BannerName=BannerName;
}
}
}
ex:- in my custom object having 8 records but when i run the class it is posting only one recrod so plesse help to post all records in third party api need urgent........
public class Flr_Insert_Records {
Public static void Insert_Records(){
/* Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPData');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
//request.setHeader('Content-Type','multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
//request.setHeader('Authorization','Bearer '+ AuthorizationToken);*/
List<Opportunity_Prod_Batch_Record__c> oppbatch=[select Edition_Name__c,Opportunity_Id__c,Opportunity_Name__c,Opportunity_Stage__c,Stand_No__c,Banner_name__c
from Opportunity_Prod_Batch_Record__c ];
system.debug('oppbatch List query '+oppbatch);
// system.debug('Query after serialization '+json.serialize(oppbatch));
OppWrapper oppwrappervar=new OppWrapper(oppbatch[0].Edition_Name__c,oppbatch[0].Opportunity_Id__c,oppbatch[0].Opportunity_Name__c,
oppbatch[0].Opportunity_Stage__c,oppbatch[0].Stand_No__c,oppbatch[0].Banner_name__c);
string jsonbody=Json.serialize(oppwrappervar);
system.debug('Json body---->'+jsonbody);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPD');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
//request.setHeader('Content-Type','multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
//request.setHeader('Authorization','Bearer '+ AuthorizationToken);
//request.setBody('[{ "RecordId": "456","RecordName": "moosa traders pvt ltd / The Big 5 Construct Egypt 2018 / / 093061123", "EventName": "a2JD0000001ns6uMAA U", "RecordStage": "Test Stage Amjad","BannerName": "Test Banner Amjad","StandNo": "Test Stand Amjad"}]');
request.setBody('['+jsonbody+']');
HttpResponse response = http.send(request);
system.debug('Response body '+ response.getBody());
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
public class OppWrapper
{
public String EventName {get;set;}
public String RecordId {get;set;}
public String RecordName {get;set;}
public String RecordStage {get;set;}
public String StandNo {get;set;}
public String BannerName {get;set;}
public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String StandNo,String BannerName)
{
this.EventName =EventName;
this.RecordId =RecordId;
this.RecordName =RecordName;
this.RecordStage=RecordStage;
this.StandNo=StandNo;
this.BannerName=BannerName;
}
}
}
ex:- in my custom object having 8 records but when i run the class it is posting only one recrod so plesse help to post all records in third party api need urgent........
Thanks
All Answers
Thanks
see this screen shot records are not posted in api why so?
But your records are getting created on the third party API as 200 status code is returning. To check if the records are created in the third party use 'GET' method to retrieve those records and response body not POST.
Hope it helps, if it does, mark it as solved.
Thanks
public class Flr_Insert_Records {
Public static void Insert_Records(){
/* Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPData');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
//request.setHeader('Content-Type','multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
//request.setHeader('Authorization','Bearer '+ AuthorizationToken);*/
List<Opportunity_Prod_Batch_Record__c> oppbatch=[select Edition_Name__c,Opportunity_Id__c,Opportunity_Name__c,Opportunity_Stage__c,Stand_No__c,Banner_name__c
from Opportunity_Prod_Batch_Record__c ];
system.debug('oppbatch List query '+oppbatch);
// system.debug('Query after serialization '+json.serialize(oppbatch));
/*OppWrapper oppwrappervar=new OppWrapper(oppbatch[0].Edition_Name__c,oppbatch[0].Opportunity_Id__c,oppbatch[0].Opportunity_Name__c,
oppbatch[0].Opportunity_Stage__c,oppbatch[0].Stand_No__c,oppbatch[0].Banner_name__c);
string jsonbody=Json.serialize(oppwrappervar);*/
// Right code
List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
for(Opportunity_Prod_Batch_Record__c oppbtch : oppbatch) {
OppWrapper oppwrappervar=new OppWrapper(oppbtch.Edition_Name__c,oppbtch.Opportunity_Id__c,oppbtch.Opportunity_Name__c,oppbtch.Opportunity_Stage__c,oppbtch.Stand_No__c,oppbtch.Banner_name__c);
oppWrapperVarList.add(oppwrappervar);
}
string jsonbody=Json.serialize(oppWrapperVarList);
system.debug('Json body---->'+jsonbody);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FP');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
//request.setHeader('Content-Type','multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
//request.setHeader('Authorization','Bearer '+ AuthorizationToken);
//request.setBody('[{ "RecordId": "456","RecordName": "moosa traders pvt ltd / The Big 5 Construct Egypt 2018 / / 093061123", "EventName": "a2JD0000001ns6uMAA U", "RecordStage": "Test Stage Amjad","BannerName": "Test Banner Amjad","StandNo": "Test Stand Amjad"}]');
request.setBody('['+jsonbody+']');
HttpResponse response = http.send(request);
system.debug('Response body '+ response.getBody());
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
public class OppWrapper
{
public String EventName {get;set;}
public String RecordId {get;set;}
public String RecordName {get;set;}
public String RecordStage {get;set;}
public String StandNo {get;set;}
public String BannerName {get;set;}
public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String StandNo,String BannerName)
{
this.EventName =EventName;
this.RecordId =RecordId;
this.RecordName =RecordName;
this.RecordStage=RecordStage;
this.StandNo=StandNo;
this.BannerName=BannerName;
}
}
}
after added your code in my http callout class please chek this where did i miss something?
yes finally it is working but now i need to do one thing what if record alredy exists
see this
If that's the case, then you may have to use GET method to retrieve those records and compare it with your org records and filter those records.
ohhh ok can you please help me on that as i am started learing and working on intergation part so i need your help too to achive the my last requirment..
yes based we are storeing opp line item records in Opportunity_Prod_Batch_Record__c Object and we also stored OPP id in Opportunity_Prod_Batch_Record__c Object and now as a record id we are posting opp id in third party api
@Meghna Vijay 7
please help me i am stuck on it
public class MyApiPostClass {
Public static void Insert_Records(){
List<Opportunity_Prod_Batch_Record__c> oppbatch=[select Edition_Name__c,Opportunity_Id__c,Opportunity_Name__c,Opportunity_Stage__c,Stand_No__c,Banner_name__c
from Opportunity_Prod_Batch_Record__c ];
system.debug('oppbatch List query '+oppbatch);
// Right code
List<OppWrapper> oppWrapperVarList = new List<OppWrapper>();
for(Opportunity_Prod_Batch_Record__c oppbtch : oppbatch) {
OppWrapper oppwrappervar=new OppWrapper(oppbtch.Edition_Name__c,oppbtch.Opportunity_Id__c,oppbtch.Opportunity_Name__c,oppbtch.Opportunity_Stage__c,oppbtch.Stand_No__c,oppbtch.Banner_name__c);
oppWrapperVarList.add(oppwrappervar);
}
string jsonbody=Json.serialize(oppWrapperVarList);
system.debug('Json body---->'+jsonbody);
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('http://fpdatamap.salesforceoutsourcing.in/api/FPDatas');
request.setMethod('POST');
request.setHeader('Content-Type','application/json');
HttpResponse response = http.send(request);
system.debug('Response body '+ response.getBody());
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
public class OppWrapper
{
public String EventName {get;set;}
public String RecordId {get;set;}
public String RecordName {get;set;}
public String RecordStage {get;set;}
public String StandNo {get;set;}
public String BannerName {get;set;}
public OppWrapper(String EventName,String RecordId,String RecordName,String RecordStage,String StandNo,String BannerName)
{
this.EventName =EventName;
this.RecordId =RecordId;
this.RecordName =RecordName;
this.RecordStage=RecordStage;
this.StandNo=StandNo;
this.BannerName=BannerName;
}
}
}
can you please add your code in my class as i am confused didnt understand where did i need to post this new code provided by can you please add this the last thing please..
There may be some errors in the syntax . If yes, please see this documentation :-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_httprequest.htm
i will chehk and let you know after running sucessfully nice to meet you thanks a lot once agian
Error:-
Line: 32, Column: 1
System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set