For some strange reason in LWC, Name
field from PermissionSetTabSetting
returns either standard object name or custom tab id, while in Classic, it returns the tab name.
Workaround here is to use Tooling API with Classic Session Id.
Create Visualforce Page 'Api'.
<apex:page controller="ApiCont" showHeader="false" sidebar="false">
{!sid}
</apex:page>
Create Apex Controller ApiCont
.
public with sharing class ApiCont {
public static String SEPAR = '[|]';
public String sid{ get{ return SEPAR + UserInfo.getSessionId() + SEPAR ;} set;}
}
Create Apex class ApiService
.
public with sharing class ApiService{
@testVisible static String sid;
public static String getClassicSessionId() {
if (sid == null) {
sid = new PageReference(
'/apex/Api'
).getContent().toString().substringBetween(ApiCont.SEPAR, ApiCont.SEPAR);
}
return sid;
}
}
Create Apex class ToolingApi
.
public with sharing class ToolingApi {
static String restGet(String endPoint, String method, String sid) {
Http h = new Http();
HttpRequest hr = new HttpRequest();
hr.setHeader('Authorization', 'Bearer ' + sid);
hr.setTimeout(60000);
hr.setEndpoint(endPoint);
hr.setMethod(method);
HttpResponse r = h.send(hr);
return r.getBody();
}
public static String query(String query) {
String baseURL = URL.getSalesforceBaseUrl().toExternalForm();
return restGet( baseURL + '/services/data/v52.0/tooling/query?q='+ (query.replace(' ', '+')), 'GET', ApiService.getClassicSessionId() );
}
}
Now if you run it as Tooling Api query, it will return correct results even in LWC:
String body = ToolingApi.query('SELECT Name, ParentId, Visibility FROM PermissionSetTabSetting WHERE ParentId IN (\'' + String.join(parentIds, '\',\'') + '\')');
System.debug(LoggingLevel.Error, 'body: ' + body);
Wherever you used to have query
SELECT Name, ParentId, Visibility
FROM PermissionSetTabSetting
WHERE ParentId IN: parentIds
use instead
Map<String, Object> dataMap = (Map<String, Object>) JSON.deserializeUntyped(body);
(List<PermissionSetTabSetting>) JSON.deserialize(JSON.serialize(dataMap.get('records')), List<PermissionSetTabSetting>.class )