You need to sign in to do that
Don't have an account?
ankitha varra
[{"message":"Missing request content","errorCode":"MISSING_ARGUMENT"}] in rest api
I want to connect two salesforce organizations, while connecting am getting the above error <apex:page standardcontroller="account" extensions="workbench" > <apex:form > <apex:pageBlock > <apex:pageblocksection title="workbench insert"> <apex:inputfield value="{!acc.Name}"/> <apex:outputtext > {!jsondata}</apex:outputtext> <apex:commandbutton value="Post" action="{!getrecords}"/> </apex:pageblocksection> </apex:pageBlock> </apex:form> </apex:page>
public class workbench { public workbench(ApexPages.StandardController controller) { } public list<account> table{get;set;} public string jsondata {get;set;} public string res1 {get;set;} public account acc{get;set;} public pagereference getrecords(){ Http h = new Http(); account acc= new account(); list<account> acclist= new list<account>(); String reqbody='grant_type=password&client_id=3MVG9ZL0ppGP5UrC3Dw9S2gx8uugsVTSNUl5gXKlKaMM58wdzzuFgcEKkK.t4AJEHVlicDe7UhkvK7JMxmLlz&client_secret=2477145618947115896&username=satishmylaproject@sfdc.com&password=anuradha1234'; HttpRequest req = new HttpRequest(); req.setBody(reqbody); req.setEndpoint('https://login.salesforce.com/services/oauth2/token'); req.setHeader('Content-Type','application/x-www-form-urlencoded'); req.setMethod('POST'); HttpResponse res = h.send(req); System.debug('Response for retrieving access token=='+res.getBody()); res1=res.getbody(); Oauth2 oauth=(Oauth2)JSON.deserialize(res.getbody(),OAuth2.class); HttpRequest req2 = new HttpRequest(); req2.setHeader('Authorization','Bearer '+oauth.access_token); req2.setHeader('Content-Type','application/json; charset=UTF-8'); req2.setHeader('Accept','application/json'); String body = JSON.Serialize(acc); req2.setBody(body); req2.setEndpoint('https://ap2.salesforce.com/services/apexrest/accountinsert/*'); req2.setMethod('POST'); Http h2 = new Http(); HttpResponse res2 = h2.send(req2); jsonData = res2.getBody(); return null; } //WrapperClass for OAuth public class OAuth2{ public String id{get;set;} public String issued_at{get;set;} public String instance_url{get;set;} public String signature{get;set;} public String access_token{get;set;} } }
@RestResource(urlMapping='/accountinsert/*') global class insertionaccount{ @HttpPost global static void insertaccount(String aname) { account a = new account(); a.name=aname; insert a; } }