You need to sign in to do that
Don't have an account?

How to display Error message in Catch?
Hi friends,
I ma creatin role with the help of vf and apex class...
and displaying roles in Visualforce page with the help of Apex class....
i want to give edit and delete functionalty on vf page... i have given the same...Edit is working properly...
Delete is also working fine... but while i want to delete a role for which any user is assigned it is Showing standard error..(i want to make it custom eg- you can not delete this role)...
can i do this???
this is my code..
public class RoleList
{
public List<UserRole> list_role{get;set;}
public String message {get;set;}
public RoleList(ApexPages.StandardController controller)
{
list_role=[Select Name From UserRole Order By Name];
}
public PageReference del()
{ String delname = ApexPages.CurrentPage().getParameters().get('id');
try
{
Database.delete(delname);
}
catch(System.DMLException e)
{
// message = 'Whoops! An error occurred -- ';
// System.assert(false,message);
System.assert(false, e.getMessage());
}
PageReference p=new PageReference('/apex/AdminListView?intFocus=6');
p.setRedirect(true);
return p;
}
}
Just modifying some part of Chamil's post, so as to catch the error dynamically.
All Answers
Hi,
Add this code segment in catch block
And place following code in visualforce (add this in place which you need to show error)
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Chamil's Blog
Just modifying some part of Chamil's post, so as to catch the error dynamically.
Now I am not getting any error message....
and if user is associated with role to which i want to delete... after clicking on delete button it lands to same page(not showing error which i have written in catch block).
why?
Sorry friends...
its working now...
i missed to give return value....
i am getting error on my page.... is it possible to give message in dialog box?? and after pressing any button on dialog box i should land to the same page...
any suggestion?
Could you elaborate more on:
see...
i am using an vf page and apex class to view all the roles...
in this vf page i have given option of edit and delete...
right now if i am deleting any role (suppose this role is assigned to any user)...then after pressing delete button it shows a message on the same vf page (on which i am displaying list of roles)...
i want that, if i want to delete such kind of roles then first i should get a pop up Sure?Do u want to delete? - this msg i am getting.....after getting this message if any exception is caught..then is it possible to show message in dialog box(which i am getting in page)??
On button click call javascript function to show confirm box and in the confirm box show the error/exception asking the reply from user.
could you please give me any example with code??