+ Start a Discussion
Barb LeungBarb Leung 

How to create "New Product" btn on Product Object?

Hi,
I am new to SF and want to learn how to create new button on Product object page layout with Buttons, Links, & Actions.

I tried to create the btn on the page, which worked using this:
<aura:component implements="force:lightningQuickAction"> 
   <center><b>This is a Lightning component </b></center>
</aura:component>

But now how do I get the fields from my product object into the pop up window and then a save btn pls?  This is what shows now :
(I put this under topic - Apex code development - is that correct?)

Thanks so much in advance!!

User-added image
Best Answer chosen by Barb Leung
Akshay Dhiman 63Akshay Dhiman 63
Hi Barb,
You can get the fields of Product Object using sObject and fetch them into the fields using their API name you can make the Save button inside your modal box using the slds-button and you can put the function name in "onClick" to perform some action when you click on save button. 
Please refer to the below code :

<aura:component>
    <aura:attribute name="product" type="Product__c" default="{'sObject':'Product__c'}" access="global"/>

    <lightning:input  aura:id="productName"  type="text" name="productName"  label=" Name" value ="{!v.product.Name}"   />
    <lightning:input  aura:id="productMrp"  type="Currency" name="productMrp"  label=" MRP" value ="{!v.product.MRP__c}"   />
    <lightning:input aura:id="productVariant" type="text" name="productVariant" label="Variant" value="{!v.product.Variant__c}" />

    <button  class="slds-button slds-button--brand" onclick="{!c.OnSave}">Save</button>
</aura:component>    

Hope this explanation will resolve your query. Mark, it as the best answer if you find it helpful.

Thanks
Akshay

All Answers

SwethaSwetha (Salesforce Developers) 
HI Barb,
Does the code mentioned in below post help to implement the Save button?
https://salesforce.stackexchange.com/questions/151000/how-to-access-the-save-button-in-a-modal-when-implementing-the-forcelightningqu?rq=1
Barb LeungBarb Leung
Hi,
Unfortunately no.  It gave an error.  In addition to the save btn i need help to get the fields from the product in the modal so the user can update...

Thanks.
Akshay Dhiman 63Akshay Dhiman 63
Hi Barb,
You can get the fields of Product Object using sObject and fetch them into the fields using their API name you can make the Save button inside your modal box using the slds-button and you can put the function name in "onClick" to perform some action when you click on save button. 
Please refer to the below code :

<aura:component>
    <aura:attribute name="product" type="Product__c" default="{'sObject':'Product__c'}" access="global"/>

    <lightning:input  aura:id="productName"  type="text" name="productName"  label=" Name" value ="{!v.product.Name}"   />
    <lightning:input  aura:id="productMrp"  type="Currency" name="productMrp"  label=" MRP" value ="{!v.product.MRP__c}"   />
    <lightning:input aura:id="productVariant" type="text" name="productVariant" label="Variant" value="{!v.product.Variant__c}" />

    <button  class="slds-button slds-button--brand" onclick="{!c.OnSave}">Save</button>
</aura:component>    

Hope this explanation will resolve your query. Mark, it as the best answer if you find it helpful.

Thanks
Akshay
This was selected as the best answer
Barb LeungBarb Leung
Hi Akshay,
Thank you for helping me.  It's soooo close.  The "cancel" btn still shows up at the bottom of the modal.  The "Save" button does show in the modal but has no functionality.  Is there additional code to make it work?  Or how can I get it to save the record now and remove the "cancel"?

This is so awesome and thanks again!