0

I have created salesforce function (node js) which will create account record when i invoke it from Apex . I amable to create account record with standard fields . But when i include custom field the record is not created. Do i miss any permission here . I have provided the FLS as well the Functions permissionset for account.

FUNCTIONS CODE NODE.JS


  import { InvocationEvent, Context, DataApi, Logger, RecordQueryResult } from "sf-fx-sdk-nodejs";

export default async function execute(event: InvocationEvent<any>, context: Context, logger: Logger): Promise<RecordQueryResult> {
  // logger.info(`Invoking Nodefunction with payload ${JSON.stringify(event.data || {})}`);


  var messages;
  var contentss = event.data.name;
   const account = {
        type: "Account",
        fields: {
          Name: 'Test123',
          Description: contentss,
          AccountDescription__c : contentss
          
        }
      };
      context.org.dataApi.create(account).then(function (result) {
        console.log(result + '----create result');
      });

      messages = result; // Any messages, such as warnings during conversion

  return messages;
}

Functions Permission Set :

 <?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
    <hasActivationRequired>true</hasActivationRequired>
    <label>Functions</label>
    <objectPermissions>
        <allowCreate>true</allowCreate>
        <allowDelete>false</allowDelete>
        <allowEdit>true</allowEdit>
        <allowRead>true</allowRead>
        <modifyAllRecords>false</modifyAllRecords>
        <object>Account</object>
        <viewAllRecords>false</viewAllRecords>
    </objectPermissions>
</PermissionSet>

When i run my function locally account record gets created with custom field also but not when i invoke it from Salesforce . Please help me !!

1
  • One thing, this code works but will not return the messages due to the async nature of the create function. Instead you can use async/await and write it like: const result = await context.org.dataApi.create(account); Jan 6, 2022 at 17:47

1 Answer 1

1

Its becuase of the field Permission .It worked now

<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
    <fieldPermissions>
        <editable>true</editable>
        <field>Account.AccountDescription__c</field>
        <readable>true</readable>
    </fieldPermissions>
    <hasActivationRequired>true</hasActivationRequired>
    <label>Functions</label>
    <objectPermissions>
        <allowCreate>true</allowCreate>
        <allowDelete>false</allowDelete>
        <allowEdit>true</allowEdit>
        <allowRead>true</allowRead>
        <modifyAllRecords>false</modifyAllRecords>
        <object>Account</object>
        <viewAllRecords>false</viewAllRecords>
    </objectPermissions>
</PermissionSet>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .