[Salesforce]LWC @AuraEnabled()

LWC @AuraEnabled()

LWC で Apex を利用するときは必ず @AuraEnabled()のデコレータが必要です。

public with sharing class ApiSampleController {

    @AuraEnabled(cacheable=true)
    public static Object createRecord() {
        return new Object();
    }

    @AuraEnabled(cacheable=true)
    public static Object getRecords() {
        return new Object();
    }

    @AuraEnabled(cacheable=true)
    public static Object getRecordById() {
        return new Object();
    }

    @AuraEnabled(cacheable=true)
    public static Object updateRecord() {
        return new Object();
    }

    @AuraEnabled(cacheable=true)
    public static Object deleteRecord() {
        return new Object();
    }
}

[Salesforce]RecordType Info Get

RecordType Info Get

Map<String, Map<String, Schema.RecordTypeInfo>> RECORDTYPEMAP = new Map<String, Map<String, Schema.RecordTypeInfo>>();
String sobjectStr = 'Account';
System.debug(Schema.getGlobalDescribe().get(sobjectStr).getDescribe().getRecordTypeInfosByDeveloperName());

{マスター=Schema.RecordTypeInfo[getDeveloperName=マスター;getName=マスター;getRecordTypeId=012000000000000XXX;isActive=true;isAvailable=true;isDefaultRecordTypeMapping=true;isMaster=true;]}

[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}`
  }));
}

[SalesforceDeveloperCertification]platform-developer-i-certification-maintenance-winter-24

platform-developer-i-certification-maintenance-winter-24

public class QueryContact {
  public static Id getContactID(String lastName, String title) {
    try {
      Contact myContact = Database.query(
        'SELECT ID FROM Contact WHERE lastName = :lastName AND title = :title LIMIT 1'
      );
      return myContact.Id;
    } catch (Exception ex) {
      return null;
    }
  }
  public static Id getContactIDWithBinds(Map<String, Object> bindVars) {
    //do not modify any code above this line
    //implement the logic that will use bindVars to retrieve the contact's ID
    String queryString =
        'SELECT ID FROM Contact WHERE lastName = :lastName AND title = :title LIMIT 1';
        List<Contact> Contacts = Database.queryWithBinds(
            queryString,
            bindVars,
            AccessLevel.USER_MODE
        );
      return Contacts[0].Id;
    }
    
}