Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Salesforce Lightning组件不会通过Apex呼叫更新记录,冻结_Javascript_Salesforce_Apex_Aura.js_Sfdc - Fatal编程技术网

Javascript Salesforce Lightning组件不会通过Apex呼叫更新记录,冻结

Javascript Salesforce Lightning组件不会通过Apex呼叫更新记录,冻结,javascript,salesforce,apex,aura.js,sfdc,Javascript,Salesforce,Apex,Aura.js,Sfdc,问题概述:当前正在编码Lightning组件以更新自定义对象上的记录。但是,每次我通过ui:按钮触发更新时,页面都会冻结,并且在调试器或控制台中看不到任何错误。我一辈子都搞不明白为什么它不起作用 上下文:该组件有许多下拉列表,其中填充了以记录名称为标签的记录。在下拉列表中选择一个新值并点击“更新”按钮,将调用下面的顶点来更改新选定项的自定义字段状态\uuu c='Ready',然后更新在其状态\uu c='Complete'之前出现的记录。我在init期间在另一个函数中执行所有的安全性和更新检查

问题概述:当前正在编码Lightning组件以更新自定义对象上的记录。但是,每次我通过ui:按钮触发更新时,页面都会冻结,并且在调试器或控制台中看不到任何错误。我一辈子都搞不明白为什么它不起作用

上下文:该组件有许多下拉列表,其中填充了以记录名称为标签的记录。在下拉列表中选择一个新值并点击“更新”按钮,将调用下面的顶点来更改新选定项的自定义字段状态\uuu c='Ready',然后更新在其状态\uu c='Complete'之前出现的记录。我在init期间在另一个函数中执行所有的安全性和更新检查,因此您不会看到这里我可以在需要时发布完整的代码。只是想让更新生效

如果有人能告诉我我的错误,我将永远感激。一直以来都是stackoverflow的超级粉丝,现在我终于签约了,我期待着为之做出贡献。谢谢大家抽出时间

顶点:

组成部分:


这可能是javascript导致的错误。由于不知道错误就很难解决,我建议您调试错误

打开调试模式。 A.从“设置”中,单击“开发”>“Lightning组件”。 B选中启用调试模式复选框。 C单击保存

在Chrome开发者工具中,选中源选项卡中的暂停捕获异常复选框。这通常有助于找到问题的根源。其他浏览器可能有类似的选项

如果要单步执行某些代码,请添加调试器语句。 调试器; 当您大致了解问题可能发生的位置时,这非常有用

调试器


我认为问题在于,您陷入了一个非常常见的陷阱,即在本例中,将客户端和服务器端控制器方法命名为相同的UpdateMilstones。尝试更改其中一个的名称以使其唯一,我希望这将使您运行

是的,这上面有一个bug,我们中的许多人一直在大声嚷嚷着要修复它


此外,我们这里有一个非常活跃的Salesforce特定的Stack Exchange论坛,它将获得更多的关注,特别是如果您用lightning组件标记帖子,例如,我的帐户配置为在每个帖子上都向我发送一封电子邮件警报,标记有lightning组件、储物柜服务等。

这解决了冻结问题!我遇到的另一个问题是选项标记中的大小写敏感性。把身份证换成了身份证,它工作得很好。再次感谢!
@AuraEnabled
public static void updateMilestones(String deployId,Boolean prodChanged,String newProdMile) {
    if( prodChanged == true && newProdMile != null ) {
        try {
            decimal newProdStepNum;
            List <Milestone__c> newReadyProdMile = New List<Milestone__c>();
            for(Milestone__c mil1:[SELECT id, Status__c, Step_Order__c FROM Milestone__c 
                                    WHERE Deployment__c = :deployID 
                                    AND id = :newProdMile LIMIT 1]){
                                    mil1.Status__c = 'Ready';
                                    newProdStepNum = mil1.Step_Order__c;
                                    newReadyProdMile.add(mil1); 
                                    }
            List <Milestone__c> prodMilesComplete = New List<Milestone__c>();
            for(Milestone__c mil2:[SELECT id, Type__C, Status__c FROM Milestone__c 
                                   WHERE Deployment__c = :deployID 
                                   AND Step_Order__c < :newProdStepNum 
                                   AND Type__c = 'Production' 
                                   AND Status__c != 'Complete'  
                                   AND Status__c != 'Revised']){
                                       mil2.Status__c = 'Complete';
                                       prodMilesComplete.add(mil2); 
                                   }
            update newReadyProdMile;
            update prodMilesComplete; 
        }
        catch (DmlException e) {
            throw new AuraHandledException('Sorry, the update did not work this time. Refresh and try again please!');
        } 
    }
}
updateMilestones : function(component, event, helper) {
    // update milestones server-side
    var action = component.get("c.updateMilestones");
    action.setParams({
        deployId : component.get("v.recordId"),
        newProdMile : component.find("prod-mile-select").get("v.value"),
        prodChanged : component.get("v.prodChanged")
    });

    // Add callback behavior for when response is received
     action.setCallback(this, function(response) {
        var state = response.getState();
        if (component.isValid() && state === "SUCCESS") {
            // re-run the init function to refresh the data in the component
            helper.milesInit(component);
            // refresh record detail
            $A.get("e.force:refreshView").fire();
            // set Update Changed Milestones button back to disabled
            component.find("updateButton").set("v.disabled","true");
            // show success notification
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                "title": "Success!",
                "message": "Milestones have been updated successfully."
            });
            toastEvent.fire();
        }
    });

    // Send action off to be executed
    $A.enqueueAction(action);
}
<aura:component controller="auraMilestonesController_v2" 
                implements="force:appHostable,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction">
    <ltng:require scripts="{!$Resource.lodash}" afterScriptsLoaded="{!c.doInit}"/>
    <aura:attribute name="recordId" type="String" />
    <aura:attribute name="prodMiles" type="Milestone__c[]"/>
    <aura:attribute name="prodChanged" type="Boolean" default="false"/>
    <!-- FORM -->
    <div class="slds-col slds-col--padded slds-p-top--large" id="theform">
        <form class="slds-form--stacked">
            <!-- UPDATE BUTTON -->            
            <div class="slds-form-element">
                <ui:button aura:id="updateButton" label="Update Changed Milestones" press="{!c.updateMilestones}" 
                           class="slds-button slds-button--brand slds-align--absolute-center" disabled="true"/>
            </div>
            <hr style="color: #005fb2;background-color: #005fb2;"/>
            <!-- PRODUCTION -->
            <div aura:id="prod-section">
                <div class="slds-form-element">
                    <label class="slds-form-element__label" for="milestone">Production Milestone</label>
                    <div class="slds-form-element__control">
                        <div class="slds-select_container">
                            <ui:inputSelect aura:id="prod-mile-select" class="slds-select" change="{!c.prodChange}">
                                <option value="" >--Select One--</option>
                                <aura:iteration items="{!v.prodMiles}" var="m">
                                    <aura:if isTrue="{!m.Status__c == 'Ready'}">
                                        <option value="{!m.id}" selected="true">{!m.Name} ({!m.User_Name__c})</option>
                                    </aura:if>
                                    <aura:if isTrue="{!m.Status__c == 'Not Ready'}">
                                        <option value="{!m.id}">{!m.Name} ({!m.User_Name__c})</option>
                                    </aura:if>
                                </aura:iteration>
                                <option value="completeProdMile" id="completeProdMile">All Production Milestones Complete</option>
                            </ui:inputSelect>
                        </div>
                    </div>
                </div>
                <div class="slds-form-element">
                    <label class="slds-form-element__label" for="description">Description</label>
                    <div class="slds-textarea">
                        <aura:iteration items="{!v.prodMiles}" var="m">
                            <aura:if isTrue="{!m.Status__c == 'Ready'}">{!m.Description__c}</aura:if>
                            <!-- <aura:set attribute="else">All production milestones have been completed.</aura:set> -->
                        </aura:iteration>
                    </div>
                    <hr style="color: #005fb2;background-color: #005fb2;"/>
                </div>
            </div>
            <!-- END PRODUCTION -->
        </form>
    </div>
    <!-- / FORM -->
</aura:component>