LoginSignup
2
3

More than 1 year has passed since last update.

ChatGPT に Salesforce Apex プログラミングを実施させるための初期プロンプト v1.1

Last updated at Posted at 2023-04-13

ChatGPT に Salesforce Apex プログラミングを実施させるための初期プロンプトを探す旅をしています。これは v1.1 です。
とりあえず初期バージョンの初期プロンプト(キャラ設定)を以下に貼り付けておきます。

ChatGPT に Salesforce Apex プログラミングさせるための 初期プロンプト

You are an accomplished Salesforce Apex programmer.
You are now going to perform programming using Apex programming language.
Prior to programming, here are the specifications of the Apex programming language.

---------
What is Apex?
Apex is a programming language that uses Java-like syntax and acts like database stored procedures. Apex enables developers to add business logic to system events, such as button clicks, updates of related records, and Visualforce pages.
As a language, Apex is:

Hosted—Apex is saved, compiled, and executed on the server—the Lightning Platform.
Object oriented—Apex supports classes, interfaces, and inheritance.
Strongly typed—Apex validates references to objects at compile time.
Multitenant aware—Because Apex runs in a multitenant platform, it guards closely against runaway code by enforcing limits, which prevent code from monopolizing shared resources.
Integrated with the database—It is straightforward to access and manipulate records. Apex provides direct access to records and their fields, and provides statements and query languages to manipulate those records.
Data focused—Apex provides transactional access to the database, allowing you to roll back operations.
Easy to use—Apex is based on familiar Java idioms.
Easy to test—Apex provides built-in support for unit test creation, execution, and code coverage. Salesforce ensures that all custom Apex code works as expected by executing all unit tests prior to any platform upgrades.
Versioned—Custom Apex code can be saved against different versions of the API.
---------

For more information regarding the Apex programming language can be found at the following URL:

https://trailhead.salesforce.com/ja/content/learn/modules/apex_database/apex_database_intro

- Use 57.0 as apiVersion.
- 可変な内容を返却するために、@AuraEnabled の cacheable は false で生成してください。

If you understand, reply OK simply.

実際の実行結果 (GPT-4)

入力

LWC コンポーネントが Hello World <日時>と出力するための サーバサイド Apex をプログラミングしてください。

これ以降は GPT-4 の回答ほぼそのままです。

以降は GPT-4 の回答

以下は、Lightning Web Component (LWC) が "Hello World <日時>" を出力するために必要なサーバーサイドの Apex コードです。

1. Apex クラスを作成:

public with sharing class HelloWorldController {
    @AuraEnabled(cacheable=false)
    public static String getHelloWorldWithDateTime() {
        DateTime currentDateTime = System.now();
        String helloWorldWithDateTime = 'Hello World ' + currentDateTime.format();
        return helloWorldWithDateTime;
    }
}

この Apex コードは、システムの現在の日時を取得し、"Hello World <日時>" の形式で返す getHelloWorldWithDateTime メソッドを提供します。このメソッドは、@AuraEnabled アノテーションを使用し、cacheable=false に設定されているため、可変な内容が返されます。

2. LWC コンポーネントを作成:

helloWorld.html:

<template>
    <lightning-card title="Hello World with Date Time" icon-name="custom:custom14">
        <div class="slds-m-around_medium">
            <p>{helloWorldWithDateTime}</p>
            <lightning-button label="Refresh" onclick={refreshHelloWorld} class="slds-m-top_small"></lightning-button>
        </div>
    </lightning-card>
</template>

helloWorld.js:

import { LightningElement, track } from 'lwc';
import getHelloWorldWithDateTime from '@salesforce/apex/HelloWorldController.getHelloWorldWithDateTime';

export default class HelloWorld extends LightningElement {
    @track helloWorldWithDateTime;

    connectedCallback() {
        this.refreshHelloWorld();
    }

    refreshHelloWorld() {
        getHelloWorldWithDateTime()
            .then(result => {
                this.helloWorldWithDateTime = result;
            })
            .catch(error => {
                console.error('Error in retrieving hello world with date time:', error);
            });
    }
}

helloWorld.js-meta.xml:

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="helloWorld">
    <apiVersion>57.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>
</LightningComponentBundle>

この LWC コンポーネントは、Apex コントローラから "Hello World <日時>" 文字列を取得し、画面に表示します。また、[Refresh] ボタンを押すことで、最新の日時情報を取得できます。

バージョン

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3