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
yuukiyuuki 

日付の計算について

カスタムオブジェクトの選択リスト項目に項目履歴管理の設定をしていて、

Visualforceページで、その期間を表示させるようにしたいと思っています。

 

しかし、日付の計算が出来なくて困っています。

一応、以下のように作成しています。

 

【コントローラ】

public class statusController {


    public List<CustomObject2__History> getCustomObject2_History(){
   
        return [SELECT Id, ParentId, CreatedDate, Field, OldValue, NewValue
                                    FROM CustomObject2__History where ParentId = 'a00A00000030p0s' order by ParentId];
    }
   
    public Integer differneceDays(){
   
        CustomObject2__History[] x = [select CreatedDate from CustomObject2__History

                         where ParentId = 'a00A00000030p0s' order by ParentId];
        Datetime i = x[0].CreatedDate;
        Datetime a = x[1].CreatedDate;
        Double y = a.getTime() - i.getTime();
        Integer u = Math.round(y);
        return u;
    }
}

 

【Visualforce】

<apex:page controller="statusController">
   
    <apex:sectionHeader title="問合せ履歴" subtitle="ステータス"/>   
    <apex:form >
   
        <apex:pageBlock >
        <apex:pageBlockTable value="{!customobject2_history}" var="u">
            <apex:column >
                <apex:facet name="header">受付履歴ID</apex:facet>
                <apex:outputField value="{!u.ParentId}"/>
            </apex:column>
           
            <apex:column >
                <apex:facet name="header">ステータス更新日</apex:facet>
                <apex:outputField value="{!u.CreatedDate}"/>
            </apex:column>
       
            <apex:column >
                <apex:facet name="header">前の値</apex:facet>
                <apex:outputField value="{!u.OldValue}"/>
            </apex:column>
           
            <apex:column >
                <apex:facet name="header">今の値</apex:facet>
                <apex:outputField value="{!u.NewValue}"/>
            </apex:column>

 

    <apex:column >
                <apex:facet name="header">期間</apex:facet>
                <apex:outputField value="{!differneceDays}"/>
            </apex:column>
            
        </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>

</apex:page>

 

 

 

また、Visualforceページに値が上手く渡せず、何も表示されません。

何か良い方法はありませんでしょうか。

 

ご教授頂けると幸いです。

 

宜しくお願いいたします。