0

In this trigger apex, I want to give error when Fee_paid__c field must not be blank. We can throw the error as "Please enter amount"

I tried above code

trigger Not_Negative on Student__c (before insert) {
    for(Student__c x: trigger.new){
        if(x.Fee_paid__c < 0 && !(isblank(x.Fee_paid__c))){
            x.Fee_paid__c.adderror('Please enter amount');
        }
    }
}

The above image contains error message that i had getting error Error msg

Please suggest me how to implement the condition. Thank you !

2
  • Hi Hari, !(isblank(x.Fee_paid__c)) is not valid . Please check x.Fee_paid__c!=null condition Dec 28, 2021 at 7:23
  • Problem is solved, but if Fee_paid__c field leaves blank then also record was get saved with blank field Dec 28, 2021 at 7:44

1 Answer 1

0

Change the if condition as below. I hope the condition should be || instead of &&

 if(x.Fee_paid__c < 0 || x.Fee_paid__c==null ){
            x.Fee_paid__c.adderror('Please enter amount');
        }
1
  • Thank you very much, Problem solved Dec 28, 2021 at 7:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .