[Salesforce]querySelector()

querySelector()

querySelector()とは、DOM要素を検索するためのメソッドの1つ。
LWC コンポーネントの DOM 要素を取得するために、this.template.querySelector を使用することができます。
これによってどのコンポーネントのDOM要素を取得するのかを指定できます。
要するに、どのコンポーネントのJavascriptから要素を取得するかを指定するものです。

html
<template> 
  <div>AAAAA</div> 
  <div>BBBBB</div> 
</template> 

import { LightningElement } from 'lwc'; 

export default class Example extends LightningElement { 
  renderedCallback() { 
    this.template.querySelector('div'); // return <div>AAAA</div>
    this.template.querySelector('span'); // return null 
    this.template.querySelectorAll('div'); // return [<div>AAAA</div>, <div>BBBB</div>] 
  } 
}

[Technical terms]DOM(Document Object Model)

DOM(Document Object Model)

DOMとはドキュメントオブジェクトモデル (Document Object Model)の略で、Webページの要素やコンテンツなどをツリー構造で表現したデータモデルのことです。

DOMのツリー構造

HTMLの階層に合わせて要素がツリー構造になっています。html、body、h2などの要素はそれぞれオブジェクトです。全てのオブジェクトはツリーの一番上にあるDocumentオブジェクトに含まれています。

[HubSpot]Google App Scriptで会社取得

Google App Scriptで会社取得

const BU = 'https://api.hubapi.com';
const props = PropertiesService.getScriptProperties().getProperties();

function myFunction() {
  const endpoint = `${BU}/crm/v3/objects/companies`;
  const options = {
    'method': 'get',
    'headers' : {
      'Content-Type' : 'application/json',
      'Authorization': 'Bearer '+ props.AT
    },
  };
  const response = UrlFetchApp.fetch(endpoint, options);
  const responseContent = JSON.parse(response.getContentText());
  console.log(responseContent['results'].map(v => {
    return `${v.id}: ${v.properties.name}`
  }));
}