tyoshikawa1106のブログ

- Force.com Developer Blog -

SFDC:Visualforceを使ったSalesforce1アクション

海外のSalesforce DeveloperがVisualforceをつかったSalesforce1アクションについてのブログを公開していたので、Dev環境で試してみました。

f:id:tyoshikawa1106:20160104225733p:plain

Salesforce1 Actions with Visualforce


上記リンク先ではリードオブジェクトのステータスを更新する処理が紹介されていました。同じようにリード状況項目の値を「Working - Contacted」に更新するアクションを試してみました。
f:id:tyoshikawa1106:20160104232632p:plain


VisualforceページとApexクラスを次のように作成します。

LeadWorkingAction.page
<apex:page standardController="Lead" extensions="LeadWorkingActionController" action="{!init}" tabStyle="Lead">
</apex:page>
LeadWorkingActionController.cls
public with sharing class LeadWorkingActionController {
   
    // リード情報
    private Lead lead = new Lead();

    /**
     * コンストラクタ
     */
    public LeadWorkingActionController(ApexPages.StandardController controller) {
        this.lead = (Lead) controller.getRecord();
    }

    /**
     * Init
     */
    public PageReference init() {
        // リード状況を更新
        this.lead.Status = 'Working - Contacted';
        update this.lead;

        return new PageReference('/' + this.lead.Id);
    }
}


Visualforceページ作成後は『Salesforce モバイルアプリケーションおよび Lightning ページでの使用が可能』にチェックをつけてSalesforce1アプリで利用できるように権限を追加します。
f:id:tyoshikawa1106:20160105003218p:plain

続いてアクションの作成です。新しいアクションは設定の「ボタン、リンク、およびアクション」から作成できます。
f:id:tyoshikawa1106:20160104233915p:plain


アクション種別に「カスタム Visualforce」を指定すると対象のVFページを選択できるようになります。
f:id:tyoshikawa1106:20160104234300p:plain


ちなみにアクションのアイコンを変更するには、静的リソースにアップしておく必要があります。
f:id:tyoshikawa1106:20160104234409p:plain


これでアクションの設定が完了です。
f:id:tyoshikawa1106:20160104234449p:plain


次は作成したアクションをページレイアウトに追加します。
f:id:tyoshikawa1106:20160104235247p:plain


これでSalesforce1アプリのアクションバーにアクションが表示されます。追加したWorking!アクションをクリックするとステータスが無事に更新されました。
f:id:tyoshikawa1106:20160105001344p:plain


ひとつうまく行かなかったのですが、更新後の画面遷移がうまく実行できませんでした。何か処理が漏れてるのかもしれません。
f:id:tyoshikawa1106:20160105001518p:plain



今回、ステータスを更新→詳細ページへ移動というアクションを試してみましたが、普通にVisualforceページを表示することも可能です。
f:id:tyoshikawa1106:20160105002428j:plain:w200

VFページを表示するとこんな感じです。
f:id:tyoshikawa1106:20160105002517j:plain:w200


アクション標準のヘッダーはapex:pageタグで『showQuickActionVfHeader="false" 』を宣言すると非表示にできます。
f:id:tyoshikawa1106:20160105002845p:plain

Visualforce カスタムアクションのアクションヘッダーの非表示

Visualforce & パブリッシャーアクション デモ動画