mitchspano/apex-trigger-actions-framework

"Required Permission" field input validate?

pmendola1 opened this issue ยท 3 comments

this is my first public issue report so go easy ๐Ÿ˜‚

Expected Behavior

If an invalid custom permission API name is entered into the "Required Permission" field in the CMDT record, it should be caught somewhere.

Actual Behavior

Today I randomly made a typo where I entered "2" in the "Required Permission" field for a trigger action record. This caused the action not to execute as expected, it silently did not trigger the update - of course this is the intent, however the "2" is an invalid value for permission api name for this org.

I guess this could be tricky to validate without querying to check for existence (hence maybe not worth the overhead), since it looks like custom permissions dont have __c and can have underscores or no spaces.

Steps to Reproduce the Problem

  1. create a trigger action CMDT record
  2. enter a permission name that doesnt exist in your org in "Required Permission"
  3. run a test/update a record to trigger the action and see that it doesnt trigger and doesnt throw an error.

Specifications

  • Version: 57

@pmendola1: Thanks for raising the issue.

I understand the frustration of typos and I would like to validate those inputs as well. But unfortunately, there is no easy way to check whether the custom permission exists or not.

I would like to use something like this as a validation rule:

AND(
	NOT(ISBLANK(Required_Permission__c)),
	ISNULL(VLOOKUP(
		$ObjectType.CustomPermission.Fields.Id,
		$ObjectType.CustomPermission.Fields.Id,
		Required_Permission__c
	))
)

But unfortunately, as of today, VLOOKUP is only supported for custom objects.

As an alternative, some would think about some automation on the CMDT. But unfortunately, as of today, we cannot define triggers nor flows on CMDT.

@benjaminloerincz
definitely makes sense, I was thinking the validation could be done in the backend of the framework like MetadataTriggerHandler or something, but it's probably not worth it to add a query there

Validating that an entered custom permission API name is valid would fall outside of the scope of the framework.

That would need to be performed in a unit test which executes on the rows of SObject_Trigger_Setting__mdt or Trigger_Action__mdt which the package installer has authored (AKA in your own org).