Ok so I have a fairly complex scenario I need to test...
I have a Trigger on a
MyObject__c that creates
MyObject__c is inserted. Because PS Assignments are system objects, they're creation must run in a future method. Because the future method can fail while the trigger succeeds, there may eventually wind up with a scenario where
MyObject__c exists but the
PermissionSetAssignment was not created.
To counter this, I have written a Batch Class that will be scheduled to run on intervals and create any PS Assignments that failed to create by the trigger.
Thus we arrive at my delimia... I can't properly test this functionality because of the following:
I must instate
MyObject__c in the test setup. The trigger will run and a
PermissionSetAssignment will be created using a future method. But this assignment doesn't get created until
Test.stopTest() is called.
I then need to delete this PermissionSetAssignment so that the state will now be out of sync.
Then, I need to run my batch class and check that the assignment has been added back. However, this code ALSO won't run until
Thus, both the Batch Execute and the future PS Assignment insert are going to run in a strange sort of "Race Condition"
I'm wondering if there is some way to prevent the trigger to run in the first place. This would give me the setup I need to test.
Or if anyone has any other suggestions on how to handle testing this.