1

I have created my custom related component for custom object on Contact detail page. It has two options edit and delete. On edit I am opening standard lightning edit page of the record and after saving the record I want to refresh my component. Following is my code for refresh

aura:dependency resource="markup://force:recordSaveSuccess" type="EVENT,COMPONENT" /> aura:handler name="handleSaveSuccess" event="force:recordSaveSuccess" action="{!c.doInit}" />

This make sure that when Contact record is updated my component is refreshed but when custom object is edited using my edit button component is not getting refreshed.

Can you help me out with this.

<aura:component controller="acons100.LTN_ContactRolesController" 
            implements='force:hasRecordId,flexipage:availableForRecordHome,force:hasSObjectName'>

    <aura:attribute name="recordId"  type="Id"/>
    <aura:attribute name="sObjectName" type="String" />

    <aura:attribute name="acons100__Investor_Contact_Role__c" 
                    type="List" access="global"/>
    <aura:attribute name="acons100__Investing_Entity_Contact_Role__c" 
                    type="List" access="global"/>
    <aura:attribute name="investorContactlist"  
                    type="acons100__Investor_Contact_Role__c[]" access="global"/>
    <aura:attribute name="entityContactlist"  
                    type="acons100__Investing_Entity_Contact_Role__c[]" access="global"/>

<aura:dependency resource="markup://force:editRecord" type="EVENT,COMPONENT" />
    <aura:dependency resource="markup://force:recordSaveSuccess" type="EVENT,COMPONENT" />
    <aura:handler event="force:refreshView" action="{!c.doInit}" />
    <aura:handler name="handleSaveSuccess" event="force:recordSaveSuccess" action="{!c.doInit}" />

<!-- Will  be called on Component Load -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> 

