You need to sign in to do that
Don't have an account?
NKrishna
Issue on JSON.serializePretty
Hi,
I am using salesforce with java integration project.
Here I am accessing the data's from the SQL database to salesforce using the webservices and vice versa.
In that I am using JSON format webservices.
Here is the code.,
public class updateAccount {
public void UpdateExternalAccount() {
AccountClass AccountClassObj = new AccountClass();
AccountClassObj.CreateUserID = 'Krishnan';
AccountClassObj.Industry = Entitlement_Values;
AccountClassObj.UserCode = Rep;
AccountClassObj.UserRole = UserRole;
AccountClassObj.AccountID = AccountID;
string serializedOutput = JSON.serializePretty(AccountClassObj);
system.debug('system.debug '+ serializedOutput);
String jsonoutput;
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
String url='http://webservice.url.com/sf/ws/Functionname';
req.setMethod('POST');
req.setHeader('content-type', 'application/json');
req.setHeader('Accept', 'application/json');
req.setEndpoint(url);
system.debug('serializedOutput ' + serializedOutput);
req.setBody(serializedOutput);
//req.setBody('{\"createUserID\":\"Kris\",\"AccountID\":\"123456789\",\"Industry\":\"Energy, Finance\",\"UserCode\":\"abc\",\"UserRole\":\"RW\"}');
system.debug('req ' + req);
res = http.send(req);
System.debug(res.toString());
System.debug(http.toString());
//jsonoutput = res.getBody();
if(res.getStatusCode() == 200) {
jsonoutput = res.getBody();
} else {
system.debug('Could not contact web service');
jsonoutput = 'Exception : Could not contact web service';
}
system.debug('res ' + res);
system.debug('jsonoutput '+ jsonoutput);
}
public class AccountClass {
public string Industry;
public string AccountID;
public string UserCode;
public string UserRole;
public string CreateUserID;
}
}
If i am calling the above class the DB is not updated, but I am changing the code like this.,(passing the values via hard coded)
req.setEndpoint(url); //system.debug('serializedOutput ' + serializedOutput); //req.setBody(serializedOutput); req.setBody('{\"createUserID\":\"Kris\",\"AccountID\":\"123456789\",\"Industry\":\"Energy, Finance\",\"UserCode\":\"abc\",\"UserRole\":\"RW\"}'); system.debug('req ' + req);
Now the values are updated in DB.,
So the values are not updated because of JSON.serializePretty functions,
string serializedOutput = JSON.serializePretty(AccountClassObj);
How to resolve the above issue?