You need to sign in to do that
Don't have an account?
i am having this HTTP Callout class it working fine and Post the all the records but when records alrady exists throghs an error
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/FPDatas');
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;
}
}
}
it is working fine just i need to do whnerver records existis then it will skeep that record and post remaning records how to achive that please help me..................
Can you try that callout with PUT method.
Like : request.setMethod('PUT');
Thanks,
Govindaraj.S
@Govindaraj thanks for the qucik response please help me...
no i am not tried can you add in my code what you want to add as i am new learner on integration so i just stuck on it can you please add in my code
@Govindaraj thanks now it is not throwing error in response body (record already exisits)
now one more thing in my custom object i havine 1084 records
see this screen shot now in my custom object having haing 1087 records but it is not posting the records in third party api can you please chehk this...............
thanks for the reply i solved this taking help from web team i mean third party genrating team....
now i m having last thing can you please help me................