function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
raghava520raghava520 

how to Clear text field if validation fails

Hi  Experts
i have written a trigger on contact object  which ristrict the user to enter only text in  language field

trigger contrg on Contact (before insert, before update) {
Contact con = trigger.new[0];
string s1= con.Languages__c;
if(s1.Isalpha()==false){
con.languages__c.Adderror('please enter only text');
}
}

it is working is throwing error when i hit sabe
but the false value which user given is remainig on the text feild so every time user have to delete and must give the correct value is there any way to Clear text field if validation fails

Thanks
Raghava.
Sonam_SFDCSonam_SFDC
Did you try initialising S1 = NULL if the code enters the if statement, like:
if(s1.Isalpha()==false){
s1= NULL;
con.languages__c.Adderror('please enter only text');
}