0

i am currently seeing some weird behaviour in a Salesforce flow. The screen flow has got a lightning component in it which is a custom build picklist that updates a Salesforce Picklist when the value is changed. I tested it and the related picklist is really updated by the apex controller when a picklist change occurs.

The lightning component also has a onInit method that gives me the current value of the related picklist. This also works when i update the picklist via the update record element in a flow.

Now comes the odd part: When i update the related picklist from the lightning component via an apex controller and navigate one screen back the value is still in the related picklist but if i navigate again to the next screen the value is gone and the onInit return a null value. (I also checked in the related picklist and it is there gone too). Is the getRecord element of a flow not getting the current values?!

I have absolutely no idea why this is happening. :D Really really looking forward to your answers.

The methods of the lightning component

getCurrentValue : function(cmp, event, helper) {
    if(cmp.get('v.recordId') != null && typeof cmp.get('v.recordId') != "undefined" && cmp.get('v.recordId') != ''){
        var action = cmp.get("c.getCurrentValue");
        action.setParams({
            "objectName": cmp.get("v.object"),
            "pickListFieldName": cmp.get("v.field"),
            "recordId": cmp.get("v.recordId")
        });

        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                cmp.set("v.defaultvalue", response.getReturnValue());
                this.fillPicklist(cmp, event, helper);
            }else{
                alert("Es gab ein Problem mit Ihrer Internetverbindung.");
            }
        });

        $A.enqueueAction(action);
    }else{
        this.fillPicklist(cmp, event, helper);
    }

},

updateRecord : function(cmp, event, helper) {
    var action = cmp.get("c.updateObject");
    action.setParams({
        "objectName": cmp.get("v.object"),
        "pickListFieldName": cmp.get("v.field"),
        "recordId": cmp.get("v.recordId"),
        "updateValue": cmp.get("v.outputvalue")
    });

    action.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {

        }else{
            alert("Es gab ein Problem mit Ihrer Internetverbindung.");
        }
    });

    $A.enqueueAction(action);
},

The related apex controller:

 @AuraEnabled
public static void updateObject(String objectName, String pickListFieldName, Id recordId, String updateValue){
    List<sObject> list_object = Database.query('SELECT Id, ' +pickListFieldName +' FROM ' +objectName +' WHERE Id = :recordId');
    SObjectType objectType = Schema.getGlobalDescribe().get(objectName); 
    DescribeSObjectResult objDef = objectType.getDescribe();
    Map<String, SObjectField> fields = objDef.fields.getMap();

    for (sObject obj: list_object){

        obj.put(pickListFieldName,updateValue);

    } 

    System.debug('updateValue: ' +updateValue);

    update list_object;
}

@AuraEnabled
public static String getCurrentValue(String objectName, String pickListFieldName, Id recordId){
    List<sObject> list_object = Database.query('SELECT Id, ' +pickListFieldName +' FROM ' +objectName +' WHERE Id = :recordId');
    SObjectType objectType = Schema.getGlobalDescribe().get(objectName); 
    DescribeSObjectResult objDef = objectType.getDescribe();
    Map<String, SObjectField> fields = objDef.fields.getMap();

    for (sObject obj: list_object){

        obj.get(pickListFieldName);

    } 

    System.debug('returnValue: ' +(String)list_object[0].get(pickListFieldName));

    return (String)list_object[0].get(pickListFieldName);
}

The screens in the flow where i navigate back and force.

enter image description here

0

This may not answer your question, but this is a detailed explanation of some of the subtleties of current Before and Next behavior:

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.