LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Tuesday, February 4, 2020

Salesforce APIでCaseのコメントを取得したい


指定したCaseのコメントを取得するには
/sobjects/Case/CASE ID/CaseComments

上記のようにCASE IDを指定して/CaseCommentsで取得できました。



ここで使うCase IDとは
対象ケースを開いた時にアドレスバーのCase/の後に表示される文字列↓




事前準備

接続アプリケーションを作成して
アクセストークンなどのデータをスクリプトのプロパティに保存しておく

手順は以下のブログに書きました。

SalesforceでAPIを使うために接続アプリケーションを作成したい
Salesforceで接続アプリケーションを作成したい(Lightningの方で)



コメントを作成しておく



コード.gs
function getData() {
  var options = {
    "method" : "GET",
    "headers" : {
      "Authorization": "Bearer " + getProp("access_token")
    }
  }
  var url = getProp("instance_url") + "/services/data/v47.0/sobjects/Case/5002w000002HSlkAAG/CaseComments";
  var response = UrlFetchApp.fetch(url, options);
  Logger.log(response);
}

function getProp(key) {
  return PropertiesService.getScriptProperties().getProperty(key);
}


getData()を実行すると、以下のような結果が返ってきました。

実行結果
{
  "totalSize": 1,
  "done": true,
  "records": [{
    "attributes": {
      "type": "CaseComment",
      "url": "/services/data/v47.0/sobjects/CaseComment/00a2w000000DatqAAC"
    },
    "Id": "00a2w000000DatqAAC",
    "ParentId": "5002w000002HSlkAAG",
    "IsPublished": false,
    "CommentBody": "最初のコメント。",
    "CreatedById": "0052w000001oTfEAAU",
    "CreatedDate": "2020-02-03T02:30:43.000+0000",
    "SystemModstamp": "2020-02-03T02:30:43.000+0000",
    "LastModifiedDate": "2020-02-03T02:30:43.000+0000",
    "LastModifiedById": "0052w000001oTfEAAU",
    "IsDeleted": false
  }]
}


関連記事

SalesforceでAPIを使うために接続アプリケーションを作成したい
Salesforceで接続アプリケーションを作成したい(Lightningの方で)


参考

レコードの操作
https://developer.salesforce.com/docs/atlas.ja-jp.222.0.api_rest.meta/api_rest/using_resources_working_with_records.htm

サンプルコードを実行する
https://developer.salesforce.com/docs/atlas.ja-jp.222.0.api_rest.meta/api_rest/quickstart_code.htm

Latest post

スプレッドシートA列にある複数のテキストをスライドに追加したい(Google Apps Script)

今回Google Apps Scriptでやりたいこと GoogleスプレッドシートA列にある複数の値を取得して Googleスライドに渡して 図形オブジェクトのテキストとして追加したい ① スプレッドシートのA列に値を入れておく ② Code.gsのinsertNewShape...