[英]Salesforce Lightning Component will not update records via Apex call, freezes
問題概述:當前編碼一個閃電組件以更新自定義對象上的記錄。 但是,每次我觸發更新(通過ui:button)時,頁面都會凍結,並且在調試器或控制台中看不到任何錯誤。 無法為我的生活弄清楚為什么它不起作用。
上下文:組件具有許多下拉列表,這些下拉列表中填充了記錄(標簽為記錄名稱)。 在下拉列表中選擇一個新值,然后單擊“更新”,將調用以下頂點更改新選定項目上的自定義字段(Status__c =“就緒”),然后更新在此字段之前發生的記錄(Status__c =“完成”)。 我會在初始化過程中盡我所有的安全性並在另一個函數中更新檢查,因此您在這里不會看到(我可以在需要時發布完整的代碼)。 只是想讓更新生效。
如果有人可以告訴我我的方式的錯誤,我將永遠感激不盡:]。 一直是stackoverflow的忠實擁護者,現在我終於簽約了,我期待着為之貢獻。 謝謝大家的寶貴時間!
頂尖:
@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!');
}
}
}
使用Javascript:
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>
我認為問題在於,您已經陷入了將客戶端和服務器端控制器方法都命名為相同的情況(在本例中為updateMilestones )。 嘗試更改任一名稱以使其具有唯一性,我希望這樣可以使您運行起來。
是的,這存在一個錯誤,而且我們很多人都在大聲疾呼對其進行修復!
此外,我們在這里https://salesforce.stackexchange.com/上有一個非常活躍的Salesforce特定Stack Exchange論壇,該論壇將引起更多關注-特別是如果您使用閃電組件標記帖子(例如,我將自己的帳戶配置為向我發送郵件每封貼有lightning-components,locker-service等標記的帖子的電子郵件提醒。
這可能是由JavaScript引起的錯誤。由於不知道該錯誤很難解決,因此建議您調試該錯誤。
打開調試模式。 一種。 在安裝程序中,單擊開發>閃電組件。 灣 選擇啟用調試模式復選框。 C。 單擊保存。
在Chrome開發者工具中,選中“來源”標簽中的“暫停捕獲的異常”復選框。 這通常可以幫助找到問題的根源。 其他瀏覽器可能具有類似的選項。
如果要逐步執行一些代碼,請添加調試器語句。 調試器; 當您大概知道問題可能發生的位置時,此功能很有用。
調試器
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/debug_intro.htm
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.