+ Start a Discussion
Hari nadh babu EluruHari nadh babu Eluru 

Fee field must not be blank

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
errorPlease suggest me how to implement the condition. Thank you !
Best Answer chosen by Hari nadh babu Eluru
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Hari,

Try to replace the if condition with the below.
 
if(x.Fee_paid__c < 0 || x.Fee_paid__c==null ){
            x.Fee_paid__c.adderror('Please enter amount');
        }

If this solution helps, Please mark it as best answer.

Thanks,
 

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Hari,

Try to replace the if condition with the below.
 
if(x.Fee_paid__c < 0 || x.Fee_paid__c==null ){
            x.Fee_paid__c.adderror('Please enter amount');
        }

If this solution helps, Please mark it as best answer.

Thanks,
 
This was selected as the best answer
Hari nadh babu EluruHari nadh babu Eluru
@Sai Praveen, Thank you very much !