0

Let's say a have

@RestResource(urlMapping='/Test/v1')
global with sharing class MuleTest {
    @HttpGet
    global static Contact getAccountContacts() {
        RestRequest request = RestContext.request;
        String accId = request.requestURI.substring(request.requestURI.lastIndexOf('/')+1);
        system.debug(accId);
        return [select id,
                        firstName, 
                        LastName 
                from Contact where Account.id= :accId];
    }

}

Then I'm trying to revoke this from POSTMAN uri: https://mule-test-dev-ed.my.salesforce.com/services/apexrest/Test/v1/getAccountContacts

I've set up security token header and username/pass for basic auth. But I get an error

Could not get any response There was an error connecting to https://mule-test-dev-ed.my.salesforce.com/services/apexrest/Test/v1/getAccountContacts.

What am I doing wrong ?

1
  • 1
    SF does not support HTTP Basic Auth, you have to use oAuth
    – identigral
    Feb 21, 2020 at 15:24

1 Answer 1

2

You need to update your @RestResource annotation and the URL you're using in order for this to work.

The body of your method is looking for the Account Id as the last part of the URL but it isn't defined in your mapping and your URL doesn't provide it.

You should update your annotation to @RestResource(urlMapping='/Test/v1/*') and then your URL to https://mule-test-dev-ed.my.salesforce.com/services/apexrest/Test/v1/ACCOUNTID and pass in an actual account id for ACCOUNTID.

There's a very similar example in the documentation for reference.

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .