+ Start a Discussion
Dan Albrecht 5Dan Albrecht 5 

Update field when Lightning Component loads

Good Day Salesforce Developer Community.

I have a small custom component that we are using lightning:picklistpath.  We are using it in a community to show the progress of a case (like a Domino's pizza tracker)   I have created a custom picklist that holds the values I want to share with the customer and I have a process builder that fires to keep the new custom picklist updated with the correct value.  

The issue I am having is that all of the prior cases that do not have a value in my new custom picklist do not display the correct stage in the picklistpath becuse there is no value yet.  I know I can use dataloader to update the still open cases but that would adjust the last modified date and could have impact to reporting. 
 

What I would like to do is when the Lightning component loads, go and update the custom picklist to the correct value.  Is there fairly easy way to do this on initation of the component?  I need it to do it without engaging validation and required fields. that could prevent me from saving the record.  

Any help would be greatly appreciated.

Suraj PSuraj P
You could do this in the init handler of the custom lightning component that contains your lightning:picklistpath. Include the below markup in your custom component. In the "doInit" method check if the picklist vlaue is null, and if so, update it.
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
However, please remeber that it is highly unadvisable to perform DML operations during the initialization of a UI component. You might be ok here, if you take care to ensure that you only do this for Cases with a null value for the picklist. Here's an alternative you might want to consider, though, for eg:
  • Create a custom checkbox field on Cases called "Is First Picklist Update". If needed, also create a custom "DateTime" field called "Previous Last Modified Date"
  • Update all the Case records with a blank picklist with the proper values using dataloader. Also, check the above checkbox in the process and, if required, store the original last modified date into the "Previous Last Modified Date" field.
  • Add a workflow rule that will uncheck this checkbox on any subsequent update of the Case and activate it
  • You can get rid of these fields once all the checkboxes on your cases have been cleared due to subsequent updates

This way, you can use the checkbox and the custom datetime field, if requried, to do reporting
 
Dan Albrecht 5Dan Albrecht 5
Thanks. I think the second option is over complicated. If I am going to update the black values using data loader, I wouldn’t need to do anything else. I am trying to avoid that though because I don’t want to affect last modified date. So if I only affect the record when someone accesses it using the doInit function (which I would need additional code example if you have it) then I can control the records one at a time and limit the impact on reporting. I attempted to use the doInit but for some reason it was not working. I think I need to shake the developer rust off. Dan Albrecht | Salesforce Technical Manager FARO | 250 Technology Park | Lake Mary, FL 32746 Office: 407.333.9911 x1344 Nasdaq: FARO | dan.albrecht@faro.com | www.faro.com