0

Any ideas on why is the field value not updating?

Here's the code that I'm using

APEX

public class btnCloseCase {


        @AuraEnabled
        public static void closeCase(String key){
            Case c = [SELECT Id, Status
                      FROM Case
                      WHERE Id=:key];
            if(c.Status != 'Closed'){
                c.Status = 'Closed';
            }
            UPDATE c;
        }
    }

Component

<aura:component controller="btnCloseCase"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

    <aura:handler event="force:refreshView" action="{!c.isRefreshed}" />
    <div class="slds-align_absolute-center" style="height:8rem">
        <lightning:button variant="brand" label="Confirm Submission" onclick="{!c.closeCase}"  />
    </div>
</aura:component>

Controller

({
    closeCase : function(component, event, helper) {
        var rid = component.get("v.recordId");
        var action = component.get("c.closeCase");
        action.setParams({key : rid});
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                $A.get('e.force:refreshView').fire();              
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                    errors[0].message);
                    }
                } 
                else {
                    console.log("Unknown Error");
                }
            }
        });
        $A.enqueueAction(action);
    },

    isRefreshed: function(component, event, helper) {
        location.reload();
    },
})

Thank you in advance

2
  • You'll need to check your browser's Developer Console and your Salesforce Developer Console to look for errors. I don't see anything obviously wrong, so it might just be a validation rule or some other problem.
    – sfdcfox
    Commented Feb 25, 2020 at 1:24
  • @sfdcfox thank you for the response. I've checked the developer console log but it's not showing anything because the page is refreshing, I also checked the debug logs and it's not showing any logs(settings is set to finest) Commented Feb 25, 2020 at 3:12

1 Answer 1

0

I copied your code it did not work, Then I just changed the variable name and function name it worked. Also, check if you have any support process.

<aura:component controller="btnCloseCase"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

    <aura:handler event="force:refreshView" action="{!c.isRefreshed}" />
    <div class="slds-align_absolute-center" style="height:8rem">
        <lightning:button variant="brand" label="Custom Close" onclick="{!c.customClose1}"  />
    </div>
</aura:component>




({
    isRefreshed: function(component, event, helper) {
        // location.reload();
    },
    customClose1 : function(component, event, helper){
        var rid = component.get("v.recordId");
        console.log('*** Id is ***' + rid);
        var action = component.get("c.customClose");
        action.setParams({ recId : rid });
        action.setCallback(this, function(response) {
            var state = response.getState();
              console.log('From server: **************' + state);
            if(state === 'SUCCESS'){

                 console.log("From server: " + response.getReturnValue() + '**************' + state);
                $A.get('e.force:refreshView').fire(); 
            }
            else if (state === "INCOMPLETE") {
                // do something
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                    errors[0].message);
                    }
                } else {
                    console.log("Unknown error");
                }
            }
        });
        $A.enqueueAction(action);

    }
})


public class btnCloseCase {
        @AuraEnabled
        public static void customClose(String recId){
            system.debug('************* ' +recId);
            Case c = [SELECT Id, Status
                      FROM Case
                      WHERE Id=:recId];
            if(c <> NULL && c.Status != 'Closed'){
                c.Status = 'Closed';
                update c;
                system.debug('************* Updating ***********' +c);
            }
        }
    }
2
  • Thank you for the response. I added the catch how should I check the message? I tried to check in the Debug Log but it's not generating any data all of the settings is set to finest just to be sure. Commented Feb 25, 2020 at 3:05
  • First, confirm that Closed is a valid picklist value. and second, close the infinite loop. for location.reload only one reload is required if you want. Commented Feb 25, 2020 at 16:39

You must log in to answer this question.

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