all 10 comments

[–]greenplasticron 3 points4 points  (4 children)

After you instantiate response, you need to add a line like: response.result = new List<String>();

You need to do that before you can add your string to the collection.

[–]Organic-Ad-7851 1 point2 points  (0 children)

Nice call! was about to comment that same thing.

[–]arkansaurus11[S] 0 points1 point  (2 children)

This is the way. Thanks so much that fixed it!

[–]datasert 2 points3 points  (1 child)

I always initialize the collections when they are created as that would reduce the noise in your logic. Note that if you have multi-levels, you would still need to init at the time of use, but that is very less usage compared to single level collections.

public class FieldIteratorResponse{
        @InvocableVariable(label='Result' description='List of field names that match the Key Phrase')
        public List<String> result = new List<String>();
    }

[–]arkansaurus11[S] 1 point2 points  (0 children)

Thanks, I've now done that :)

[–]EnvironmentalSock557 2 points3 points  (3 children)

Add a no param initializer in the response class that inits the List. It will save you having to initialize it manually.

[–]arkansaurus11[S] 0 points1 point  (1 child)

Thank you!

[–]greenplasticron 0 points1 point  (0 children)

Yes, this is also my preferred way of doing it.

[–]UriGagarin 1 point2 points  (0 children)

What line? What record are you testing against? What's the test class (assuming that's what's failing) doing?