You are on page 1of 1

@RestResource(urlMapping='/apexSecurityRest')

global with sharing class ApexSecurityRest {


@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 = [SELECT id, Name, Title, Top_Secret__c,


Account.Name FROM Contact WHERE Id = :recordId];
SObjectAccessDecision readDecision =
Security.stripInaccessible(AccessType.READABLE,results);
if (!readDecision.getRecords().isEmpty()) {

SObjectAccessDecision updateDecision =
Security.stripInaccessible(AccessType.UPDATABLE, readDecision.getRecords());
result = (Contact)(updateDecision.getRecords()[0]);
if (!
updateDecision.getRemovedFields().get('Contact').contains('Account.Name')){
result.Description = result.Account?.Name;
}
}

return result;
}
public class FunctionalException extends Exception{}
public class SecurityException extends Exception{}
}

You might also like