Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Custom controller to display related records
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Custom controller to display related records
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-12-2012 01:10 PM
So, what I'd like to do in my controller is query the current user id, pull the related contactid from that user, and display all Applications related to that Contact ID. (is there an easier way to do this?) Here is my code, but it doesn't seem to be working:
public class CurrentApps {
String userid = UserInfo.getUserId();
User firstuser;
public List<User> getCurrentUser(){
//Declare a new list
List<User> CurrentUser = new List<User>();
//Set the list equal to the results of the SOQL query
CurrentUser =
[SELECT
FirstName, LastName, ContactId
FROM User
WHERE Id =:userid ];
firstuser = CurrentUser.get(0);
//Return the List
return CurrentUser;
}
public List<Application__c> getUserApps(){
//Declare a new list
List<Application__c> UserApps = new List<Application__c>();
//Set the list equal to the results of the SOQL query
UserApps =
[SELECT
Name
FROM Application__c
WHERE Contact__c =:firstuser.ContactId ];
//Return the List
return UserApps;
}
}
Solved! Go to Solution.
Re: Custom controller to display related records
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-13-2012 01:06 AM
Hi,
You can update your code as follows.
public class CurrentApps {
String userid = UserInfo.getUserId();
public List<Application__c> getUserApps(){
User CurrentUser = new User();
CurrentUser = [SELECT FirstName, LastName, ContactId FROM User WHERE Id =:userid];
//Declare a new list
List<Application__c> UserApps = new List<Application__c>();
//Set the list equal to the results of the SOQL query
UserApps = [SELECT Name FROM Application__c WHERE Contact__c =:CurrentUser.ContactId ];
//Return the List
return UserApps;
}
}
Re: Custom controller to display related records
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-13-2012 08:54 AM
Works great...thank you!

