I'd like to use salesforce rest api in Apex Controller class. Main purpose to use rest api in Apex is to fetch listview colums details(colums order and colums field name) and output visualforce page with xlsx format in visualforce. when I try this sample code in Visualforce using fetch api, it works fine, but in Apex class, it fails. Error Message is shown. FATAL_ERROR System.CalloutException: no protocol: Url:[delegate=https://cs75.salesforce.com]/services/data/v49.0/sobjects/Account/listviews/00B5F0000059jK4UAI/describe
anybody konows how to solve it? thanks for advance.
Sample code is as below.
public class ListViewSampleController {
public Id listviewId {get; set;}
public ListViewSampleController(ApexPages.StandardSetController controller) {
this.listviewId = [SELECT Id FROM ListView WHERE SObjectType = 'Account' AND DeveloperName = 'ALL'].Id;
fetchListViewDetail();
}
public void fetchListViewDetail() {
HttpRequest req = new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl() + '/services/data/v49.0/sobjects/Account/listviews/' + this.listviewId + '/describe');
req.setMethod('GET');
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());
}
}
UPDATE: I found a solution. This code works well
change like below
req.setEndpoint(Url.getOrgDomainUrl().toExternalForm() + '/services/data/v49.0/sobjects/Account/listviews/' + this.listviewId + '/describe');