198k views
5 votes
What is a programmatic solution for the following scenario:

A user should only be able to update an account record if certain unrelated custom object records have been created.

1 Answer

4 votes

Final answer:

A programmatic solution using Apex triggers can allow a user to update an account record only if certain unrelated custom object records have been created.

Step-by-step explanation:

A programmatic solution for the scenario where a user should only be able to update an account record if certain unrelated custom object records have been created can be implemented using Apex triggers in Salesforce.

An Apex trigger can be written on the account object to check for the existence of the related custom object records. If the required records are not found, the trigger can prevent the update operation from completing by throwing an exception.

Here's an example of how the trigger code might look:

trigger AccountRecordTrigger on Account (before update) {
// Query the related custom object records
List<CustomObject__c> customObjects = [SELECT Id FROM CustomObject__c WHERE Account__c IN :Trigger.new];

// Check if the required records are present
if (customObjects.isEmpty()) {
// Throw an exception to prevent the update
throw new AuraHandledException('Cannot update account record without certain custom object records.');
User Manmay
by
7.2k points