0
0

Visualforce page のまとめ

Last updated at Posted at 2022-10-21

まとめページに戻る
まとめN~Z

できないこと

いろいろと試してみましたが、Visualforceページではレポートやダッシュボードを表示することができませんでした。また、Salesforceサポートに問い合わせたところ、やはり表示できないとのことでした。

詳しくは以下のリンクをご参照ください: Salesforceサポート記事

画面遷移させる : LEXだとgetParameters().put()が動作しない

PageReference pageReference;

if(Userinfo.getUiThemeDisplayed().equals('Theme4d')){
    //新たに追加したもの
    pageReference = new PageReference('/lightning/r/CustomObject__c/' + record.Id + '/edit?recordTypeId=' + recordType.Id + '&backgroundContext=/lightning/r/CustomObject__c/' + record.Id + '/view');
}else{
    //もともとあったもの
    pageReference = new PageReference('/' + record.Id + '/e');
    pageReference.getParameters().put('nooverride', '1');
    pageReference.getParameters().put('RecordType', recordType.Id);
    pageReference.getParameters().put('retURL', record.Id);
}

エラー

OK、解決策が見つかりました。機能は動作しているようです。 RenderAsPdf が Post-API 27 で動作しなくなったという非常に古い記事を見つけました。VF ページに HTML タグを追加する必要があります。 applyHtmlTag="false" を apex:page タグに追加する必要もあります。

OK have found the solution, seems features do work. I found a very old article where RenderAsPdf stopped working Post-API 27. You need to add a HTML tag in VF page. You will also need to add applyHtmlTag="false" to the apex:page tag.

<apex:page controller="ShowPDFReportController" renderAs="pdf" applyHtmlTag="false" name="ShowPDFReport" showHeader="false" sidebar="false" title="PDF DashBoard" standardStylesheets="false" applyBodyTag="false" action="{!LoadData}" >
<html>
    <head>      
        <style type="text/css">
            table.maintable {border: 2px solid red;border-collapse: collapse;}
        </style>
    </head>
    <apex:form >
        <table class="maintable"><tr><td class="title">Top Donors</td></tr></table><br />
    </apex:form>
</html>
</apex:page>

Solution was to amend apex page tag to include on all Visualforce pages

applyHtmlTag="false"
showHeader="false"

image.png

With the help of Salesforce Support, I found the piece of documentation that references this piece of functionality.

As documented here (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/message_channel_considerations.htm), "Visualforce supports only LightningMessageChannels where isExposed is true." This feature is working as documented.

image.png

After opening a support ticket, I learned that I had to rerun the visualforce scan by clicking on Scan for Visualforce Pages. Since changes had happened in the org since the last scan, this caused a conflict and it wasn't able to show the details of the page issues. Rerunning the scan enabled me to see the actual issues when clicking on the page issues number. Simple but not obvious fix.

サポートチケットを開いた後、[Visualforce ページのスキャン] をクリックして Visualforce スキャンを再実行する必要があることがわかりました。前回のスキャン以降に組織で変更が発生したため、競合が発生し、ページの問題の詳細を表示できませんでした。スキャンを再実行すると、ページの問題番号をクリックすると実際の問題を確認できるようになりました。シンプルですが明らかな修正ではありません。

image.png

ビューステートが170Kを超えていた

以下の方法を試してみてください

開発者コンソールの [View State (ビューステート)] タブでは、Visualforce ページ要求のビューステートを調べることができます。

https://help.salesforce.com/s/articleView?id=sf.code_dev_console_tab_view_state.htm&type=5

View State(ビューステート)とは〜対象と減らし方〜

Visualforce Basics > Using Standard Controllers

image.png

私自身はChrome(拡張機能は何にも入れてません)を使っていますが、以下を読むと Firefox あるいは IE を使えってあるのですが、今更IEはあり得ないので、Firefoxあるいはsafariを使ってみてください

What browser are you using?I was encountering this message in the dev console while I was writing some visualforce. It looks like this option is set by default for visualforce pages to help prevent clickjacking and Chrome doesn't support the ALLOW-FROM X-frame option (https://www.owasp.org/index.php/Clickjacking_Defense_Cheat_Sheet⌗X-Frame-Options_Header_Types). If this is preventing you from completing a trailhead then you could try using Firefox or IE. Or you could try adding the showHeader="false" arg to your page tag. This disables the default headers in visualforce but you may still fail the trailhead validation test depending on how the validation is calculated.

https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4DSvSAN

The static resource does not require a '/' in the image URL. If you're using a slash, try removing it and check the challenge again.

