You need to sign in to do that
Don't have an account?
learnSF
I need to handle exception and show my person message(like record is deleted) when user try to fetch data which is already deleted.
And page is like this.
Now this page shows message which is not user readable.Istead of standard message,I need to diaply like"record is deleted and it will be in recyclebin for 30 days"
ApexPages.addMessages(e) in visual force page
I need to handle exception and show my person message(like record is deleted) when user try to fetch data which is already deleted.
I wrote code like this in extention controller.
Code:
public MyControllerExtension(ApexPages.StandardController stdController) { try { this.acct = [select id, name, site,Account_Manager__c,RecordTypeId,Dealer_ID__c,OwnerId from Account where id = :System.currentPageReference().getParameters().get('id')]; this.profile=[Select p.Name From Profile p where p.Id=:UserInfo.getProfileId()]; } catch (System.QueryException e) { ApexPages.addMessages(e); } init(); }
And page is like this.
Code:
<apex:page standardController="Account" extensions="MyControllerExtension" action="{!doRedirect}"> <apex:pageMessages /> <apex:detail relatedList="true" relatedListHover="true"subject="{!account.id}"/> </apex:page>
Now this page shows message which is not user readable.Istead of standard message,I need to diaply like"record is deleted and it will be in recyclebin for 30 days"
How I can show this meesage instead of standard message in visual force page?
Any help will be great.
ApexPage.addMessage('record is deleted and it will be in recycle bin for 30 days');
what message do you get today?
Thanks Ron for reply.
I tried to write message in addMessage method,but it gives me error that ,method signature(String) does not exist.
Right now I me getting below error with catch statement.
Attempt to de-reference a null object
An unexpected error has occurred. Your development organization has been notified.
Without writing catch statement error was like shown below.
List has no rows for assignment to SObject
An unexpected error has occurred. Your development organization has been notified.
Hi Ron,
I wroe like this.
} catch (System.QueryException e) {
ApexPages.addMessage('record deleted');
}
But it does not allowed to arite string in addMessage method.It says method does not exist or addMessage(String)is not correct argument.
Could you please tell me how I can write personal message in place of e?
Here's a thread where we discussed something similar and I provided several links to the doc.
Hi,
I read document but I am not able to find example where I can write my own custom messages instead of standard.Each exmaple shows standard messages passes to pages.
When I am trying to write custom messages,addMessage methos does not allowed to save me class nad giving compile error.If you see my above post you will see what type of message I want.
I tried this way also.
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'my error msg');
public MyControllerExtension(ApexPages.StandardController stdController) {
try {
this.acct = [select id, name, site,Account_Manager__c,RecordTypeId,Dealer_ID__c,OwnerId from Account where id =
:System.currentPageReference().getParameters().get('id')];
this.profile=[Select p.Name From Profile p where p.Id=:UserInfo.getProfileId()];
} catch (System.QueryException myMsg) {
ApexPages.addMessage(myMsg);
}
init();
}
Error: Compile Error: Method does not exist or incorrect signature: ApexPages.addMessage(System.QueryException)
That tells you that you're trying to pass a QueryException into the addMessage method, which is incorrect because you want to be passing in your own message. You named your query exception myMsg, which is the same name as your ApexPages.Message. It's not doing what you think it's doing because your message is outside of the scope.
I would also suggest bring your ApexPages.Message myMsg declaration inside the catch, since there's no reason to construct it unless you actually need to add the message.
Hi,
Yes I am getting same error.
But still I didnot understand after catching query exception,how I can diaply personal message to page?As It dipsly standard message which is define for query Exception,which is not user readable.
As addMessage only accept QueryException or any other Exception only.How I can pass String Message to method or page?
ApexPages.addMessages() (plural) accepts only an exception. ApexPages.addMessage() (singular) accepts a Message object.
Your attempt in which you created a Message object containing the error text is almost correct. Jill explained above where it went wrong.... take another look, I think you must have not quite made the changes she suggested .
I encountered a similar error and this is how u can add the error message to ur page..
In the apex class u add
Then in the Visual force page add
This will help displaying your messages on the page
Cheers,
Sirisha
I got it.
Now I wrote code like this.
And page is like this.
Even though I add personal message to addMessage method,it still shows same error message.
Attempt to de-reference a null object
An unexpected error has occurred. Your development organization has been notified.
It is not showing my perosnal message.
Any suggestion?
Message Edited by learnSF on 06-24-2008 12:30 PM
One more thing.
Developer edition shows <apex:pageMessage/> in refrence component while this tag I am trying to writing in my sandbox page,but it givis error.
It suggest only one tag that is <apex:pageMessages/>
Any idea?
Attempt to de-reference a null object
An unexpected error has occurred. Your development organization has been notified. error.
But anytime it didn't show my personal message.
Are you in development mode? Based on the message it doesn't look like it, you should be getting an Apex code stack trace.
Basilcally this record is deleted by user. and if they copy and paste same url,query is trying to fatch data based on id on url and data is not present.
So it give error for null ponter.
But even though exception catch I am not sure why it is not showing personal message?
The NullPointer is actually happening somewhere later, like maybe in your init method, which is why you need to enable development mode so you can see your stack and find out where it's happening. Or maybe you are trying to reference {!account.name} on your page when the account has been deleted. In which case you'll need to conditionally render the blocks that are referencing account fields.
If you're catching a NullPointer around your query that's not going to work. It's not throwing a NullPointer, it's throwing a QueryException, which is why your QueryException is bubbling out to the page.
If you're catching a QueryException, do you need to call return; after setting the message, instead of continuing on to call init()? You're probably catching it and adding the exception correctly, but an NPE is happening somewhere else in your page, and so the page isn't going to load, it's going to take you to the error page instead.
Please try that out (if you're not in development mode, you should definitely enable it!) and make sure your page and controller are bulletproofed against having a null account, since you expect that the account can be null from time to time.
One more thing,Do I have to enable development mode in sandbox through my personal information?
How this mode will help me? Sorry but I am not familier with stack trace.
Message Edited by learnSF on 06-25-2008 08:06 AM
Message Edited by learnSF on 06-25-2008 08:07 AM
If you're not using development mode you should be!!!! Please look at the documentation, it is the first thing you are asked to do, and it's where I would have expected you to start.
Development mode gives you access to the inline editor as well as all of the quickfixes and things that make developing in Visualforce much much easier. It also changes some of the error messaging behavior -- you might see much more descriptive error messages in dev mode, including the Apex code stack trace that will help you pinpoint the line that's throwing an exception. Had you been in dev mode I suspect you would have seen your NPE coming from your init method and fixed it right away.
You enable it through your personal information, and this info is on the first page of the quickstart in the dev guide! Please read it, if you're going to be developing in Visualforce you should have this perm turned on.
Message Edited by jwetzler on 06-25-2008 11:35 AM