function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jim BoudreauxJim Boudreaux 

Accessing User Info from Apex

I created a custom field called theme__c in the User Object.
I created a custom object called Theme__c with fields listing the colors for various parts of my VF page.
I created a VF page using a custom apex controller and used fields from the Theme__c Object to fill in the CSS color values.

My problem now lies in accessing the custom field theme__c in the User Object in order to retrieve the color fields in the theme__c Object.

Here is what I tried:

public theme__c getTheme(){
string usertheme = User.theme__c;
theme__c theme = [select bg_color__c, primary_color__c, accent_color__c from theme__c where name = :usertheme];
return theme;
}

I get an error because User.theme__c is of a datatype SObject field and I am trying to cast it as a string.

What up with that?

Message Edited by Jim Boudreaux on 12-05-2008 06:54 AM
Best Answer chosen by Admin (Salesforce Developers) 
ForcecodeForcecode
Code:
string usertheme = [select theme__c from User where id = :UserInfo.getUserId()].theme__c;


 

 

All Answers

ForcecodeForcecode
Code:
string usertheme = [select theme__c from User where id = :UserInfo.getUserId()].theme__c;


 

 

This was selected as the best answer
Jim BoudreauxJim Boudreaux
That worked perfectly, thank you very much!