Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.9 KB
Raw Blame
import { Property, createAction } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { salesforceAuth } from '../..';
import { callSalesforceApi, salesforcesCommon } from '../common';
import { sobjectCreateResponseOutputSchema } from '../output-schemas';

export const createNote = createAction({
    auth: salesforceAuth,
    name: 'create_note',
    classification: 'WRITE',
    displayName: 'Create Note',
    description: 'Creates a note on a record.',
    audience: 'human',
    aiMetadata: { description: 'Create a classic Salesforce Note (title and body) and attach it to a parent record via its record Id. Use to add a free-text note to an existing record. Not idempotent: each call creates a new Note, so re-running adds a duplicate.', idempotent: false },
    outputSchema: sobjectCreateResponseOutputSchema,
    propertyGroups: [
        { key: 'record', display: 'section', label: 'Record', icon: 'file', props: ['object', 'parent_id'] },
        { key: 'note', display: 'section', label: 'Note', icon: 'text', props: ['Title', 'Body'] },
    ],
    props: {
        object: salesforcesCommon.object,
        parent_id: salesforcesCommon.record, 
        Title: Property.ShortText({
            displayName: 'Title',
            required: true,
            placeholder: 'Call summary',
        }),
        Body: Property.LongText({
            displayName: 'Body',
            required: true,
        }),
    },
    async run(context) {
        const { parent_id, Title, Body } = context.propsValue;

        const body = {
            ParentId: parent_id,
            Title: Title,
            Body: Body,
        };

        const response = await callSalesforceApi(
            HttpMethod.POST,
            context.auth,
            '/services/data/v56.0/sobjects/Note',
            body
        );

        return response.body;
    },
});