ラベル

2021-11-01

Salesforce - Schema.DescribeFieldResult


Schema.DescribeFieldResult に関するメモ書き
  • 任意のオブジェクトの項目の表示ラベルを apex で取得したい





■ Account.Name の表示ラベルを取得する 

静的

Schema.SObjectType.Account.fields.Name.label;

動的

Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().get('Name').getDescribe().getLabel();

オブジェクト:静的 / 項目:動的

Map<String, Schema.SObjectField> accountFieldMap = Schema.SObjectType.Account.fields.getMap();
String label = accountFieldMap.get('Name').getDescribe().getLabel();


ref:

2021-09-17

Salesforce - Attachment


添付ファイルに関するメモ書き
  • VFPage から任意のオブジェクトレコードに添付ファイルをアップロードしたい
  • VFPage に任意のオブジェクトレコードの添付ファイル一覧を表示したい(ファイル名のみ)





■ 添付ファイルのアップロード 

VFPage

<apex:form>

	<apex:outputLabel value="ファイル" for="file" />
	<apex:inputFile value="{!attachment.Body}" filename="{!attachment.Name}" id="file" />

	<apex:commandButton value="アップロード" action="{!doUpload}" />

</apex:form>

Apex

public class SampleController {

	private Id recordId;

	public Attachment attachment { get; set; }

	public SampleController(ApexPages.StandardController controller) {

		this.recordId = controller.getId();

		this.attachment= new Attachment();
	}

	public PageReference doUpload() {

		if(this.attachment.Body != null && String.isNotBlank(this.attachment.Name) ) {

			this.attachment.ParentId = this.recordId;

			insert this.attachment;
		}
		return null;
	}
}

■ 添付ファイル一覧の表示 

VFPage

<apex:dataList value="{!attachmentList}" var="attachment">
	<apex:outputText value="{!attachment.Name}"/>
</apex:dataList>

Apex

public class SampleController {

	private Id recordId;

	public List<Attachment> attachmentList { get; set; }

	public SampleController(ApexPages.StandardController controller) {

		this.recordId = controller.getId();

		this.attachmentList = [SELECT Id, Name FROM Attachment WHERE ParentId = :this.recordId ORDER BY CreatedDate ASC];
	}
}


ref:

2021-09-06

Salesforce - レポート


レポートに関するメモ書き
  • アクセス権の設定





■ レポートのリリース状況 

  • 設定 → ビルド → 作成 → レポートタイプ から編集可能
  • リリース状況
    • 開発中: 「カスタムレポートタイプの管理」権限を持つユーザのみアクセス可能
    • リリース済み: すべてのユーザがアクセス可能
  • ref: カスタムレポートタイプの作成 - Salesforce Help

■ レポートフォルダのアクセス権 


■ プロファイル 

  • レポートが参照するオブジェクト・項目に「参照」アクセス権があること・必要に応じて下記権限が付与されていること
  • システム管理者権限
    • 公開レポートの管理
    • すべてのデータの参照 ※ 権限を制御する場合は OFF
    • 設定・定義を参照する ※ 管理レポートの場合
  • 一般ユーザ権限
    • レポートの作成とカスタマイズ
    • レポートビルダー
    • レポートの実行

■ 共有設定 

  • レポートが参照するオブジェクトにユーザの「参照」アクセス権があること



ref:

2021-08-29

Salesforce - Visualforce - apex:selectList


apex:selectList のメモ書き
  • 任意の選択リスト型の入力項目を表示する
※ 2021/09/06: 「SelectOption」のラベルと値がの設定が逆だったため修正





■ select 

VFPage

<apex:selectList label="選択リスト" value="{!option}" size="1" >
        <apex:selectOptions value="{!options}"/>
</apex:selectList>

※ 複数選択リストにする場合は、「apex:selectList コンポーネント」に「multiselect="true"」属性を追加する
※ 「size="1"」表示される選択肢を 1 個にする

Apex

public class SampleController {

	public String option { get; set; }
	public List<SelectOption> options { get; set; }

	public SampleController(ApexPages.StandardController controller) {

		this.option = '';
		this.options = this.getSelectOption(`オブジェクト名`, `選択リストのフィールド名`);

	}

	public List<SelectOption> getSelectOption(Strin sObjectName, String fieldName) {
		List<SelectOption> retval = new List<SelectOption>();
        retval.add(new SelectOption('', '下記から選択してください。', true));	// ラベルを表示・非選択
		Schema.DescribeFieldResult f = Schema.getGlobalDescribe().get(sObjectName).getDescribe().fields.getMap().get(fieldName).getDescribe();
		List<Schema.PicklistEntry> pickList = f.getPicklistValues();
		for(Schema.PicklistEntry pick : pickList) {
			if(pick.isActive()) {
				retval.add(new SelectOption(pick.getValue(), pick.getLabel()));		// ラベルを表示・選択可能
			}
		}
		return retval;
	}

}



ref:

2021-08-27

Salesforce - Visualforce - apex:outputText


apex:outputText のメモ書き
  • 日付型の項目をフォーマット指定して表示する





■ date 

VFPage

<apex:outputText label="日付" value="{0,date,yyyy/MM/dd}" >
	<apex:param value="{!NOW}" />
</apex:outputText>



ref:

Salesforce - Visualforce - apex:input


apex:input のメモ書き
  • 任意の日付型の入力項目を表示する(入力値の最大値・最小値の制限も加える)





■ type : date 

VFPage

<apex:page docType="html-5.0" StandardController="Contact" extensions="SampleController">

<apex:input label="日付" type="date" value="{!sampleDate}" html-min="{!sampleMinDate}" html-max="{!sampleMaxDate}"  />

</apex:page>

※ 「type 属性」を使うには「apex:page コンポーネント」の「docType 属性」を指定する
※ 「html-min 属性」「html-max 属性」はパススルー属性

Apex

public class SampleController {

	public Date sampleDate { get; set; }
	public String sampleMinDate { get; private set; }
	public String sampleMaxDate { get; private set; }

	public SampleController(ApexPages.StandardController controller) {

		this.sampleMinDate = String.valueOf(System.today());
		this.sampleMaxDate = String.valueOf(System.today().addYears(1));

	}
}



ref: