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

throw an exception for relatedlist del action
Hi Friends,
I have a small requirement , please let me know whether it is a valid one or not.
I am displaying Account Contacts using a relatedlist in a Visual force page(Standard Controller to Account object Extensions a class) , in which for a certain role like CEO i should not allow the contact to be get deleted . I have to do this using related list(not by other means such as a table datalist) , so i have overriden the del action of Contact object with a visual force page and i am calling a action method on it page load.
I am able to check the CEO record and stop the record from getting delete, but my requirement is to display a message to the user that the record cannot be deleted.
I am ok with custom confirm message (Are you sure?), just need to throw an exception in the visual force from which the del action commensed.
I have tried using trigger on before delete for Contact object, but the error message should be displayed on the VFP.
Please let me know how this can be done,or i am thinking in a wrong direction
Regards,
Hi,
To redirect to page 2 , you can use :
public PageReference redirectFuntion()
{
PageReference pageRef= new PageReference('/APEX/Page2');
pageRef.setredirect(true);
pageRef.getParameters().put('idRedirect','Hello');
return pageRef;
}
it will pass the Hello label to 2nd page using through parameter 'idRedirect'
to retrieve it in 2nd page just use : this.Label=Apexpages.currentPage().getParameters().get('idRedirect');
as far as I know , apex class didnt support alert function. You may use javascript instead.
All Answers
Hi ,
create new function for delete.
add the apex:message in the visualforce and define it in the apex class using :
ApexPages.Message myMsg2 = new ApexPages.Message(ApexPages.Severity.Error,'You cannot delete this contact');
ApexPages.addMessage(myMsg2);
is it what r you looking for ?
Hi S_Lie,
Thanks for the reply , actually the page 2(iam overriding the delete action of contacts with the VFP) in which the Delete action handled was different from the page 1 in which the message have to be shown.
Right now iam planning to show a label in the Page 2 and provide a back button
or
show a alert message from apex class (if possible).
Please let me know if it can be done in a better way.
Hi,
To redirect to page 2 , you can use :
public PageReference redirectFuntion()
{
PageReference pageRef= new PageReference('/APEX/Page2');
pageRef.setredirect(true);
pageRef.getParameters().put('idRedirect','Hello');
return pageRef;
}
it will pass the Hello label to 2nd page using through parameter 'idRedirect'
to retrieve it in 2nd page just use : this.Label=Apexpages.currentPage().getParameters().get('idRedirect');
as far as I know , apex class didnt support alert function. You may use javascript instead.
Thanks for the reply again,
I have used a trigger for the event before delete on contact object to restrict the del action.
It worked out well, redirecting the control to a page with the errror Message.