+ Start a Discussion
mwille64mwille64 

Custom Object standard button 'New' override

I have two custom objects, Booking and related Services. I want to implement an override for the standars New button of the Service object as a new Service record can only be created in the context of a Booking. So I created a Lightning component for that, which should open a new page saying 'please create a Service record from within a Booking, showing below a datatable of the most recent edited Booking records. 

<aura:component controller="BookingController" implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:actionOverride" access="global">
    <ui:message title="Information" severity="warning" closable="false">
        Please create new Service records from a Booking record.
    </ui:message>
    
    <aura:attribute type="Booking__c[]" name="bookList"/>
    <aura:attribute name="mycolumns" type="List"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.fetchBookings}"/>
    
    <lightning:datatable data="{! v.bookList }"
                         columns="{! v.mycolumns }"
                         keyField="id"
                         hideCheckboxColumn="true"/>          
</aura:component>

The component controller has following code:

({
    fetchBookings : function(component, event, helper) 
    {    
        helper.fetchBookingsHelper(component, event, helper);
    }
})

And the helper:

({
    fetchBookingsHelper : function(component, event, helper) 
    {
        component.set('v.mycolumns', [
            {label: 'Booking Number', fieldName: 'Name', type: 'text'},
            {label: 'Booking Reference', fieldName: 'Booking_Name__c', type: 'text'},
            {label: 'Arrival Date', fieldName: 'Arrival_Date__c', type: 'date'},
            {label: 'Departure Date', fieldName: 'Departure_Date__c', type: 'date '},
            {label: 'Agent', fieldName: 'Agent__c', type: 'text'}
           ]);

        var action = component.get("c.fetchBookings");
        
        action.setParams({});
        
        action.setCallback(this, 
            function(response)
            {
                var state = response.getState();
                
                if (state === "SUCCESS") 
                { 
                    component.set("v.bookList", response.getReturnValue());
                    alert("Success: " + response.getReturnValue());
                }
                else if (state === "INCOMPLETE")
                {
                    // do something
                }
                else if (state === "ERROR") 
                {
                    var errors = response.getError();
                    
                    if (errors) 
                    {
                        if (errors[0] && errors[0].message) 
                        {
                            alert("Error message: " + errors[0].message);
                        }
                    }
                } 
                else 
                {
                    alert("Unknown error");
                }
            }
        );
        
        $A.enqueueAction(action);
    }
})

To retrieve the data I wrote an Apex class:

public class BookingController {
    @AuraEnabled
    public static List <Booking__c> fetchBookings() {
        //Qyery 20 recent bookings
        List <Booking__c> bookList = 
            [SELECT Id, Name, Booking_Name__c, Arrival_Date__c, Departure_Date__c, Agent__c 
             FROM Booking__c
             ORDER BY LastModifiedDate DESC
             LIMIT 20];
        //return list of bookings
        return bookList;
    }
}

The BookingController() function works perfectly fine. The data is retrieved correctly. However, when clicking the New button within one of the Service record views, the Lightning components appears (without data) on the screen, followed by an infinite loop of Success message.

I can't get my head around why the callback function that should receive a result set is not receiving any result and on top of that is being called in an endless loop.

Any idea?
 
mwille64mwille64
In addition, I followed this example as far as I can tell precisly:

https://www.sfdcpoint.com/salesforce/lightning-datatable-example-salesforce/
mwille64mwille64
Further more, if I take the Alert ("Success") message out, I get a "Sorry to interrupt" message box with following details:

(We're reporting this as error ID: 1148540067)

AuraClientService.postProcess: error in processing [Maximum call stack size exceeded]
bH.Wd()@https://mydomain.lightning.force.com/auraFW/javascript/dDIdorNC3N22LalQ5i3slQ/aura_prod.js:715:382
bH.Fr()@https://mydomain.lightning.force.com/auraFW/javascript/dDIdorNC3N22LalQ5i3slQ/aura_prod.js:729:204
CG()@https://mydomain.lightning.force.com/auraFW/javascript/dDIdorNC3N22LalQ5i3slQ/aura_prod.js:642:31
vG()@https://mydomain.lightning.force.com/auraFW/javascript/dDIdorNC3N22LalQ5i3slQ/aura_prod.js:640:485
sG()@https://mydomain.lightning.force.com/auraFW/javascript/dDIdorNC3N22LalQ5i3slQ/aura_prod.js:632:373
vG()@https://mydomain.lightning.force.com/auraFW/javascript/dDIdorNC3N22LalQ5i3slQ/aura_prod.js:639:160
sG()@https://mydomain.lightning.force.com/auraFW/javascript/dDIdorNC3N22LalQ5i3slQ/aura_prod.js:632:373
vG()@https://mydomain.lightning.force.com/auraFW/javascript/dDIdorNC3N22LalQ5i3slQ/aura_prod.js:639:160
sG()@https://mydomain.lightning.force.com/auraFW/javascript/dDIdorNC3N22LalQ5i3slQ/aura_prod.js:632:373
vG()@https://mydomain.lightning.force.com/auraFW/javascript/dDIdorNC3N22LalQ5i3slQ/aura_prod.js:639:160
mwille64mwille64
Gee, just found an answer to the infinite loop:

https://salesforce.stackexchange.com/questions/130091/auraclientservice-postprocess-error-in-processing-rangeerror-maximum-call-sta

"As per the doc, it is recommended to use different names for the client side and server side methods/actions.
Use unique names for client-side and server-side actions in a component. A JavaScript function (client-side action) with the same name as a server-side action (Apex method) can lead to hard-to-debug issues."

I also had to remove ...

    <ui:message title="Information" severity="warning" closable="false">
        Please create new Service records from a Booking record.
    </ui:message>
    
...from the component.

But now it works.
damion medamion me
New button of the Service object as a new Service record can only be created in the context of a Booking. 
https://www.marks4sure.com/PL-200-exam.html
john alemjohn alem
If you Want to become a salesforce Certified Professional then you need to know the best way to get certified. Gratisdumps.com exam dumps and practice tests can be that best way because:

1.Verified question answers.
2.Exam dumps are in PDF.
3.Online Practice tests.
4.All Exam dumps are available with 90 days free updates.

Some Exam Here:
 
  1. Service-Cloud-Consultant
  2. Marketing-Cloud-Developer
  3. Marketing-Cloud-Administrator
  4. Nonprofit-Cloud-Consultant
  5. Salesforce-Certified-Administrator
  6. User-Experience-Designer
  7. Identity-and-Access-Management-Designer
  8. Integration-Architecture-Designer
  9. Data-Architecture-And-Management-Designer
  10. FSL-201
  11. Sharing-and-Visibility-Designer
  12. PDII
  13. ADM-201
  14. ADM-211
  15. CRT-251
  16. CRT-261
  17. CRT-450