0

This is possible to create a trigger on Survey object, but DML operation insert is forbidden on Survey object. How one can cover Survey Trigger with a test?

1
  • I have seen a couple of questions around survey objects which are not writable. At this point it seems to be not allowed and unfortunately there wont be a way to cover and test the trigger. You may look at this question or the issue. These links are for Survey response which has same behaviour.
    – manjit5190
    Commented Mar 26, 2020 at 16:48

1 Answer 1

0

To test the trigger

trigger SurveyTrigger on Survey(before insert){
    //factor your logic to a  handler class and method
}

we could try to catch to exception of DML operation insert is now allowed

@isTest
private static void survey(){
    Survey s = new Survey();
    try{
        insert s;
    }
    catch(Exception e){
        System.assertEquals(...); 
    }
}
3
  • Same applies to SurveyInvitation?
    – Ysr Shk
    Commented Nov 8, 2021 at 10:15
  • how does this code cover the trigger? I don't see how trigger would ever execute
    – cropredy
    Commented Dec 14, 2022 at 23:31
  • statement execution insert s; should give coverage
    – Patlatus
    Commented Dec 15, 2022 at 10:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .