2

i am new to lightning and trying to learn lightning. i have created component in that component i am showing the contact based on the accountid using (implements="flexipage:availableForRecordHome,force:hasRecordId") which is working fine it;s showing data and i have added "new" button so that i can create another contact based on the accountid but it's not showing popup so unable to create record. below is component

   <aura:set attribute="actions">
        <lightning:button label="New" onClick="{!c.newContact}" />
    </aura:set>

-------------below is my component controller-----------------------------

newContact: function(component, event, helper){
    var createContact = $A.get("e.force.createRecord");
    alert(createContact);
    createContact.setParams({
        'entityApiName': 'Contact',
        'defaultfieldValues': {
            'AccountId': component.get("v.recordId")
        }
    });
    createContact.fire();
}
  • Are you testing this component in app? or you added this component in account detail page? – Ratan Paul Jul 2 '18 at 7:42
  • 2
    One problem is that defaultfieldValues should be defaultFieldValues as Aura/JavaScript is case sensitive. There is a small chance that is causing the problem. – Keith C Jul 2 '18 at 7:43
  • i have tried Capital F in defaultFieldValues... but it didn't worked – cloudZigZag Jul 2 '18 at 9:11
  • @ratan i have added component on Record page.. i know in app it will not work because accountid(recordId) was not there – cloudZigZag Jul 2 '18 at 9:12
  • @KeithC if i use defaultFieldValues then it show "Uncaught Action failed: c:MyContactComp$controller$newContact [Cannot read property 'setParams' of undefined]" – cloudZigZag Jul 2 '18 at 9:33

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.