2

In a Flow Screen LWC, I would like to allow the admin to build a series of screens with input fields mapped to sObject fields of their choosing, and automatically set the input value to the corresponding field on an sObject variable of their choosing.

Building a component to render the appropriate input for an Object/Field is pretty straightforward, but I'm struggling with getting the value assigned to the sObject variable. Is this something that is even possible?

When you pass an sObject variable into a Flow Screen LWC, it looks like it is just an object with the assigned field names/values as properties. For example:

I have a Flow record variable for My_Object__c called "myObject" and My_Object__c.Field__c is assigned a value of 'test', then "myObject" is passed into a property called "record" in the LWC. In the LWC:

console.log(JSON.stringify(this.record)); // {"Field__c" : "test"}

A little bare-bones I thought, but something we can work with. If I copy this object to another property and add another field with a value, then notify the Flow of the change, it seems like it might work:

this._record = JSON.parse(JSON.stringify(this.record));
this._record['Field2__c'] = 'another value';
console.log(JSON.stringify(this._record)); // {"Field__c" : "test","Field2__c" : "another value"}
this.dispatchEvent(new FlowAttributeChangeEvent('record', this._record));

That piece will execute without error, but then later in the Flow if you try to reference the newly assigned field, the Flow fails with the error "The flow failed to access the value for myObject.Field2__c because it hasn't been set or assigned."

2
  • Hi @jakranz33 I think you are looking for a solution where you can find the field value changes on runtime flow. Am I correct on it or not?
    – Virendra
    Oct 11, 2020 at 20:58
  • @VirendraKhatke Yes, when the value of an input in my LWC Flow Screen component changes, I would like to report that change to an admin-defined sObject variable. Specifically, the field on that sObject variable that the admin defines. In the sample code above, the dispatchEvent() method would be called in a function that handles change of the input, assigning the event.detail.value to the field in question.
    – Jeff Kranz
    Oct 12, 2020 at 12:53

1 Answer 1

2

Circling back on this.

It seems that the good folks on the Salesforce Flows Product Management team were reading my mind and have since released a feature that does exactly what I described wanting to achieve in this question. Released as Beta in Summer 21 (still in Beta as of Winter 22)

https://help.salesforce.com/s/articleView?id=release-notes.rn_automate_flow_builder_place_object_fields_on_screens.htm&type=5&release=232

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.