2

I have created the following class

@RestResource(urlMapping='/Expense/*')
global class ExpenseWS
{


@HttpPost
global static void createExpense(String ExpenseName,String Type,Integer Amount)
{

Expenses__c e = new Expenses__c();

e.Expense_Name__c = ExpenseName;
e.Type__c = Type;
e.Amount__c = Amount;

insert e;



}


}

And I am able to successfully insert a expense using workbench REST explorer as shown below.

enter image description here

I would like to get the URI (endpoint) for this particular REST class so that I can invoke this REST resource from another org.

As per the guides I need to use the following notation.

https://ap2.salesforce.com/services/apexrest/Expense

I am not sure whether this is right because there is no unique org identifier in the above URI. There could be thousands of instances under ap2.salesforce.com

I hope I am making sense.

Q : How to get the endpoint/URI for the above REST resource ?

UPDATE Thanks . The scenario which I am testing consist of two SF orgs..one sending expense data and another inserting expense data.

As such I have added the second org which absorbs the data sent (i.e where the post rest resource exists) in the first org's "Security Controls"->"Remote Site Settings".

I observed the following .

enter image description here

enter image description here

Can someone explain why the /services/apexrest/expense part of the URL is not accepted as endpoint by Salesforce ?

  • You have to authenticate before you can call the rest resource. You authentication is what allows you to access the endpoint – Eric Sep 18 '15 at 6:14
  • Thanks Eric...so let me understand this...let us say I want this webservice to be public to the whole world..then the only way to achieve that is via Sites..am I right ? – Varun Sep 18 '15 at 6:18
  • Someone chime in here if I am wrong but I believe so. developer.salesforce.com/blogs/developer-relations/2012/02/… – Eric Sep 18 '15 at 6:21
4

You have to authenticate before you can call the rest resource. You authentication is what allows you to access the endpoint

A little while ago, Paul McGurn blogged how to create a public (SOAP-based) web service via a Force.com Site. As Paul explains, you add your web service class to the Enabled Apex Classes in the Site’s Public Access Settings. You’ll also need to add the appropriate object and field-level permissions for any data you will be exposing; remembering, of course, that this web service will be accessible without any authentication!

As I was setting up a WebHook the other day, I realized that the same principle applies to Apex REST Methods – add the class and any relevant objects/fields to your Site’s Public Access Settings, and you can access the REST methods via the Site URL. Let’s code up a simple example; here’s my Apex class:

https://developer.salesforce.com/blogs/developer-relations/2012/02/quick-tip-public-restful-web-services-on-force-com-sites.html

  • Great mate..tx for the help..just one more thing..I have updated the question..can you please provide your inputs..cheers ! – Varun Sep 18 '15 at 6:37
  • Please close out this question and ask that as a new question. It helps keep things better organized for people looking for similar issues (seeing this one answered and searching for the second one) – Eric Sep 18 '15 at 6:39
  • Sure...I have created the following question for the second part salesforce.stackexchange.com/questions/92972/… – Varun Sep 18 '15 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.