[Salesforce]Json 形式

Json形式

文字列

{ "name": "Tanaka" }

数値

{
  "age": 26,
  "pi": 3.14,
  "planck_constant": 6.62607e-34
}

ヌル値

{
  "name": null
}

真偽値

{
  "active_flag": true,
  "delete_flag": false
}

オブジェクト

{
  "user_info": {
    "user_id": "A1234567",
    "user_name": "Yamada Taro"
  }
}

配列

{
  "color_list": [ "red", "green", "blue" ],
  "num_list": [ 123, 456, 789 ],
  "mix_list": [ "red", 456, null, true ],
  "array_list": [ [ 12, 23 ], [ 34, 45 ], [ 56, 67 ] ],
  "object_list": [
    { "name": "Tanaka", "age": 26 },
    { "name: "Suzuki", "age": 32 }
  ]
}

jsonデータ 例

{
  "movies": [
    {"id": 1, "name": "The Godfather", "director":"Francis Ford Coppola", "rating": 9.1},
    {"id": 2, "name": "Casablanca", "director": "Michael Curtiz", "rating": 8.8}
  ]
}
[
  {
    "id": 1,
    "name": "The Godfather",
    "director": "Francis Ford Coppola",
    "rating": 9.1
  },
  {
    "id": 2,
    "name": "Casablanca",
    "director": "Michael Curtiz",
    "rating": 8.8
  }
]

[Salesforce]Visualforceページのinputfileとactionfunction

Visualforceページのinputfileとactionfunctionを同一Visualforcrページにて使用するときにポイント。

Visualforceページのinputfileとactionfunctionを同一Visualforceページで使う時に、以下のエラー発生する場合がある。

apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute.

このエラーの解決策の一つとして、actionfunctionをactionregionで囲むことです。

例えば、以下の例です。

	<apex:actionRegion >
		<apex:outputPanel id="thePanel">
			<apex:actionFunction name="theActfunc" action="{!theCtlfunc}" rerender="thePanel">
    			<apex:param name="theActprm" value="" />
			</apex:actionFunction>
		</apex:outputPanel>
	</apex:actionRegion >

[Salesforce]String.isBlankとisEmptyの動き

Salesforce のStringメッソドのisBlankとisEmptyについて例を共有します。

String emptyStr = '';
String blankStr = ' ';
String nullStr = null;

System.debug(String.isEmpty(emptyStr));  // true
System.debug(String.isEmpty(blankStr));  // false
System.debug(String.isEmpty(nullStr ));  // true
System.debug(String.isBlank(emptyStr));  // true
System.debug(String.isBlank(blankStr));  // true
System.debug(String.isBlank(nullStr ));  // true

[Salesforce]Apexトリガの二重起動退避対策

SalesforceのApexトリガで、Updateの場合に、ワークフローによる該当オブジェクトの更新による、Apexトリガが二重で起動することがあります。

それによって、予期せぬ動きが発生する場合があります。

その防止対策として、Apexトリガのハンドラークラスに、static変数を使用して、初回起動かどうかをApexトリガが判断し、二重防止を回避する。

以下はサンプルです。

--- Apexトリガのハンドラクラス ---
public class ApexTriggerHandler {
public static boolean firstRun = true;
}
--- Apexトリガ ---
trigger ApexTestTrigger on TestObject__c (before update) {
 if(p.firstRun==true){
    system.debug('1回目の起動です。');
    ApexTriggerHandler.firstRun=false;
 }else{
    system.debug('2回目の起動です。');
 }
}

[Salesforce]Apexトリガのガバナ制限について

SalesforceのApexトリガでは、ガバナ制限することができません。

対応策としては、データローダでバッチサイズを調整してガバナ制限を対応する。

バッチサイズは、1トランザクションでのガバナ制限を超えないところに、設定する。