I am trying to call ui api from apex code with in a lightning component.
String instance = System.URL.getSalesforceBaseURL().toExternalForm();
String restApi = instance + '/services/data/v42.0/ui-api/object-info/Account';
HttpRequest req = new HttpRequest();
req.setEndpoint(restApi);
req.setMethod(method);
if(String.isNotBlank(requestBody)){
req.setBody(requestBody);
}
//session id is valid
req.setHeader('Authorization', 'Bearer '+this.sessionId);
String body = '';
try{
Http h = new Http();
HttpResponse res = h.send(req);
body = res.getBody();
if(res.getStatusCode() == 200){
//Parse JSON response
return body;
} else {
System.debug(res.getStatusCode());
System.debug('Error body ' + body);
}
}catch(System.CalloutException ex){
//handle callout error
}
return body;
This piece of code returns correct result when the component displayed by internal user. However, when component is display on Community and viewed by Community Portal User, I have following error:
[{"message":"The requested API is not available to portal users. You may need to specify a community for portal user access.","errorCode":"FUNCTIONALITY_NOT_ENABLED"}]
I tried to make rest api(like:"/services/data/v42.0/sobject/Account/describe"
) calls using portal user, calls return successfully.
Does that mean salesforce ui api does not support calls made by portal user? or there is some settings I need to turn on for portal user? Anyone can point me to any Salesforce documentation?