You need to sign in to do that
Don't have an account?
Trigger error using pattern.matches
Hi,
I am trying to use the pattern.matches function on an apex trigger on our sandbox, what we are trying to do is update a record to Pending Validation based on whether a linked record meets the format required.
So on the trigger we have:
trigger Enrg_PendingValidation_Trigger on Registrations__c (Before Update, Before Insert){
for(Registrations__c reg:trigger.new){
Boolean validTelephone;
telephonePat='[0-9]{3} [0-9]{4} [0-9]{4}';
telephone = reg.Site__r.Site_Phone__c;
validTelephone= Pattern.matches(telephonePat,telephone);
if(reg.Site__r.Site_Phone__c != null && validTelephone!= true ){
reg.Registration_Status__c='Pending Validation';
}
}
}
This trigger saves ok on Salesforce but when I try to edit and save the registration I get the error message
Script-thrown exception: Class.System.Pattern.matcher
It appears that the issue is being caused by the line validTelephone= Pattern.matches(telephonePat,telephone); as when I comment this out I am able to save the record.
Can anyone help me on this? I can't see what I am doing wrong here.
Thanks in advance.
Try a different regex, something like:
Please note that this is a very basic regex and wont match on numbers with parenthesis around area codes or phone numbers with extensions, etc.
Hi James,
Thanks for the reply - unfortunately when I try that format the error message still appears.
The field I'm validating against is from a child record - would this matter?