+ Start a Discussion
SandrineSandrine 

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 Sandrine
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