You need to sign in to do that
Don't have an account?
Mahesh Gorrepati
Integration from salesforce to slaesforce org:- error :-JSON_PARSER_ERROR"
ERROR:-16:20:52:632 USER_DEBUG [67]|DEBUG|[{"message":"Unexpected parameter encountered during deserialization: Amount__c at [line:1, column:15]","errorCode":"JSON_PARSER_ERROR"}]
Code:-
public class paymentfromsalesforce {
public static string apiclientid;
public static string apiclientsecrete;
public static string username;
public static string password;
public static void getAuthCreds()
{
salesforcefromsalesforce__c clientid = salesforcefromsalesforce__c.getInstance('Client ID');
salesforcefromsalesforce__c clientsecreate = salesforcefromsalesforce__c.getInstance('client secret');
salesforcefromsalesforce__c clientusername = salesforcefromsalesforce__c.getInstance('username');
salesforcefromsalesforce__c clientpassword = salesforcefromsalesforce__c.getInstance('password');
apiclientid = clientid.value__c;
apiclientsecrete =clientsecreate.value__c;
username = clientusername.value__c;
PASSWORD = clientpassword.value__c;
}
public class deserializeResponse
{
public String id {set;get;}
public String access_token {set;get;}
public string typeofpayment {set;get;}
public integer payamount {set;get;}
public string paymethod {set;get;}
}
public String ReturnAccessToken (paymentfromsalesforce acount)
{
// method used authoentication details in the system.
getAuthCreds();
String reqbody = 'grant_type=password'+'&client_id='+apiclientid+'&client_secret='+apiclientsecrete+'&username='+username+'&password='+PASSWORD;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setBody(reqbody);
req.setMethod('POST');
req.setEndpoint('https://vignesh9666-dev-ed.my.salesforce.com/services/oauth2/token');
HttpResponse res = h.send(req);
system.debug('The access token for the ' + res.getBody());
deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
system.debug('The access token for the ' + resp1.access_token);
return resp1.access_token;
}
@AuraEnabled
public static deserializeResponse createpayment(String ptype, integer pamount, String pstatus)
{
paymentfromsalesforce acount = new paymentfromsalesforce();
String accessToken = acount.ReturnAccessToken (acount);
if(accessToken != null)
{
HttpRequest req1=new HttpRequest();
req1.setEndpoint('https://vignesh9666-dev-ed.my.salesforce.com/services/apexrest/mypaymentgateway/');
req1.setMethod('POST');
req1.setHeader('Content-Type','application/json');
req1.setHeader('Accept','application/json');
req1.setHeader('Authorization','Bearer '+accessToken);
req1.setBody( '{"Amount__c":"' +pamount+ '"}');
Http http1=new Http();
HttpResponse res1=new HttpResponse();
res1=http1.send(req1);
System.debug(res1.getStatusCode());
System.debug(res1.getBody());
deserializeResponse resp2 = (deserializeResponse)JSON.deserialize(res1.getbody(),deserializeResponse.class);
system.debug('The record id is ' + resp2.id);
}
return resp2;
}
}
webservices code from another org:-
@RestResource(urlMapping='/mypaymentgateway/*')
Global class newpaymentgatewayrcord {
@HttpPost
global static id paymentrecords(string ptype, integer pamount, string pstatus)
{
Payment_Gateway__c pay = new Payment_Gateway__c();
pay.TYPE__c=ptype;
pay.Amount__c=pamount;
pay.Status__c=pstatus;
insert pay;
return pay.id;
}
}
Code:-
public class paymentfromsalesforce {
public static string apiclientid;
public static string apiclientsecrete;
public static string username;
public static string password;
public static void getAuthCreds()
{
salesforcefromsalesforce__c clientid = salesforcefromsalesforce__c.getInstance('Client ID');
salesforcefromsalesforce__c clientsecreate = salesforcefromsalesforce__c.getInstance('client secret');
salesforcefromsalesforce__c clientusername = salesforcefromsalesforce__c.getInstance('username');
salesforcefromsalesforce__c clientpassword = salesforcefromsalesforce__c.getInstance('password');
apiclientid = clientid.value__c;
apiclientsecrete =clientsecreate.value__c;
username = clientusername.value__c;
PASSWORD = clientpassword.value__c;
}
public class deserializeResponse
{
public String id {set;get;}
public String access_token {set;get;}
public string typeofpayment {set;get;}
public integer payamount {set;get;}
public string paymethod {set;get;}
}
public String ReturnAccessToken (paymentfromsalesforce acount)
{
// method used authoentication details in the system.
getAuthCreds();
String reqbody = 'grant_type=password'+'&client_id='+apiclientid+'&client_secret='+apiclientsecrete+'&username='+username+'&password='+PASSWORD;
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setBody(reqbody);
req.setMethod('POST');
req.setEndpoint('https://vignesh9666-dev-ed.my.salesforce.com/services/oauth2/token');
HttpResponse res = h.send(req);
system.debug('The access token for the ' + res.getBody());
deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
system.debug('The access token for the ' + resp1.access_token);
return resp1.access_token;
}
@AuraEnabled
public static deserializeResponse createpayment(String ptype, integer pamount, String pstatus)
{
paymentfromsalesforce acount = new paymentfromsalesforce();
String accessToken = acount.ReturnAccessToken (acount);
if(accessToken != null)
{
HttpRequest req1=new HttpRequest();
req1.setEndpoint('https://vignesh9666-dev-ed.my.salesforce.com/services/apexrest/mypaymentgateway/');
req1.setMethod('POST');
req1.setHeader('Content-Type','application/json');
req1.setHeader('Accept','application/json');
req1.setHeader('Authorization','Bearer '+accessToken);
req1.setBody( '{"Amount__c":"' +pamount+ '"}');
Http http1=new Http();
HttpResponse res1=new HttpResponse();
res1=http1.send(req1);
System.debug(res1.getStatusCode());
System.debug(res1.getBody());
deserializeResponse resp2 = (deserializeResponse)JSON.deserialize(res1.getbody(),deserializeResponse.class);
system.debug('The record id is ' + resp2.id);
}
return resp2;
}
}
webservices code from another org:-
@RestResource(urlMapping='/mypaymentgateway/*')
Global class newpaymentgatewayrcord {
@HttpPost
global static id paymentrecords(string ptype, integer pamount, string pstatus)
{
Payment_Gateway__c pay = new Payment_Gateway__c();
pay.TYPE__c=ptype;
pay.Amount__c=pamount;
pay.Status__c=pstatus;
insert pay;
return pay.id;
}
}
Query:-
→ when trying to create a record by keeping the name as the auto number in a salesforce org, by making an integration call out from another salesforce org. I am getting null for the name of the created record. Kindly help me with the query.
please click on the below link for the code
Updated solution and query regarding (https://docs.google.com/document/d/15fNTM7PEcxQIr2rNi4yeS4gOX-BAjetqByM0rwJfCE0/edit)
It sounds like the issue you are encountering is with the data type mismatch between the amount__c field (currency) and the parameter you are passing (integer). To resolve this issue, you'll need to make sure that the parameter you are passing is of the correct data type (i.e., currency) when making the integration callout. If you are using Apex code to make the callout, you can use the Decimal data type to represent currency values.
Additionally, it is possible that the error with the Name field being null is related to the record creation process. Make sure that you are properly setting a value for the Name field before making the callout, or that the Name field is set to automatically generate a value.
Here's an example of how you could set the amount__c and Name fields in Apex code:
from your Google doc
The code seems to be working correctly, however, it's missing the auto number assignment for the name of the created record. In Salesforce, you can either let the system assign an ID (Auto Number) or set it manually, but you can't set a specific format for an auto-generated ID. To resolve this issue, you can set the name field of your Payment_Gateway__c object to be a formula field that concatenates the ID of the record and other fields of your choice. This way, you will have a unique name for each record, and the auto-number assignment is handled by the platform.
QUERY:-
I am not passing the name field in the JSON body. it is a autonumber field in the another org,which generates by salesforce.
so, i am storing that name field in the wrapper class as the repsonse and i am using that response to create a record in my org.
BY making name field another as trasaction ID field in my Org. but in the response it is showing name filed is NULL.
Kindly, Help here
Thank you so much your response. it helped me so much