[Salesforce]superキーワード

superキーワードは、親クラスのコンストラクタおよびメソッドを上書きできます。

例えば、次のクラスがあるとします。

public virtual class SuperClass {
    public String mySalutation;
    public String myFirstName;
    public String myLastName;

    public SuperClass() {

        mySalutation = 'Mr.';
        myFirstName = 'Carl';
        myLastName = 'Vonderburg';
    }

    public SuperClass(String salutation, String firstName, String lastName) {

        mySalutation = salutation;
        myFirstName = firstName;
        myLastName = lastName;
    }

    public virtual void printName() {

        System.debug('My name is ' + mySalutation + myLastName);
    }

   public virtual String getFirstName() {
       return myFirstName;
   }
}

Superクラスを拡張して、サブクラスで使います。

public class Subclass extends Superclass {
  public override void printName() {
        super.printName();
        System.debug('But you can call me ' + super.getFirstName());
    }
}

Subclass.printName をコールした場合に期待される出力は、「My name is Mr. Vonderburg. But you can call me Carl」です。

[Salesforce]switch構文

switch構文は次のとおりです。

switch on expression {
    when value1 {		// when block 1
        // code block 1
    }	
    when value2 {		// when block 2
        // code block 2
    }
    when value3 {		// when block 3
        // code block 3
    }
    when else {		  // default block, optional
        // code block 4
    }
}

switch on i {
   when 2 {
       System.debug('when block 2');
   }
   when -3 {
       System.debug('when block -3');
   }
   when else {
       System.debug('default');
   }
}

switch on i {
   when 2, 3, 4 {
       System.debug('when block 2 and 3 and 4');
   }
   when 5, 6 {
       System.debug('when block 5 and 6');
   }
   when 7 {
       System.debug('when block 7');
   }
   when else {
       System.debug('default');
   }
}

switch on someInteger(i) {
   when 2 {
       System.debug('when block 2');
   }
   when 3 {
       System.debug('when block 3');
   }
   when else {
       System.debug('default');
   }
}

[Salesforce Recommended Plugins]Salesforce Change Set Turbo使い方

Salesforce Change Set Turbo使い方

・Classicモードで開きます。

・送信変更セットを開きます。

・変更セットの「追加」ボタン押下します。

・「コンポーネントの種類」を「カスタム項目」に変更します。

EditModeにて「upload commponent from csv」ボタン押下いて、以下のuploadtest.csvをUploadすると変更セットに追加されます。

Name,API,Type,Type API
test1,test1__c,testobj,testobj__c

その追加されたのを「View Mode」で確認できます。

[C言語]PCでgccコンパイル環境構築から実行までの流れ

PCで環境構築から実行までの流れ

gccコンパイラダウンロード

https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/sjlj/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0.7z/download

ダウンロードしたのを展開します。

システム環境変数Pathに、展開先が以下のフォルダの場合、以下のように追加します。

C:\Users\PC\Downloads\x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0\mingw64\bin

コマンドプロンプトでgccバージョン確認します。

gcc –version

c言語ファイルを作成します。

ファイル名:test.c

#include <stdio.h>
 
int main(void) {
    char str1[12] = "Hello World";
    char str2[10] = "Yokkaichi";
    printf("%s  ", str1);
    printf("%s\n", str2);
 
    return 0;
}

test.c保存先へ移動します。例)保存先が、c:\gcc\test.cの場合

gccでコンパイルします。

実行ファイルを実行します。

[Windows]システム環境変数の設定ができなくなった場合の対処

システム環境変数の設定ができなくなった場合の対処

PowerShell管理者で Start C:\Windows\system32\rundll32.exe sysdm.cpl, EditEnvironmentVariables と入力

手順

  1. スタートメニューを右クリックして、Powershell(管理者)を呼び出す。
  2. コマンドで、コントロールパネルの環境変数の設定 を実行する
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

新しいクロスプラットフォームの PowerShell をお試しください https://aka.ms/pscore6

PS C:\WINDOWS\system32> Start C:\Windows\system32\rundll32.exe sysdm.cpl, EditEnvironmentVariables

[Salesforce]Salesforceのディスク容量の計算

Salesforceのディスク容量の計算

組織のエディションとユーザライセンスの数によってディスク容量は決まります。

計算式は「組織のエディションによって決まる固定ストレージ」+「ユーザライセンス数にして比例して追加されるストレージ」です。

データストレージはオブジェクトのレコードを格納する容量です。

Salesforceでは一部のオブジェクトを除いて1レコード2KBです。

データストレージの容量と組織で使用を想定しているレコード数が分かれば、容量が十分かどうかを確認することができます。

ファイルストレージは関連ファイルなどにアップロードするファイルを格納する容量です。

ファイルストレージ容量と組織で扱うファイル数・サイズが分かれば、容量が十分かどうかを確認することができます。

[Salesforce]Lightning Web ComponentからApex呼び出し方法

Lightning Web ComponentでApex呼び出し方法

■LWCから呼び出せるApexメソッド

条件

  @AuraEnabledがついていること

  staticであること

  publicもしくはglobalであること

例)

Apexクラス作成します。

testController

public with sharing class testController {
    @AuraEnabled
    public static List<test__c> getRecord( String str ){
        return [
                SELECT
                 Id,
                 Name
                FROM test__c
                Where Name = str
            ];
    }
}

■LWCからApex呼び出し

・Javascript

testLwc.js

import { ShowToastEvent } from "lightning/platformShowToastEvent";
import { CurrentPageReference } from "lightning/navigation";
import getRecord from '@salesforce/apex/testController.getRecord';

export default class testLwc extends LightningElement {

 @api recordId;

  @wire(CurrentPageReference)
  async getStateParameters(currentPageReference) {
    //ScreenActionの場合、レコード詳細画面でLightning Web コンポーネントアクション押下時のレコードID取得
    this.recordId = currentPageReference.state.recordId;
    //Apexクラスメソッド呼び出して、レコード取得
    const rows = await getRecords({ recordId: this.recordId }).catch((e) => {
      console.error(e);
   //dispatchEventメソッドでカスタムイベントをディスパッチし、親コンポーネントに伝達します。
      this.dispatchEvent(
        new ShowToastEvent({
          title: "エラーが発生しました。",
          message: e.body.message,
          variant: "error",
        })
      );
    });
  }

}

・xml

testLwc.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>56.0</apiVersion>
    <isExposed>true</isExposed>
  <targets>
  <target>lightning__RecordAction</target>
  </targets>
  <targetConfigs>
    <targetConfig targets="lightning__RecordAction">
      <actionType>ScreenAction</actionType>
    </targetConfig>
  </targetConfigs>
</LightningComponentBundle>

・html

testLwc.html

<template>
        <lightning-quick-action-panel header="test">
            ここにモーダルコンテンツを記載する
            <div slot="footer">
                <lightning-button variant="neutral" label="ボタン1" class="slds-m-left_x-small"></lightning-button>
                <lightning-button variant="brand" label="ボタン2" class="slds-m-left_x-small"></lightning-button>
            </div>
        </lightning-quick-action-panel>
</template>