2016-12-04 85 views
2

問題概述:目前編碼一個閃電組件更新的自定義對象的記錄。然而,我每次觸發更新(通過用戶界面:按鈕),頁面凍結,我沒有看到在調試器或控制檯的任何錯誤。不能爲我的生活找出爲什麼它不會工作。Salesforce的閃電組件將不通過的Apex通話更新記錄,凍結

上下文:組件有許多下拉列表中填充了記錄(標籤是記錄名稱)。在下拉列表中選擇一個新值,並創下「更新」調用下面頂點上的新選擇的項目更改自定義字段(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> 

回答

3

我認爲,問題是,你已經陷入命名既是客戶端和服務器端的控制方法相同(updateMilestones的太常見陷阱在這種情況下)。嘗試改變其名稱以使它們獨一無二,我期望這會讓你運行。

是的,這有一個錯誤,我們許多人一直在發出非常響亮的聲音來修復它!

此外,我們在此處有一個非常活躍的Salesforce特定的Stack Exchange論壇https://salesforce.stackexchange.com/,它將獲得更多關注 - 尤其是當您使用閃電組件標記您的帖子時(例如,我的帳戶已配置爲向我發送每封帖子的電子郵件提醒用雷電組件,儲物櫃服務等標記)。

+0

這解決了凍結問題!我遇到的另一個問題是選項標籤中的區分大小寫。將id更改爲Id,並且完美運行。再次感謝! –

0

這可能是造成的javascript由於在知道錯誤的情況下很難解決,我建議您調試錯誤。

  1. 打開調試模式。 a。從安裝程序中,單擊開發>閃電組件。 b。選擇啓用調試模式複選框。 c。點擊保存。

  2. 在Chrome開發人員工具中,選中Sources選項卡中的「暫停捕捉異常」複選框。這通常可以幫助找到問題的根源。其他瀏覽器可能有類似的選項。

  3. 如果您想逐步執行某些代碼,請添加調試器語句。 調試器; 當你有一個大概的瞭解問題出在哪裏可能發生的,這非常有用。

調試

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/debug_intro.htm