/ValidationController.cls Secret
Created
January 21, 2023 07:45
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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