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

Custom Button not passing ID
hi,
I have a custom button that I use to pass two id's to a controller. The button allows me to launch a VF page from a related list. This button was working fine, but has suddenly started throwing an invalid id error. My first assumption was that it had to do with the introduction of a new record type, which was causing an error in my controller somewhere, but I quickly noticed that the button was setting up the URL incorrectly. So, the button is meant to pass two ids one for custom object Goal__c and another for Account, and their query string variables are gid and aid, respectively. I noticed that when I click the button and get the error message that aid does not have the account's id assigned, and the error message points me to first line of code that works with account id. To further confuse things, I have buttons that work in a very similar matter, but they are launched from a different object, but still rely on account id in the same way...these still work fine. So, I'm curious to know if anybody has any ideas on why this might be failing.
Here is url that the button sets up: /apex/narrativeWizard3?gID={!Goal__c.Id}&aID={!Account.Id}
1. Which page is the cutom button on? Is it on Account detail page, Goal__c detail page or some other page?
2. What is the relationship between Goal__c and Account (lookup? master-detail?) When you contructing a query string like this
/apex/narrativeWizard3?gID={!Goal__c.Id}&aID={!Account.Id}
Which Goal__c and Account are you expecting to get returned? You mentioned it is a related list of Accounts. So how would the page know which Account to return?
3. What was the error message you see when you try the following?
/apex/narrativeWizard3?gID={!Goal__c.Id}&aID={!Goal__c.AccountId__c}
All Answers
Hi,
Please post your code.
The error is 'String Exception: Invalid Id' on line 33, which is the following line in the constructor: swpn.Account__c = ApexPages.currentPage().getParameters().get('aID');
Are you able to get the URL it is using to request your new page?
That is what the problem seems to be...the URL comes out wrong. The button is configured to feed the Goal Id and the Account Id as such: /apex/narrativeWizard3?gID={!Goal__c.Id}&aID={!Account.Id}
However, on the error page the URL says /apex/narrativeWizard3?gID=a1D40000000I9ns&aID=
And again, what is weird is that this use to work, and I have other buttons like it that still work. For example, I have the same button but for the Contact object rather than Goal__c, which is set up like so: /apex/narrativeWizard3?cID={!Contact.Id}&aID={!Account.Id}
It is really hard to know what is going on without poking around the actual page.
My wild guess is that Account.id might not even be there for you to pass it into the query string in the first place.Can you try to change the content source to be "Onclick Javascript" and replace the content to:
alert( {!Account.Id});
you should be able to see a valid id in the alert box once you invoke the button.If not, then that means the way you construct the query string is not correct. On the other hand,
alert( {!Goal__c.Id}); should definitely display an id in your case.
Thanks for the idea. I know nothing about javasript...just some Apex and VF so i wouldn't have though of that.
Anyway, I did it, and clicking the button simply presents me with the word 'undefined' in the alert pop-up.
So, it seems that our suspicion was correct...the Account ID is not being found. Any ideas on why?
If that is the case, are you sure this ever worked before? I am guessing you are on the Goal detail page and you are trying to find the Account id associated with that Goal. I think the correct sytax should be:
/apex/narrativeWizard3?gID={!Goal__c.Id}&aID={!Goal__c.AccountId__c}
Let me know if this works for you.
Yes, it worked when we initially deployed everything, and there are other buttons that work in the same way but from a different object. For example, one from the Contact object, and it finds the Account ID fine. The only thing I can remember doing before it broke was introducing a new record type to the Goal Object, but going back to one record type doesn't make it work again, and can't think of why that would effect anything.
It won't let me use the syntax that you suggested. The syntax I have seems to be the only way, and it is wokring for those other buttons that I mentioned.
1. Which page is the cutom button on? Is it on Account detail page, Goal__c detail page or some other page?
2. What is the relationship between Goal__c and Account (lookup? master-detail?) When you contructing a query string like this
/apex/narrativeWizard3?gID={!Goal__c.Id}&aID={!Account.Id}
Which Goal__c and Account are you expecting to get returned? You mentioned it is a related list of Accounts. So how would the page know which Account to return?
3. What was the error message you see when you try the following?
/apex/narrativeWizard3?gID={!Goal__c.Id}&aID={!Goal__c.AccountId__c}
Just got back around to this...it's been a busy week because we just turned chatter on.
anyway, you're right. the syntax is {!Goal__c.AccountId__c} and the button works as expected now.
I think I was getting an error when I tried {!Goal__r.AccountId__c}
Thanks!