• kashish choudhary
  • 0 Points
  • Member since 2019

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 2

I try to make a quik action and a lightning component to create a quote :

<aura:component controller="QuickQuoteController" 

    <aura:attribute name="opportunity" type="Opportunity" />
    <aura:attribute name="newQuote" type="Quote"
        default="{ 'sobjectType': 'Quote' }" />
    <!-- default to empty record -->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

    <!-- Display a header with details about the opportunity -->
    <div class="slds-page-header" role="banner">
        <p class="slds-text-heading_label">{!v.opportunity.Name}</p>
        <h1 class="slds-page-header__title slds-m-right_small
            slds-truncate slds-align-left">Créer un nouveau devis</h1>

    <!-- Display the new quote form -->
     <lightning:input aura:id="quoteField" name="name" label="Name"
                      value="{!v.newQuote.Name}" required="true"/>

    <lightning:input aura:id="quoteField" type="date" name="date" label="Date"
                     value="{!v.newQuote.Date}" required="true"/>
    <lightning:button label="Cancel" onclick="{!c.handleCancel}" class="slds-m-top_medium" />
    <lightning:button label="Save Quote" onclick="{!c.handleSaveQuote}"
               variant="brand" class="slds-m-top_medium"/>

    doInit : function(component, event, helper) {

        // Prepare the action to load opportunity record
        var action = component.get("c.getOpportunity");
        action.setParams({"opportunityId": component.get("v.recordId")});

        // Configure response handler
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS") {
                component.set("v.opportunity", response.getReturnValue());
            } else {
                console.log('Problem getting opportunity, response state: ' + state);

    handleSaveQuote: function(component, event, helper) {
        if(helper.validateQuoteForm(component)) {
            // Prepare the action to create the new quote
            var saveQuoteAction = component.get("c.saveQuoteWithOpportunity");
                "quote": component.get("v.newQuote"),
                "opportunityId": component.get("v.recordId")

            // Configure the response handler for the action
            saveQuoteAction.setCallback(this, function(response) {
                var state = response.getState();
                if(state === "SUCCESS") {

                    // Prepare a toast UI message
                    var resultsToast = $A.get("e.force:showToast");
                        "title": "Quote Saved",
                        "message": "The new quote was created."

                    // Update the UI: close panel, show toast, refresh quote page
                else if (state === "ERROR") {
                    console.log('Problem saving quote, response state: ' + state);
                else {
                    console.log('Unknown problem, response state: ' + state);

            // Send the request to create the new quote

	handleCancel: function(component, event, helper) {


    validateQuoteForm: function(component) {
        var validQuote = true;

        // Show error messages if required fields are blank
        var allValid = component.find('quoteField').reduce(function (validFields, inputCmp) {
            return validFields && inputCmp.get('v.validity').valid;
        }, true);

        if (allValid) {
        // Verify we have an opportunity to attach it to
        var opportunity = component.get("v.opportunity");
        if($A.util.isEmpty(opportunity)) {
            validOpportunity = false;
            console.log("Quick action context doesn't have a valid opportunity.");


public with sharing class QuickQuoteController {

    public static Opportunity getOpportunity(Id opportunityId) {
        // Perform isAccessible() checks here
        return [SELECT Name FROM Opportunity WHERE Id = :opportunityId];
    public static Quote saveQuoteWithOpportunity(Quote quote, Id opportunityId) {
        // Perform isAccessible() and isUpdateable() checks here
        quote.OpportunityId = opportunityId;
        upsert quote;
        return quote;

I have an issue and I can't find where it comes :
Uncaught Action failed: c:quickQuote$controller$handleSaveQuote [validOpportunity is not defined]



Any idea ?
I have a requirement to prepopulate some fields (Address Fields) when standard "New" button is clicked from the related list (Contact) of Account. This was being achieved using an intermediate VF page in classic.
Now in lightning, I am able to create a component with a quick action to achieve the same - but the problem here is that the override has to be either a vf page or a lightning component.
Is there any way to have both on a single button - like when in classic, follow the old approach by redirecting to an intermediate vf and prepopulating the values and when in lightning, use the newly created lightning component?