Heroku AppLinkの使い方(DML)

Heroku AppLinkの使い方のサンプル第2弾でも。

※サンプルコードは Node.js 版のSDKを使ったものに限定です。SDKのリポジトリは https://github.com/heroku/heroku-applink-nodejs を参照してください。

1. レコードの作成

※もちろん添付ファイルを作成することも可能

import * as salesforcesdk from "@heroku/applink";


async function sample () {
  const sdk = salesforcesdk.init();
  // ※Authorized Userを使います
  const org = await sdk.addons.applink.getAuthorization(process.env.HEROKU_APPLINK_CONNECTION_NAME);

  //----------------------------------------------------------
  // (1)レコードを作成
  //  - 参照先を設定する際には、外部キーの指定も可能
  const new_record = await org.dataApi.create({
    type: "customobject__c", // オブジェクトAPI
    fields: {
      key__c: ulid(),
      text01__c: 'xxxxx',
      longtextarea01__c: description,
      num01__c: 123,
      datetime01__c: new Date().toISOString(),
      check01__c: false,
      other_object__r: { key__c: 'other_key' },
    },
  });

  //----------------------------------------------------------
  // (2)contentversionの場合も
  //   JSONファイルを作成してBase64エンコード
  const jsonData = JSON.stringify(someobject, null, 2);
  const base64Data = Buffer.from(jsonData, 'utf-8').toString('base64');
  const fileName = 'xxx.json';

  // ContentVersionを直接作成
  const contentVersionResult = await org.dataApi.create({
    type: 'ContentVersion',
    fields: {
      Title: fileName,
      PathOnClient: fileName,
      VersionData: base64Data,
      ContentLocation: 'S'
    }
  });
  
  // ContentDocumentIdを取得するためにContentVersionをクエリ
  const contentVersionQuery = await org.dataApi.query(`SELECT ContentDocumentId FROM ContentVersion WHERE Id = '${contentVersionResult.id}'`);
  const contentDocumentId = contentVersionQuery.records[0]?.fields?.ContentDocumentId;

  // ContentDocumentLinkを直接作成してレコードに関連付け
  const linkResult = await org.dataApi.create({
    type: 'ContentDocumentLink',
    fields: {
      ContentDocumentId: contentDocumentId,
      LinkedEntityId: '(record id)',
      ShareType: 'V',
      Visibility: 'AllUsers'
    }
  });
  
}

2. レコードの更新

import * as salesforcesdk from "@heroku/applink";


async function sample () {
  const sdk = salesforcesdk.init();
  // ※Authorized Userを使います
  const org = await sdk.addons.applink.getAuthorization(process.env.HEROKU_APPLINK_CONNECTION_NAME);
  
  // レコードを更新
  //  - 参照先を設定する際には、外部キーの指定も可能
  const new_record = await org.dataApi.update({
    type: "customobject__c", // オブジェクトAPI
    fields: {
      id: '(オブジェクトid)',
      text01__c: 'xxxxx',
      longtextarea01__c: description,
      num01__c: 123,
      datetime01__c: new Date().toISOString(),
      check01__c: false,
      other_object__r: { key__c: 'other_key' },
    },
  });

}

3. レコードの削除

※ type と id を指定するだけ

import * as salesforcesdk from "@heroku/applink";


async function sample () {
  const sdk = salesforcesdk.init();
  // ※Authorized Userを使います
  const org = await sdk.addons.applink.getAuthorization(process.env.HEROKU_APPLINK_CONNECTION_NAME);
  
  // レコードを削除
  const new_record = await org.dataApi.delete({
    type: "customobject__c", // オブジェクトAPI
    fields: {
      id: '(オブジェクトid)',
    },
  });

}

そんなにややこしいAPIになってないので、素直に利用できる。
が、upsert がないのが残念...

ちなみに、dataApi.insert() の中身を掘り下げていくと、こんな記述をお目にかかります。

import { Connection } from "jsforce/lib/connection";

Heroku AppLinkのNode.js SDKの内部では、stomita先生のjsforceが使われている、ということでした。さすが。

Read more

Salesforce

Salesforce コアサービスでサービス中断が発生(2026-9-16 16:50発生 2026-9-17 04:00解決)

ここ最近発生していなった大規模障害が発生しました。ちょうど日本時間の夕刻で、当社のお客様にも影響が出ていたため、本ポストを作成しました。 * AWS障害ではなく、Salesforce側の障害と思われます。 * Sandboxは実は正常だったということで修正されました。当日の状況とも合致します。 https://status.salesforce.com/incidents/20004433 以下は、日本語話者向けの妙訳です。(生成AIを利用しています。) 更新(2026-09-18 2:16) その後、当社チームが本インシデントについてさらに調査を進めた結果、Sandbox 環境は影響を受けていなかったことが判明しました。 実際の影響範囲を正確に反映するため、本投稿を更新し、Sandbox インスタンスを影響対象から除外しました。 この変更により混乱を招いた可能性があることをお詫び申し上げます。 As our teams investigated the incident further, we discovered that sandboxes were not

By Hiroki Matsumoto

Salesforce

Multi-Frameworkが運用組織で利用可能に(実質的に2026/7/9から)

Mutlti-Frameworkは2026/6/3にGAするも、Data SDKとGraphQLがGAしたのは7/9なので、実質的に動かせるのは、2026/7/9からということだった。 When: This feature is available starting June 3, 2026. Develop React Apps with Salesforce Multi-Framework (Generally Available) When: This feature is generally available starting July 9, 2026. Get Record Data in Your React Apps with Data SDK and

By Hiroki Matsumoto

Agentforce

文字起こしエージェントアクションの追加(Summer'26)

エージェントアクションにWhisper V3 Turbo (Whisper Large V3 Turboと思われる)による文字起こし機能が追加。6/22週から利用可能。 * Whisperはセルフホストっぽい。 * 5MB未満 * 話者識別やタイムスタンプはない。 電話音声だと帯域狭いから、適切な前処理すれば50分ぐらいいけるかも。MP3 64Kbpsだと10分ほどの計算になる。 Choose a Transcription Model for the Speech to Text Agent Action Use the Transcription Model parameter on the Speech to Text action to control which model converts audio to text. Choose the model

By Hiroki Matsumoto

Salesforce

Multi-FrameworkでReactAppを(内部向けアプリ)

あれ、もうGAになったのかな? 前に外部向け(Experience Cloud)のReact Appを作成してみたので、今度は内部向けも試してみる。今回はSandbox環境にデプロイして動かせるのか試してみよう。 内部向けのsfdxプロジェクトを作成 今回は --template に reactinternalapp を指定する $ sf template generate project --name wkInReactApp --template reactinternalapp npmパッケージのインストール&ビルド READMEにある通りに、作成したプロジェクトのルートディレクトリで、以下を実行する $ npm install $ npm run sf-project-setup > @salesforce/ui-bundle-template-base-sfdx-project@1.135.0 sf-project-setup >

By Takahiro Yonei