<aura:renderIf isTrue="{!v.sObjectName == 'Contact' || v.sObjectName == 'Account'}">
        <div style="margin:10px 10px 10px 10px">
            <div class="slds-m-top--medium">
                <div class="slds-col slds-size--12-of-12 slds-card">
                    <header class="slds-card__header slds-grid">
                        <div class="slds-col slds-media slds-media--center">
                            <div class="slds-media__figure">
                                <span class="slds-icon_container slds-icon-standard-account" title="Investor Contact Roles">
                                    <acons100:svg svgPath="/resource/acons100__SLDS100/assets/icons/standard-sprite/svg/symbols.svg#account"
                                           class="slds-icon" category="standard" size="small">
                                    </acons100:svg>
                                    <span class="slds-assistive-text">Sort</span>
                                </span>
                            </div>
                            <div class="slds-media__body">
                                <h3 class="slds-text-heading--small">Investor Contact Roles ({!v.investorContactlist.length})</h3>
                            </div>
                            <div>
                                <div class="slds-button-group" role="group">
                                    <button onclick="{!c.newInvestorContactRole}" class="slds-button slds-button--neutral" type="button">
                                        <span class="label bBody truncate" dir="ltr">New Investor Contact Role</span>
                                    </button>
                                    <aura:if isTrue="{!v.sObjectName == 'Account'}">
                                        <button onclick="{!c.newContact}" class="slds-button slds-button--neutral" type="button">
                                            <span class="label bBody truncate" dir="ltr">New Investor Contact</span>
                                        </button>
                                    </aura:if>
                                </div>
                            </div>
                        </div>
                    </header>
                    <section class="slds-card__body">
                        <table id="oppTable" 
                           class="slds-table slds-table--bordered slds-max-medium-table--stacked-horizontal">
                            <aura:if isTrue="{!v.investorContactlist.length > 0}">
                                <thead>
                                    <tr class="slds-no-hover">
                                        <aura:if isTrue="{!v.sObjectName == 'Contact'}">
                                            <th class="slds-text-heading--label slds-is-resizable  slds-is-sortable"
                                                scope="col">Investor</th>
                                            <aura:set attribute="else">
                                                <th class="slds-text-heading--label slds-is-resizable  slds-is-sortable"
                                                    scope="col">Contact</th>
                                            </aura:set>
                                        </aura:if>
                                        <th class="slds-text-heading--label slds-is-resizable  slds-is-sortable"
                                            scope="col">Role</th>
                                        <th class="slds-text-heading--label slds-is-resizable  slds-is-sortable"
                                            scope="col">Email</th>
                                        <th></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <aura:iteration var="investor" items="{!v.investorContactlist}" indexVar="i">
                                        <tr class="slds-hint-parent">
                                            <aura:if isTrue="{!v.sObjectName == 'Contact'}">
                                                <td  data-label="Investor">
                                                    <a aura:id="investorId" href="{! '#/sObject/' + investor.acons100__Investor__c +'/view'}">
                                                        {!investor.acons100__Investor__r.Name}
                                                    </a>
                                                </td>
                                                <aura:set attribute="else">
                                                    <td  data-label="Contact">
                                                        <a aura:id="contactId" href="{! '#/sObject/' + investor.acons100__Contact__c +'/view'}">
                                                            {!investor.acons100__Contact__r.Name}
                                                        </a>
                                                    </td>
                                                </aura:set>
                                            </aura:if>
                                            <td  data-label="Role" >{!investor.acons100__Role__c}</td>
                                            <td  data-label="Email" >{!investor.acons100__Email_Formula__c}</td>
                                            <td>
                                                <div class="slds-float--right">
                                                    <div class="slds-dropdown-trigger slds-dropdown-trigger--click"  
                                                     aura:id="investorDropDown" 
                                                     aria-expanded="true">
                                                        <button data-record="{!investor.Id}" 
                                                            onclick="{!c.openEditDelete}" 
                                                            class="slds-button slds-button--icon-border slds-button--icon-x-small" 
                                                            aria-haspopup="true">
                                                            <acons100:svg value="{!investor.Id}" 
                                                                   svgPath="/resource/acons100__SLDS100/assets/icons/utility-sprite/svg/symbols.svg#down"
                                                                   name="down" size="x-small"
                                                                   ariaHidden="true" class="slds-button__icon slds-button__icon--hint slds-button__icon--small">
                                                            </acons100:svg>
                                                            <div class="slds-dropdown slds-dropdown--right">
                                                                <ul class="dropdown__list"  role="menu" aria-labelledby="editdelete">
                                                                    <li class="slds-dropdown__item">
                                                                        <a href="javascript:void(0);"
                                                                           role="menuitem"
                                                                           data-record="{!investor.Id}"
                                                                           onclick="{!c.editContactRole}">
                                                                            <p class="slds-truncate">Edit</p>
                                                                        </a>
                                                                    </li>
                                                                    <li class="slds-dropdown__item">
                                                                        <a href="javascript:void(0);" 
                                                                           role="menuitem"
                                                                           data-index="{!i}" 
                                                                           onclick="{!c.deleteInvestorContactRole}">
                                                                            <p class="slds-truncate">Delete</p>
                                                                        </a>
                                                                    </li>
                                                                </ul>
                                                            </div>
                                                        </button>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                    </aura:iteration>
                                </tbody>
                                <aura:set attribute="else">
                                    <tbody>
                                        <tr class="slds-hint-parent">
                                            <td colspan="7">No records to display.</td>
                                        </tr>
                                    </tbody>
                                </aura:set>
                            </aura:if>
                        </table>
                    </section>
                    <aura:if isTrue="{!v.investorContactlist.length > 0}">
                        <section class="slds-card__footer" style="text-align:left;">
                            <ui:outputURL value="" label="View All" click="{!c.navigateToInvestorRoles}"/>
                        </section>
                    </aura:if>
                </div>
            </div>
        </div>
    </aura:renderIf>
</aura:component>

Controller method calling edit method

editContactRole : function(component, event, helper) {
        var record = event.currentTarget.dataset.record;
        var editRecordEvent = $A.get("e.force:editRecord");
        editRecordEvent.setParams({
            "recordId": record
        });
        editRecordEvent.fire();

        var cmpEvent = component.getEvent("refreshafterCustomEdit");
        cmpEvent.fire();
    }
openEditDelete : function(component,event,helper){
$A.util.toggleClass(event.currentTarget.parentNode,'slds-is-open');
}
  • Please share your code – Praveen Jul 30 '16 at 12:40
  • Hi Praveen, which part of the code do you want to see? . It is custom related list on which I have used the above mentioned code for re-rendering. I have designed using lightningdesignsystem.com/components/cards/… this code. – Shankish Aug 1 '16 at 3:05
  • Can you check the code and let me know. I have updated the code. After successfully finishing the editing contact role I want to refresh detail page on which the component is loaded. – Shankish Aug 1 '16 at 3:20
  • Can you remove name attribute in force:recordSaveSuccess's aura:handler and check it – Praveen Aug 2 '16 at 3:50
  • Because application event's(force: recordSaveSuccess) handler won't fire if name attribute specified in the aura:handler's markup – Praveen Aug 2 '16 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.