Try this

<apex:page>
<apex:image url="{!URLFOR($Resource.vfimagetest, 'cats/kitten1.jpg')}" />
</apex:page>

https://developer.salesforce.com/forums/?id=906F0000000BTKGIA4

DOMException: Failed to execute 'querySelectorAll' on 'Element': '*,:x' is not a valid selector.

「Visualforce」コンポーネントの「Visualforce ページ名」には無効な値が含まれています。

Component 'Visualforce' has an invalid value for property 'Visualforce Page Name'.

をVF Pageに追加したら解決するみたいです。

<apex:page showHeader="false" applyHtmlTag="true" applyBodyTag="false">
    <head>
        <apex:slds />
    </head>
    <body class="slds-scope" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
        <!-- Your SLDS-styled content -->
        <span class="slds-icon_container slds-icon-utility-announcement" title="Description of icon when needed">
            <svg class="slds-icon slds-icon-text-default" aria-hidden="true">
                <use xlink:href="{!URLFOR($Asset.SLDS, '/assets/icons/utility-sprite/svg/symbols.svg#announcement')}"></use>
            </svg>
            <span class="slds-assistive-text">Description of icon when needed</span>
        </span>
    </body>
</apex:page>

PDFの作成

.docx formatのファイルを作る。

残念ですができません。

I don't think you can do it with just the VF page.

DOCX is part of Microsoft Office Open XML specification (also known as OOXML or OpenXML) and was introduced with Office 2007. DOCX is a zipped, XML-based file format. Microsoft Word 2007 and later uses DOCX as the default file format when creating a new document. Support for loading and saving legacy DOC files is also included.

https://www.leadtools.com/help/sdk/v21/dh/to/file-formats-microsoft-word-document-docx-doc.html

日付のフォーマットと1日前の表示

<apex:outputText value="{0, date, MMMM d','  yyyy}">
    <apex:param value="{!contact.Birthdate - 1}" /> 
</apex:outputText>

開発

トレイルヘッド

You are absolutely correct. Visualforce pages always display with the standard Lightning Experience user interface when they run in Lightning Experience. There’s no way to suppress or alter the Lightning Experience header or sidebar. In particular, the showHeader and sidebar attributes of apex:page have no effect on Visualforce pages when displayed in Lightning Experience.

However, to pass this particular challenge you need to use showHeader attribute in visualforce page. If you don't use showHeader attribute it won't allow you to pass the challenge.

<apex:page showHeader="false" title="DisplayImage" >

    <apex:image value="https://developer.salesforce.com/files/salesforce-developer-network-logo.png" height="100" width="300" />

</apex:page>

https://developer.salesforce.com/forums/?id=9062I000000XlkjQAC

あなたは完全に正しいです。 Visualforce ページは、Lightning Experience で実行する場合、常に標準の Lightning Experience ユーザインターフェースで表示されます。 Lightning Experience のヘッダーやサイドバーを抑制したり変更したりする方法はありません。特に、apex:page の showHeader 属性とsidebar 属性は、Lightning Experience で表示される Visualforce ページには影響しません。

ただし、この特定の課題をクリアするには、visualforce ページで showHeader 属性を使用する必要があります。 showHeader 属性を使用しない場合、チャレンジに合格することはできません。

<apex:page sidebar="false">
<!--Flight Systems Checklist Visualforce Page-->
   <h1>StationStatus</h1>
   <apex:form id="stationReadinessChecklist">
      <apex:pageBlock title="Station Readiness Checklist">
         <apex:pageBlockButtons >
            <!--Adding Save Button-->
            <apex:commandButton value="Save" action="{!save}"/>
         </apex:pageBlockButtons>
      </apex:pageBlock>
   </apex:form>
</apex:page>

標準の Lead オブジェクトの VF ページリストビューボタンを作成しようとしています。フィールド名とテキストボックスの間の幅を狭くしたいのですが、実現できませんでした。

I coudnt get the style property of output text working for some reson but this worked

<div style="word-wrap:break-word; width:100px;" >     <apex:outputText value="ssssssssssssssssssssssssssssssssssssssssssssss"   ></apex:outputText>     </div>

https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4XdaSAF

vfRetURLInSFX

何か仕様が変わったような投稿がありますね。

after Summer'24 release, vfRetURLINSFX returns List view Developer name instead List view ID in the url

https://salesforce.stackexchange.com/questions/349924/capture-list-view-id-from-url

ちょっと気になる記述が... 残念ながら詳細が書いてありそうなヘルプのリンクは404エラーです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0