You need to sign in to do that
Don't have an account?
sarvesh001
Rest in apex
Hi ,
I have created a simple REST API in Apex through Your Name | Setup | Develop | Apex Classes | New
how to get cURL for this.
thanks,
sarvesh.
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Hi ,
I have created a simple REST API in Apex through Your Name | Setup | Develop | Apex Classes | New
how to get cURL for this.
thanks,
sarvesh.
Hi Servesh,
you can call like that..
String url = 'https://ap1.salesforce.com/services/apexrest/GetService';
All Answers
Hi,
which method you are using get or post
for get u use like this.
@RestResource(urlMapping='/test/*')
global with sharing class testEndPoint{
@HttpGet
global static string doGet(){
return 'Swell';
}
}
for get u use like that and pass it like that
req.setEndpoint(instanceUrl+'/services/apexrest/test');
and post
@RestResource(urlMapping='/OneToAnother/*')
global class SalesforceAcc
{
public SalesforceAcc(){}
@HttpPost
global static string doPost(){
string jsonData = RestContext.request.requestBody.tostring();
//jsonData = jsonData.replace('"{','{').replace('}"','}').replace('"[','[').replace(']"',']').replace('\\','');
jsonData = jsonData.replace('Account','Account_c');
System.debug(' :: string::'+jsonData);
//getting the JSON and deserializing according the class structure
Account_c reqData = (Account_c)JSON.deserialize(jsonData, Account_c.class);
System.debug(' :: JSON :: '+ reqdata );
return reqdata.Id;
}
public class Account_c
{
string Id {get; set;}
string Name {get; set;}
}
}
Hi Sunil,
thanks for replay and my code is below
My target org code:
My target org code:
for the above code how to get url to add to remotesite settings
i mean if our target code and source code in one orgnisation then i want target url to add to reotesite
for ex like 'https://vikashtalanki-developer-edition.na12.force.com/services/apexrest/GetService how to get this type url for my target code.
please replay.
thanks,
GO
Setup--->Sequrity Controls---->Remote Site Setting and put there name and https://ap1.salesforce.com thats it.
Hi sunil ,
meas for the above my target code i can add url https://ap1.salesforce.com in remote site settigs.
Thanks,
Yes
or
can you tell me what types of error r u getting?
My target org code:
and my source org code is:
which on cliking submit button should give me 'Hi, You have invoked getservice1 created using Apex Rest and exposed using REST API'..........
for te above code they are added url 'https://vikashtalanki-developer-edition.na12.force.com/services/apexrest/GetService' in Remote Sites (Setup | Administration Setup | Security Controls | Remote Site Settings).
My dought is i have created the same thing in my org but i did'n got the above type url to add to remote site settings
please suggest me .
you can put this URL:-
https://ap1.salesforce.com
or when you click on button getting some MSG then follw the same it will give out put
Please Accept my answer as solution (if it was helpful) to make it available to others for similar problem & Don't forget to give me KUDOS by Clicking on STAR icon
Hi Sunil, sorry for truble ,
it sowig error when i mensioned the url: https://ap1.salesforce.com
my modified code is like below
public class getservice2
{
public String myresponse{get;set;}
public Pagereference getResult()
{
HttpRequest req = new HttpRequest();
Http http = new Http();
req.setMethod('GET');
String url = 'https://ap1.salesforce.com';
req.setEndpoint(url);
req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
HTTPResponse resp = http.send(req);
myresponse=resp.getBody();
return null; }
}
when i am clicking button it shows error.
i think url may be problem.
thanks,
Hi Servesh,
you can call like that..
String url = 'https://ap1.salesforce.com/services/apexrest/GetService';
can you explain error also
Hi Sunil,
Thank you so much .. its working.
thanks for giving solution to me.
Thanks,
Sarvesh.
HI Sunil,
its working ,but i have created new site (Develop-->sites) and added that rest class to this site ,
i mean new site having target code then how can i call that one in same org.
please replay
thanks,
Sarvesh.
Hello Servesh,
you can add your VF page in site and call it normally it will work
steps:-Setup---->Develop--->Sites--->Click on site level or edir----> site VF Pages Edit buttons and add UR VF page in
now check it will work
Hi Sunil,
I have added rest class to site add tried to call that but it shows error
[{"message":"HTTPS Required","errorCode":"UNSUPPORTED_CLIENT"}]
please suggest
thanks
Hi Sunil,
I have added rest class to site add tried to call that but it shows error
[{"message":"HTTPS Required","errorCode":"UNSUPPORTED_CLIENT"}]
please suggest
thanks
Hello Servesh,
you need to enabled your Apex class.
Enabled Apex Class Access
how to enable the Apex also you can give the access of object and VF and Apex classes.
Step:- Setup--->Develop---->Sites------>Edit-------->Click on public Access Settings----> Go Section for enabled Apex classes Access -----> Edit buttons and Add your Apex classes.
Hi Sunil,
I have added my apex class contaied rest code to sites through Setup--->Develop---->Sites------>Edit-------->Click on public Access Settings, but i have got same error.
my apex class that i have added to site is below
@RestResource(urlMapping='/GetService/*')
global with sharing class getservice1
{
@HttpGet
global static String postRestMethod()
{
return 'Hi, You have invoked getservice1 created using Apex Rest and exposed using REST API';
}
}
my apex page source code is
<apex:page controller="getservice2">
<apex:form >
<apex:commandButton action="{!getResult}" value="Submit"> </apex:commandButton>
<br/><br/> {!myresponse}
</apex:form>
</apex:page>
public class getservice2
{
public String myresponse{get;set;}
public Pagereference getResult()
{
HttpRequest req = new HttpRequest();
Http http = new Http();
req.setMethod('GET');
String url = 'http://sarveswararao-developer-edition.ap1.force.com/services/apexrest/GetService ';
req.setEndpoint(url);
req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
HTTPResponse resp = http.send(req);
myresponse=resp.getBody();
return null; }
}
plesae suggest me.
you have create any namespace prefix or package if you have then simply copy that namespace prefix and add it below location
String url = 'http://sarveswararao-developer-edition.ap1.force.com/services/apexrest/HERE namespace prefix/GetService ';
where i put you can put ur namespace
HERE namespace prefix = ur namespace
It was due to a permissions error it seems. Somehow an object for the services profile had an impossible permission setup (it had full read write modify all on an child object where it did not have read write modify all on the parent object (an opportunity)). So fixing the permissions and making sure the service had read/write to all objects and fields it required seems to have fixed this error.
HI Sunil,
Sorr for trouble
I have create names prifix and use that in url but same error happen.
my url is:String url = 'http://sarveswararao-developer-edition.ap1.force.com/services/apexrest/ysr/GetService ';
Here i have foud some inforation please check http://salesforce.stackexchange.com/questions/6122/custom-rest-service-https-error
thanks,
sarvesh.
HI Sunil ,
GMorning
its working... by below
changes
Thanks,
Sarvesh.