0

I have the following method implemented in my controller class:

public String buildTemplate(Task task) {

    Id taskId = task.Id;

    List<Task_History__c> listTaskHistory = [SELECT Field1, Id, Field2, Username__c, LastModifiedDate FROM Task_History__c WHERE Task_ID__c = :taskId];
    String pageHTMLContent = '<HTML><HEAD><STYLE>table.css_class , .css_class th, .css_class td { border: 1px solid black; padding: 10px; } table.css_class th { text-align: center; } </STYLE></HEAD><BODY><TABLE class="css_class">';
    pageHTMLContent += '<TR><TH>Comment1</TH><TH>Comment2/TH><TH>Last Modified By</TH><TH>Last Modified Date</TH>';

    for(Task_History__c taskHistory :listTaskHistory) {
        String oldValue = taskHistory.Old_Value__c;
        String newValue = taskActivityHistory.New_Value__c;
        String userName = taskActivityHistory.Username__c;
        DateTime lastModifiedByDate = taskActivityHistory.LastModifiedDate;
        pageHTMLContent += '<TR>';
        pageHTMLContent += '<TD>' + oldValue + '</TD><TD>' + newValue + '</TD><TD>' + userName + '</TD><TD>' + lastModifiedByDate + '</TD>';
        pageHTMLContent += '</TR>';
    }

    pageHTMLContent += '</TABLE></BODY></HTML>';

    return pageHTMLContent;
}

I'd like to move the css "String pageHTMLContent = 'table.css_class , .css_class th, .css_class td { border: 1px solid black; padding: 10px; } table.css_class th { text-align: center; } ';" part in the Visual Force page

<apex:page standardController="task" extensions="TaskHistoryController">
  <apex:form >
   <apex:pageBlock >
       <apex:pageMessages escape="false"/> 
    </apex:pageBlock>
  </apex:form>   
</apex:page>

or to an external file?

Could you please give an example how the css would look when implemented in vf page or an external file?

1 Answer 1

3

The Trailhead module on Visualforce has, about halfway down the page, an example of how to declare an <apex:styleSheet>:

    <apex:stylesheet value="{!
      URLFOR($Resource.jQueryMobile,'jquery.mobile-1.4.5/jquery.mobile-1.4.5.css')}"/>

You would replace the references to jQuery with the name of the Static Resource that you've uploaded (as a ZIP file), and the path to your CSS file within the Static Resource.

More details are to be found in the Visualforce Developer Guide.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .