Skip to main content

I’ve been trying to access a apex REST method in a same org trough skuid and unfortunately it was not successful,



  1. created a “model service” as below.




  2. created a model as below.




  3. and the result is as below.



I already provided the username and the password for the “Model Service” though it gives me the “Unauthorized” error



  1. Error retrieving metadata for Model(s) associated with Data Source ‘RESTAPI’. Please check Models’ properties to ensure they are set correctly. Error connecting to REST Data Source at URL "https://cs16.salesforce.com/services/apexrest/Account/*": Unauthorized


Webservice that I’m trying to access;


@RestResource(urlMapping='/account/\*')
global with sharing class AdviceAccreditionsWebService { @HttpDelete global static void doDelete() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; //String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); Account account = 1SELECT Id FROM Account limit 1]; delete account; } @HttpGet global static Account doGet() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; //String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); Account result = +SELECT Id, Name, Phone, Website FROM Account limit 1]; return result; } @HttpPost global static String doPost(String name, String phone, String website) { Account account = new Account(); account.Name = name; account.phone = phone; account.website = website; insert account; return account.Id; } }

What am I missing here? Please help, Thanks.

Hasantha, a couple issues here:

1. Model Service settings — to connect to your own Salesforce org (the own you’re currently on), you (perhaps unintuitively) need to have “No Authentication” turned on and then add a “Common Request Header”. Click the little box to “Append” a new Header. For the key, you should have “Authorization”, and the value should be “Bearer {{$Api.Session_Id}}”. 

43c93e4d77e99e7c84713a5a8aac13b264d73976.png

2. In your Skuid Page, the Model’s “Service URL” should be /services/apexrest/account/{{Id}} — then, when you go to click on Fields, Skuid will prompt you to enter a sample value for the Account’s Id, so be prepared beforehand with a sample Account’s Id (copy it from an Account detail page URL).


Thanks Zach, it works!

Got one more question, How could I save a record via REST. I could see my request Payload contains the modified values of the fields other than the Id, Please see the payload source below,


 
   “action”:“skuid.RemotingStubs”,
   “method”:“proxy”,
   “data”:r  
      “{”“url”“:”“https://cs16.salesforce.com/services/apexrest/account1"”,““headers””:{““User-Age… (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36"”,”“Accept”“:”“application/json”“,”“Authorization”“:”“Bearer 00Df0000001oJ3z!AQUAQJiiMf.66tRd97j08Hgg4T8HAF_7Ha0sE1Tjge0ny5ZluW_wtQPwZo74I3GKmMjjA8OODubQ”“,”“Content-Type”“:”“application/json”“},”“method”“:”“PUT”“,”“modelService”“:”“RESTAPI”“,”“contentType”“:”“application/json”“,”“body”“:”“{"“Name"”:"” Practicea"“,"“Phone"”:"“42345345354353a"”}”“}”
   ],
   “type”:“rpc”,
   “tid”:3,
   “ctx”:{  
      “csrf”:“VmpFPSxNakF4Tmkwd01pMHhPVlF3TXpvek5EbzBPUzQyTnpWYSxtQ1VLblJSOEcweGpta0tyNjl”,
      “vid”:“06613000001IuRt”,
      “ns”:“skuid”,
      “ver”:33
   }
}


Reply