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
AbAb 

Throw error to user on save of button

Hello,

How can i throw a message to user to say that the below fields are required.

thank you for suggestion
Best Answer chosen by Ab
Malika Pathak 9Malika Pathak 9

Hi Sandrine,

Please find solution.  Throw error to user on save of button.

You can write trigger for this or you can write Process Builder. I am solving it with trigger.

trigger OpportunityTrigger on Opportunity (before Insert) {
    
    if(trigger.isBefore && Trigger.isInsert){
        for(opportunity op:trigger.new){
            if(op.StageName=='' || op.StageName==null){
                    op.StageName.addError('StageName is required');
            }
        }
    }
}
Please let me know it is working or not.
If it is working please mark best answer so that other people would take reference from it.
Thanks

All Answers

VinayVinay (Salesforce Developers) 
Hi Sandrine,

Have you tried using standard validation rules?  That should be enough to show error message.

Thanks,
Malika Pathak 9Malika Pathak 9

Hi Sandrine,

Please find solution.  Throw error to user on save of button.

You can write trigger for this or you can write Process Builder. I am solving it with trigger.

trigger OpportunityTrigger on Opportunity (before Insert) {
    
    if(trigger.isBefore && Trigger.isInsert){
        for(opportunity op:trigger.new){
            if(op.StageName=='' || op.StageName==null){
                    op.StageName.addError('StageName is required');
            }
        }
    }
}
Please let me know it is working or not.
If it is working please mark best answer so that other people would take reference from it.
Thanks
This was selected as the best answer