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
徹 竹井徹 竹井 

VISUALFORCEを使った日本語PDF出力での改行を行うコードのリリースができない

ネットの情報を参考にしながら、visualforceで日本語pdf出力で改行できない問題を改行コード<wbr />を入れて解決するクラスを作ってみたのですが、sandboxでは動くのですが、本番リリースでうまくいきません。IDに関連するeventの情報を取ってきて、時系列にpdf上に表示するvisualforcepageを別に用意しています。初心者なもので、何を修正したらカバー率が上がるかわからず、アドバイス頂けると助かります。

visualforce class  ShowAllSObjectActivityKaig
public class ShowAllSObjectActivityKaig {
Id sObjectname= ApexPages.currentPage().getParameters().get('Id');

public list<Event> tasklist{get;set;}
public list<Event> namae{get;set;}
public  ShowAllSobjectActivityKaig(){
if(sObjectname !=null )

namae= [select id,ActivityDateTime,StartDateTime,Field6__c,Field5__c,Field1__c,Subject,Type,Field2__c,Who.Name,What.Name,Description,LastModifiedDate,Owner.Name FROM Event WHERE WhatID=:sObjectname OR whoId=:sObjectname order by startdatetime asc
LIMIT 1];

tasklist= [select id,ActivityDateTime,StartDateTime,Field6__c,Field5__c,Field1__c,Subject,Type,Field2__c,Who.Name,What.Name,Description,LastModifiedDate,Owner.Name FROM Event WHERE WhatID=:sObjectname OR whoId=:sObjectname order by startdatetime asc
];


//一文字ずつクラスを参照し、返す
//参加者
for(Event a : tasklist){
a.Field1__c = kaigyo(a.Field1__C,1);
}
//内容
 for(Event a : tasklist){
 a.Description = kaigyo(a.Description,1);
 }
}

public PageReference cancel() {
PageReference ldPage = new PageReference('/'+sObjectname);
ldPage.setRedirect(true);
return ldPage;
}
//指定位置にwbrコードを入れる
public String kaigyo(String value, Integer posLength )
    { 
    if(value == null || value.length() <= posLength) return value; 
    String rtnValue = value.substring(0, posLength ) + '<wbr/>'; 
    for(Integer i = posLength; i < value.length(); i++)
        {
        if(Math.mod(i, posLength ) == 0)
            { 
            if(value.length() > i + posLength)
                { 
                rtnValue += value.substring(i, i + posLength ) + '<wbr/>';
                }
                else
                { 
                rtnValue += value.substring(i,value.length());
                }
               //  kaigyoCount[col]++; 
             }
        }
        return rtnValue;
    }
}
visualforce page 
 
<apex:page controller="ShowAllSObjectActivityKaig" standardStylesheets="false"

 showHeader="false"
 sidebar="false"
 applyHtmlTag="false"
 renderAs="pdf">
<head>
 <style>
  @page {
    size: 8.27in 11.69in;
    padding: 0;
  }
  body {
    font-family: Arial Unicode MS;
    font-size: 10pt;
    text-align: left;

  }
  
table.type01 {
    width: 650px;
    table-layout:fixed;
    word-wrap: break-word;
    border-collapse: collapse;
    text-align: left;
    line-height: 1.2;
    margin-left:15px;
}
table.type01 th {
    width: 150px;
    padding: 2px;
    font-weight: bold;
    vertical-align: top;
    border: 1px solid #333;
}
table.type01 td {
    width: 500px;
    padding: 2px;
    vertical-align: top;
    border: 1px solid #333;
}





  
</style>
  
    
 </head>
<h2>
<center>相談支援記録</center></h2>
<table class="type01" >
<tbody>
<tr>
<th>

<br></br>
</th>
<td><apex:repeat value="{!namae}" var="item">
(<apex:outputText value="{!item.Who.Name}"/>)
[<apex:outputText value="{!item.What.Name}"/>]
</apex:repeat> 
</td>
</tr>
<apex:repeat value="{!tasklist}" var="oSobject">
<tr>                 
<th><apex:outputText value="{!oSobject.Field6__c}" />
    <br>
    <apex:outputText value="{0,date,HH:mm}">
    <apex:param value="{!oSobject.startdatetime}"/></apex:outputText>
    </br>
    <br><apex:outputText value="(種){!oSobject.Subject}" /></br>
    <br><apex:outputText value="(所){!oSobject.Field2__c}" /></br>
    <br><apex:outputText value="(参){!oSobject.Field1__c}" escape="false" /></br>
</th>

<td><apex:outputText value="{!oSobject.Description}" escape="false" /></td></tr>     
                  
</apex:repeat>                    
</tbody>
</table>  
</apex:page>



 
Best Answer chosen by 徹 竹井
Taiki YoshikawaTaiki Yoshikawa
処理は実行できていて後はテストクラスだけという感じでしょうか。こんな感じの処理で各処理を最低限通すことができると思います。
@isTest
private class ShowAllSObjectActivityKaigTest {
    
    private static User testAdminUser = [SELECT Id FROM User WHERE Id =: UserInfo.getUserId() LIMIT 1];
    
    static testMethod void ShowAllSobjectActivityKaigTest1() {
        System.runAs(testAdminUser) {
            ShowAllSobjectActivityKaig cls = new ShowAllSobjectActivityKaig();
        }
    }
    
    static testMethod void cancelTest1() {
        System.runAs(testAdminUser) {
            ShowAllSobjectActivityKaig cls = new ShowAllSobjectActivityKaig();
            cls.cancel();
        }
    }
    
    static testMethod void kaigyoTest1() {
        System.runAs(testAdminUser) {
            ShowAllSobjectActivityKaig cls = new ShowAllSobjectActivityKaig();
            String value = '';
            Integer posLength = 0; 
            cls.kaigyo(value, posLength);
        }
    }
}

あとはテストデータを用意した版の処理を用意して同じように処理を実行することでカバー率を増やしていけると思います。

All Answers

Taiki YoshikawaTaiki Yoshikawa
処理は実行できていて後はテストクラスだけという感じでしょうか。こんな感じの処理で各処理を最低限通すことができると思います。
@isTest
private class ShowAllSObjectActivityKaigTest {
    
    private static User testAdminUser = [SELECT Id FROM User WHERE Id =: UserInfo.getUserId() LIMIT 1];
    
    static testMethod void ShowAllSobjectActivityKaigTest1() {
        System.runAs(testAdminUser) {
            ShowAllSobjectActivityKaig cls = new ShowAllSobjectActivityKaig();
        }
    }
    
    static testMethod void cancelTest1() {
        System.runAs(testAdminUser) {
            ShowAllSobjectActivityKaig cls = new ShowAllSobjectActivityKaig();
            cls.cancel();
        }
    }
    
    static testMethod void kaigyoTest1() {
        System.runAs(testAdminUser) {
            ShowAllSobjectActivityKaig cls = new ShowAllSobjectActivityKaig();
            String value = '';
            Integer posLength = 0; 
            cls.kaigyo(value, posLength);
        }
    }
}

あとはテストデータを用意した版の処理を用意して同じように処理を実行することでカバー率を増やしていけると思います。
This was selected as the best answer
徹 竹井徹 竹井
ご回答ありがとうございました。いただいたテストクラスをセットし、検証した所、カバー率クリアし、無事リリースまで
できそうです。感謝します。