You need to sign in to do that
Don't have an account?
finalist
Force.com Cookbook: Chapter 1 - Example code failure
I'm working my way through the cookbook and am running into an issue with the 'Building a Table of Data' example. I created a class and a VisualForce page with the example code but the class won't save - the error is 'Save error: Return value must be of type: Account'
public class mySecondController {
public Account getAccount() {
return [select id, name,
(select id, firstname, lastname
from Contacts limit 5)
from Account where id =
:System.currentPageReference()
.getParameters().get('id')];
}
public String getName() {
return 'My Second Custom Controller';
}
}
p.s. is there a wiki section for the Cookbook et.al.? That would be a great way to address issues and provide support - I'm just sayin'
Message Edited by finalist on 11-09-2008 02:47 PM
public class mySecondController {
public Account getAccount() {
return [select id, name,
(select id, firstname, lastname
from Contacts limit 5)
from Account where id =
:System.currentPageReference()
.getParameters().get('id')];
}
public String getName() {
return 'My Second Custom Controller';
}
}
p.s. is there a wiki section for the Cookbook et.al.? That would be a great way to address issues and provide support - I'm just sayin'
Message Edited by finalist on 11-09-2008 02:47 PM
-Jason
Message Edited by TehNrd on 11-09-2008 07:40 PM
I think that the goal of the exercise is to return a single Account record and 5 associated Contact records; the Contacts should be in a related list, and the VisualForce page is set up to handle that. I did find a wiki page for this example, and apparently the code hasn't changed since the previous version of the Cookbook, but the error is still cropping up.
(unfortunately, I cannot find the wiki page today; at least, not the one with the class definition)
Here is the link to the VisualForce page definition: Table of data.page
I'm curious as to that error you are getting. Are you doing anything else on that page?
The code you posted works just fine (I just pasted it in and it compiles for me).
I wonder. When you go to setup->develop->apex classes->mysecondcontroller and edit the apex class, what is the API version set to? Try setting it to 14.0 if it isn't already. LMK if that helps... (We'll be making a home for the new cookbook on the wiki soon)
Regards,
Jon
I have not made any changes to the example code at all - I created one Apex Class and one VisualForce page and neither one is compiling w/o an error. I checked the API version as you suggested and it is 14.0.
Here is the entirety of the class definition:
public class mySecondController {
public Account getAccount() {
return [select id, name, (select id, firstname, lastname from Contacts limit 5)
from Account where id = :System.currentPageReference().getParameters().get('id')];
}
public String getName() {
return 'My Second Custom Controller';
}
}
(the page details do not appear correctly if I paste them in -- no 'Code' options in editor)
The errors in Eclipse are:
(x)Save error: Return value must be of type: Account (from the class)
(x)Save error: Unknown property 'mySecondController.account' (from the page)
I am also getting 2 warnings re: File only saved locally, not to server, but I do have some information that was saved to the server (perhaps when the class and page were first created?) - I will see if it works correctly if I make the changes inside of Salesforce directly rather than in Eclipse.
-- update after trying same code inside of Salesforce directly - nope:
I am still getting an error:
Error: Compile Error: Return value must be of type: Account at line 3 column 9
Api Version 14.0
Message Edited by finalist on 11-11-2008 07:52 AM
(x)Save error: Return value must be of type: Account (from the class)
The other error is because your class is not saving and the page does not see the method because it does not yet exist.
x)Save error: Unknown property 'mySecondController.account' (from the page)
I would try deleting both and then starting from scratch. Sounds like you may be doing this in eclipse? I would try doing this all in the UI but make sure your user setting has the Developer Mode checkbox enabled. First create the page by using the in browser wizard by entering the URL server.salesforce.com/apex/mySecondPage. Once created in the page tag add the attribute controller="mySecondControlller". This will automatically create the class and then you can edit them side by side.
Message Edited by TehNrd on 11-11-2008 08:54 AM
I'll keep trying though -- there must be something that I'm doing out of sequence ..?
argh -- nope. The only other thing that I have done is to enable sites, so that Salesforce is prepending my sitename to the front of all my new page and class/controller attempts. Aside from that, however, I am entering the code exactly as it appears in the Cookbook.
Message Edited by finalist on 11-11-2008 09:54 AM
If it works the very last line should say DEBUG - Success
Thanks, Jill! I honestly don't know where that came from - I hacked around trying different projects while in the Developer Lounge at DreamForce, I must've added it all unbeknownst. Thanks for the suggestion!
It sounds like you have the exact same problem as the post above yours... do you have an apex class in your dev org called Account? If so, your query is returning the Account object but your method signature is referring to the Account apex class, so that's why there's a mismatch.