Skip to content

Instantly share code, notes, and snippets.

@arun12209
Created January 21, 2023 07:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
public with sharing class ValidationController {
@AuraEnabled
public static ValidationResult validateData(String name, String email, Integer age) {
ValidationResult result = new ValidationResult();
if (name == null || name.isEmpty()) {
result.addError('Name is required');
}
if (email == null || email.isEmpty() || !email.contains('@')) {
result.addError('Valid email is required');
}
if (age == null || age < 18) {
result.addError('Age must be 18 or older');
}
return result;
}
public class ValidationResult {
@AuraEnabled
public List<String> errors { get; set; }
public ValidationResult() {
errors = new List<String>();
}
public void addError(String error) {
errors.add(error);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment