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
nrwingnrwing 

Conditional Color For Visualforce Page Depending On Record Type

I am putting together basic VS pages, but want I had hoped to do is set it up so that I can change the label and color on the detail of a record (when it is first being created as well as viewed and edited) depending on the record type.  Can you do this using the visualforce and incorporating apex conditionals?  I would assume I want to use a conditional that might reference a stylesheet, but how do you do that in visualforce?
 
 
David VPDavid VP
You can include stylesheets in a VF page just as you would do with any html page.

If you want conditional logic to determine which class an element needs to use you can do something like :

Code:
In your VF page :

 <p class="{!conditionalClass}">Text here ...</p>


Controller :

public String getConditionalClass() {
        //....
        return 'myclass';
}

 

You could even use the same trick to swap the entire stylesheet based on some condition :

<apex:stylesheet value="{!somemethod}"/>

Hope this helps,


David


Message Edited by David VP on 10-13-2008 03:42 PM
nrwingnrwing
Thanks! That alone has helped a lot in pointing me in the right direction.
 
Here is my setup in VF so far. (for a different obejct in a testing environment though)
 
I haven't had to do apex conditional like this till now.  Is this something where I would need to rebuild the ENTIRE page, as it seems to be in some references, or can I just substitute the stylesheet and leave the rest of the standard Controller intact?  I am hoping to have this done within in a day or two for a presentation, so I am just curious if that is possible.
 
Also, if you could point me to a good complete example of a conditional in an Apex class please do.
 
Code:
<apex:page standardController="Job_Application__c" >
<apex:stylesheet value="/resources/htdocs/css/basic1.css"/>
    <apex:variable value="{!Job_Application__c}" var="job"/>
    <apex:variable value="{!Job_Application__c.Candidate__r}" var="candidate"/>
    <apex:form >
    <apex:pageBlock title="CPPF Opportunity" >
        <apex:pageBlockButtons >
            <apex:commandButton action="{!edit}" value="Edit"/>
            <apex:commandButton action="{!delete}" value="Garbage"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection >
            <apex:outputField value="{!job.RecordType.Name}"/>
            <apex:outputField value="{!job.Name}"/>
            <apex:outputField value="{!job.OwnerId}"/>
            <apex:outputField value="{!job.Candidate__c}"/>
            <apex:outputField value="{!job.Status__c}"/>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Candidate Information">
            <apex:outputField value="{!job.Candidate__c}"/>
            <apex:outputField value="{!Job_Application__c.Candidate__r.Phone__c}"/>
            <apex:outputField value="{!Job_Application__c.Candidate__r.First_Name__c}"/>
            <apex:outputField value="{!Job_Application__c.Candidate__r.Last_Name__c}"/>
            <apex:outputField value="{!Job_Application__c.Candidate__r.Mobile__c}"/>
            <apex:outputField value="{!Job_Application__c.Candidate__r.Email__c}"/>
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Name"/>
                <apex:outputText value="{!candidate.First_Name__c} {!candidate.Last_Name__c}"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
  <apex:relatedList list="OpenActivities"/>
    <apex:relatedList list="ActivityHistories"/>
</apex:page>

 


Message Edited by nrwing on 10-13-2008 03:54 PM


Message Edited by nrwing on 10-13-2008 03:57 PM
David VPDavid VP

Check out 'Controller Extensions' in the Visualforce Developer's guide.
You can basically leave your standard controller in place and 'extend' it with some custom logic of your own. That's where you could put a method for deciding which stylesheet you would like to render.

The conditional logic itself is basically the same as in most other languages (if  then ... return ... else return ...) ... You'll find plenty of examples of that in the docs or in this forum.



-David

nrwingnrwing
I have come across a good amount of info, a lot more than I was finding at first.  I think I could now put together a page redirect that would show a different page depending on record type for the 'view' and 'edit', at least if the discussion prove accurate....I am still trying to make that work, but feel positive about it.
 
However, I am stuck regarding how to do it for the 'new' action.  since the record doesn't exist yet, I am having issues with it recognizing a record type for a record that is 'in process' as of yet and choosing a page accordingly.
 
Would it be possible to use the 'urlfor' functionality to have it redirect to a particular page if the url contains a particular ID (the id of the record type) since that is in the url by default on the standard page?  Or, is there something else I should be looking at?  The urlfor is a little confusing to me yet, but using that with a case argument appears to be the best option so far.
 
View and Edit redirects based on record types seem possible, but finding something for the 'New' action is proving difficult.....especially  new at this anyway.  I may be biting off more than I can chew at this point.