pozil / pub-sub-api-node-client

A node client for the Salesforce Pub/Sub API
Creative Commons Zero v1.0 Universal
70 stars 37 forks source link

Publishing Platform Events - CreatedById checks #17

Closed gaelguimini closed 1 year ago

gaelguimini commented 1 year ago

Hi @pozil,

I tried this client to mock an backend in order to make sure Flows subscribing to the Platform Events executed without error. It turns out, there actually is a check on the CreatedById field. Specifying a value that does not correspond to an active user does NOT trigger any subscription (flow or trigger) in salesforce.

Readme should mention this.

const payload = {
    CreatedDate: new Date().getTime(), // Non-null value required but there's no validity check performed on this field
    CreatedById: '005_________', // Valid user id
    Message__c: { string: 'Hello world' } // Field is nullable so we need to specify the 'string' type
};
const publishResult = await client.publish('/event/Sample__e', payload);
console.log('Published event: ', JSON.stringify(publishResult));
pozil commented 1 year ago

Thanks for catching this @gaelguimini. I'm updating the docs.

gaelguimini commented 1 year ago

BTW :) It would be great if pubsub api would actually reject the message if the publisher fails to provide the exact expected userId instead of having the event be published. It would help catching issues much easier than having the message fall into the void, not triggering nor logging anything in salesforce. Any chance you may be the right person to submit the issue ?

pozil commented 1 year ago

I'm not in charge of the server implementation but this is good feedback. Perhaps you can share it on the official Pub/Sub API repo?

gaelguimini commented 1 year ago

Yep, will do :)