12 件の回答
Refer this link https://success.salesforce.com/answers?id=9063A000000lSPsQAMYou dont have to provide access to any fields. If you read the challenge, you just have to edit the query to include the new WITH SECURITY_ENFORCED attribute, and remove other field level security checks. You need to put the query in a try/catch statement, and catch the System.Query Exception.Use this code @RestResource(urlMapping='/secureApexRest')
global with sharing class SecureApexRest {
@HttpGet
global static Contact doGet(){
Id recordId = RestContext.request.params.get('id');
Contact result;
if (recordId == null){
throw new FunctionalException('Id parameter is required');
}
List<Contact> results;
try{
results = [SELECT id, Name, Secret_Key__c FROM Contact WHERE Id = :recordId WITH SECURITY_ENFORCED];
}catch(QueryException e){}
if (!results.isEmpty()) {
result = results[0];
}
return result;
}
public class FunctionalException extends Exception{}
public class SecurityException extends Exception{}
}