How to display the error message from a trigger to a custom visualforce page?
public PageReference save()
{
Student__c stud=new Student__c();
stud.Firstname__c=student.Firstname__c;
stud.Lastname__c=student.Lastname__c;
stud.Address__c=student.Address__c;
stud.Collegename__c=student.Collegename__c;
stud.Branchname__c=student.Branchname__c;
stud.Contact_Number__c=student.Contact_Number__c;
stud.Date_Of_Birth__c=student.Date_Of_Birth__c;
stud.Gender__c=student.Gender__c;
studentlist.add(stud);
try
{
if(studentlist!=null)
{
insert studentlist;
}
}
catch(Exception e)
{
Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,e.getMessage()));
}
return null;
}
i tried using this code but it does not display the message.