• Muddassar Jawed
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello.
I am creating a lightning component to override the New Opportunity button. Stagename is excluded, as I populate that field with an Apex trigger. What is the most efficient way to search for the account? I have 85,000 accounts, so should I use a combo box.... I need an idea on what to use.  Right now, the user has to enter the AccountID to save. Thanks in advance! 

NewOpp.apxc
public class NewOpp {
    
    @AuraEnabled
    public static void saveOpp(Opportunity opp) {
        system.debug('opp:' + opp);

        insert opp;
        //return opp.id;
    }
}

NewOpp.cmp
<aura:component controller="NewOpp" implements="flexipage:availableForAllPageTypes,lightning:actionOverride" access="global" >
    <aura:attribute name="opps" type="Opportunity[]"/>

    
    <aura:attribute name="newOpp" type="Opportunity"
                    default="{ 'sobjectType': 'Opportunity',
                             'Name': '',
                             'AccountId': '',
                             'CloseDate': '',
                             'Amount': 0 }"/>
    
    <lightning:card iconName="standard:opportunity" title="New Opportunity">
        <form class="slds-form--stacked">         
            <lightning:input aura:id="oppform" label="Owner"
                             name="ownername"
                             value="{!v.newOpp.AccountId}"
                             required="true"/>
            
            <lightning:input aura:id="oppform" label="Opportunity Name"
                             name="oppname"
                             value="{!v.newOpp.Name}"
                             required="true"/>
            
            <lightning:input type="number" aura:id="oppform" label="Revenue"
                             name="revenue"
                             value="{!v.newOpp.Amount}"
                             required="true"/>
            
            <lightning:input type="date" aura:id="oppform" label="Estimated Close Date"
                             name="closedate"
                             value="{!v.newOpp.CloseDate}"
                             required="true"/>
            <lightning:button label="Save"
                          class="slds-m-top--medium"
                          variant="brand"
                          onclick="{!c.clickCreate}"/>

        </form>
    </lightning:card>
</aura:component>

NewOppController.js
({
    clickCreate: function(component, event, helper) {
        var validOpp = component.find('oppform').reduce(function (validSoFar, inputCmp) {
            // Displays error messages for invalid fields
            inputCmp.showHelpMessageIfInvalid();
            return validSoFar && inputCmp.get('v.validity').valid;
        }, true);
        // If we pass error checking, do some real work
        if(validOpp){
            // Create the new expense
            var newOpp = component.get("v.newOpp");
            console.log("Create opp: " + JSON.stringify(newOpp));
            helper.createOpp(component, newOpp);
        }
    }
})

NewOppHelper.js
({
    createOpp: function(component, opp) {
    var action = component.get("c.saveOpp");
    action.setParams({
        "opp": opp
    });
    action.setCallback(this, function(response){
        var state = response.getState();
        if (state === "SUCCESS") {
            var opps = component.get("v.opps");
            opps.push(response.getReturnValue());
            component.set("v.opps", opps);
          //  var urlOpp = $A.get("e.force:navigateToURL");
          //  urlOpp.setParams({
          //      "url": response.getReturnValue()
                
          //  });
          //  urlOpp.fire();
         
        }
    });
    $A.enqueueAction(action);
},

})

Thanks so much for your help!