I have a VF page with a controller that allows user to input time sheets against a pay run (custom objects) This is testing well. I would like to be able to display the current week of the year at the top of the page so they know what week this entry is for. I have a formula for current 'week of the year' on the time sheet object but I am not sure how display this to user prior to the the actual Time sheet record getting created .

page currently

I tried to just drop a page section pointing to the custom field as a apex:outputField value but looks like the system doesn't regnoise it because Its not a standard controller ,

So the question is how am I am able to add the custom formula field into my controller so that I can drop it on to my VF page ?

<apex:page controller="AddingChildControllerv2" >
    <apex:form >
        <apex:variable var="rowNum" value="{!0}" />
        <apex:pageBlock >
            <apex:variable var="rowNum" value="{!0}" />
            <apex:PageBlockTable value="{!childList}" var="int">
            <apex:facet name="footer">
                <apex:commandLink value="Add" action="{!insertRow}"/>
                <apex:column headerValue="Pay Run">
                    <apex:inputField value="{!int.Pay_Run__c}"/>                                      

                <apex:column headerValue="Lead Generator">
                    <apex:inputField value="{!int.Lead_Gen__c}"/>                                      

                <apex:column headerValue="Monday">
                <apex:inputField value="{!int.Monday__c}"/>
                <apex:column headerValue="Tuesday">
                <apex:inputField value="{!int.Tuesday__c}"/>
                <apex:column headerValue="Wednesday">
                <apex:inputField value="{!int.Wednesday__c}"/>
                <apex:column headerValue="Thursday">
                <apex:inputField value="{!int.Thursday__c}"/>
                <apex:column headerValue="Friday">
                <apex:inputField value="{!int.Friday__c}"/>
                 <apex:column headerValue="Delete">
                <apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}">
                    <apex:param value="{!rowNum}" name="index"/>
                    <apex:variable var="rowNum" value="{!rowNum+1}"/>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!insertChild}"/>



public class AddingChildControllerv2 {
    Id parentId;
    public List<Time_Sheets__c> childList {get;set;}
    public Integer rowNum{get;set;}

    public Pay_Run__c Parent {get;set;}

    public AddingChildControllerv2(){
        Id childId = ApexPages.currentPage().getParameters().get('childId');
        childList = new List<Time_Sheets__c>();
        childList.add(new Time_Sheets__c());


    public pagereference insertChild(){
        insert childList;

        Pagereference parentPage;
        if(!childList.isEmpty() && !string.isBlank(childList[0].Pay_Run__c))
            parentPage=new pagereference('/'+childList[0].Pay_Run__c);
        return parentPage;
    public void insertRow(){
        childList.add(new Time_Sheets__c());
    public void delRow(){
        rowNum = 

  • What formula are you using to get the "current week"? Can you not do this calculation in your apex controller? developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… Could use "toStartOfWeek" to pull start of the week (note: difference for US locale vs. european) Oct 2, 2019 at 0:21
  • thanks @KrisGoncalves the formula looks like this IF( CEILING( ( DATEVALUE(CreatedDate) - DATE( YEAR( DATEVALUE(CreatedDate) ), 1, 1) + 1) / 7) > 52, 52, CEILING( ( DATEVALUE(CreatedDate) - DATE( YEAR( DATEVALUE(CreatedDate) ), 1, 1) + 1) / 7) ) Oct 2, 2019 at 2:20

1 Answer 1


As I understand it, you want to show the week of the year for the moment the user is punching the timesheets. If that's the case, you could calculate it on your controller, storing it on an Integer property and show it as an <apex:outputText> (not a field).

Here's the snippet for that:

Controller Changes

public class AddingChildControllerv2 {
    /** your other class properties **/

    public Integer weekOfYear {get; set;}

    public AddingChildControllerv2(){
        /** other stuff **/
        Integer dayOfYear = Date.today().dayOfYear();
        weekOfYear = Math.mod(Math.ceiling(dayOfYear / 7), 52) + 1;

Visualforce Changes

Just include something like this before your PageBlockTable

<apex:outputText value="Current Week: {0}">
    <apex:param value="{!weekOfYear}" />

You must log in to answer this question.

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