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
ChinnoduChinnodu 

How to erase value from text field while updating record ?

Hi All,

How to erase value from text field while updating record?

Reauirement :
i have one text field, while creating a record it is required field and while updating same record, i would be erase value from text field.?

please let me know how can i achive this .Give me example code also.

Thanks in advance.
China
@anilbathula@@anilbathula@
Hi Chinnodu,

Write a validation rule on insert 

AND(Isnew(),ISBLANK(Your_field__C))

Thanks
Anil.B
James Wilson 57James Wilson 57
When you find a matching record, that record becomes the current record, and you can then edit or delete it. Click the field that you want to search. On the Home tab, in the Find group, click Find, or press CTRL+F. Click the Find tab. In the Find What box, type the value that you want to match. Abyssinia Ethiopian Menu (https://centralmenus.com/abyssinia-ethiopian-menu-prices-locations/)
Ravi Dutt SharmaRavi Dutt Sharma
Hi China,

You can use below code for your requirement. On lead insert, it make the City mandatory and on lead update, it will blank out the value from City.
 
trigger LeadTrigger on Lead (before insert) {
	
    if(Trigger.IsBefore && Trigger.isInsert){
        LeadTriggerHandler.checkForRequiredField(Trigger.new);
    }
    
    if(Trigger.isBefore && Trigger.isUpdate){
		LeadTriggerHandler.emptyRequiredFieldValue(Trigger.new);        
    }
}
 
public class LeadTriggerHandler {
    
    public static void checkForRequiredField(List<Lead> newLeads){
        for(Lead ld: newLeads){
            if(String.isBlank(ld.City)){
                ld.addError('City cannot be blank');
            }
        }
    }
    
    public static void emptyRequiredFieldValue(List<Lead> newLeads){
        for(Lead ld: newLeads){
            if(!String.isBlank(ld.City)){
                ld.City = '';
            }
        }
    }
}