-1

I have a request class used to call into a REST endpoint for an APEX class.

I wish to mark a property on the class required so that I do not need to manually validate the field.

How is that done?

Something like this would be nice:

Public class MyRequest{
    [Required] String UserName;     
} 

1 Answer 1

2

There is no attribute to mark a particular field as required in apex. Only annotations in apex rest are these : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation.htm

@ReadOnly
@RestResource(urlMapping='/yourUrl')
@HttpDelete
@HttpGet
@HttpPatch
@HttpPost
@HttpPut

Either you need to put the logic in the caller service, or if you want to put a logic in apex, then, you need to write the logic in Apex. Something like this.

Check required fields:

public static Boolean isRequestValid(MyRequest myRequest){
    return String.isNotBlank(myRequest.UserName);
}

And other params as required.

You must log in to answer this question.

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