You need to sign in to do that
Don't have an account?
First Custom Controller..... but receiving 'List has no rows for assignment to SObject' error
Hello... this is my first attempt at a custom controller. The purpose is to get user and contact information from a Custom Controller based on the User object. I recieve the following error:
'System.QueryException: List has no rows for assignment to SObject'
at the ' private final User user; ' statement. This was pretty much out of the Apex Developer guide for Custom Controllers but I'm obviously missing something because I can't get past this error.
Thanks for looking.
Regards,
public class CPcontroller {
private final User user;
private final Contact contact;
private final Case c;
public CPcontroller() {
user = [select id,Name,ContactId,TimeZoneSidKey,Account_Sharing__c, Title, CompanyName,Phone,Extension,Fax,MobilePhone,
Email,Street,City,State,Country,PostalCode,CurrencyIsoCode from User where Id =
:ApexPages.currentPage().getParameters().get('Id') ];
contact = [select id, Name,Email,Phone,Fax,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry,Title,
ContactAccountName__c from Contact where Id = :user.Contactid] ;
}
public User getUser() {
return user;
}
public Contact getContact() {
return contact;
}
public PageReference save() {
update user;
update contact;
return null;
}
}
Hello, I'm not sure how to answer this question. This custom controller is running from within Customer Portal and is replacing the standard 'My Profile' link that a CP user would see. So if my test user is logged in then the URL looks like this in our sandbox:
https://c.cs1.visual.force.com/apex/Cases_No_Edit?sfdc.tabName=01rS00000004gEK
Is this what you meant?
Regards,
Your code is looking for a parameter named Id.
ApexPages.currentPage().getParameters().get('Id')
Your URL doesn't have that parameter.
I thought I had that taken care of here:
user = [select id,Name,ContactId,TimeZoneSidKey,Account_Sharing__c, Title, CompanyName,Phone,Extension,Fax,MobilePhone,
Email,Street,City,State,Country,PostalCode,CurrencyIsoCode from User where Id =
:ApexPages.currentPage().getParameters().get('Id') ];
private final string User = ApexPages.currentPage().getParameters().get('id');
Regards,
ApexPages.currentPage().getParameters().get('id') = NULL
Because in this URL there is no id parameter
https://c.cs1.visual.force.com/apex/Cases_No_Edit?sfdc.tabName=01rS00000004gEK
The URL I mentioned earlier is the link in Customer Portal that is shown prior to hitting the link to 'my Profile' ( which fires the custom contoller).
I went back and tried this using a controller Extention on the User object instead of a custom contoller and this works except that contact information will not be passed to the CP user because of our Sharing rules.... hence the need for this custom contoller. The point I'm making is that when I use the extension controller the URL is:
https://c.cs1.visual.force.com/apex/Symyx_CP_Welcome_Message?id=005S0000000OqSH
So I think my Custom Controller will need the user Id just like it's shown when I'm using a controller extension. So I'm still stuck and how to I pass the user Id to my custom cotroller. Hopefully I made this a little clearer.... I don't think I did before.
Regards,