• Pritesh Khole 1
  • NEWBIE
  • 30 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 8
    Replies
Hi Team,

I have created a lightning component on leads, however I am not able to save the record. Below is my code:

LeadParentPage.cmp

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,lightning:actionOverride,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller = "LeadLightningApexController" >

<aura:attribute name="recordDetails" type="Lead[]"/>
    <aura:attribute name="simpleNewLead" type="Object"/>
    <aura:attribute name="newLeadError" type="String"/>
    <aura:attribute name="Lead"
                    type="Lead"
                    default="{ 'sobjectType': 'Lead', 'LastName': 'Unknown', 'Status':''}"/>
    <aura:attribute name="er" type="boolean" default="false"/>
    
   <!--  <force:recordData aura:id="leadRecordCreator"
                      layoutType="FULL"
                      targetRecord="{!v.newLead}"
                      targetFields="{!v.simpleNewLead}"
                      targetError="{!v.newLeadError}" />  -->
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
   <aura:attribute name="SIPEligibleReferral" type="String[]" default="None,Yes,No"/>  
    <aura:attribute name="parentOptions" type="List"/>
    <aura:attribute name="dependentPicklist" type="Object"/>
    <aura:attribute name="dependentOptions" type="List"/>
    <aura:attribute name="disabledPick" type="Boolean" default="true"/>
    
  <aura:attribute name="openModal" type="boolean" default="true"/>
    <div class="slds-m-around--xx-large">
       
    <aura:if isTrue="{!v.openModal}">
            <!--Modal Box Start-->
            <div role="dialog" class="slds-modal slds-fade-in-open ">
                <div class="slds-modal__container">
                    <div class="slds-modal__header">   
                        <button class="slds-button slds-modal__close slds-button--icon-inverse" title="Close" onclick="{!c.handleCloseModal}">
                            X
                            <span class="slds-assistive-text">Close</span>
                        </button>
                        <h1 class="slds-text-heading--medium">Lead Page</h1>
                    </div>  
                     
                    <!--Modal Box Header-->
                    <div class="slds-modal__content slds-p-around--medium">
                        <p><b>
                           <h1 class="slds-section-title--divider">Account Information</h1>
                <label class="slds-form-element__label" for="input-id-01">
                    <div style="width:200px;" class="slds-form-element__control">
                        Account  <force:inputField aura:id="Lead Field" value="{!v.Lead.Account__c}"/>
                    </div>
                </label>
                            <label class="slds-form-element__label" for="input-id-02">
                    <div style="width:200px;" class="slds-form-element__control">
                        <lightning:input aura:id="LeadField" label="Customer Company Name" value="{!v.Lead.Company}" />
                    </div>
                </label>
                            <h2 class="slds-section-title--divider">Contact Information</h2>
                <label class="slds-form-element__label" for="input-id-01">
                    <div style="width:200px;" class="slds-form-element__control">
                        Contact  <force:inputField aura:id="Lead Field" value="{!v.Lead.Contact__c}"/>
                    </div>
                </label>
                            <br></br>
                        <label class="slds-form-element__label" for="input-id-01">
                    <div style="width:200px;" class="slds-form-element__control">
                        <lightning:input aura:id="LeadField" label="First Name" value="{!v.Lead.FirstName}"/>
                    </div>
                </label>
                            <label class="slds-form-element__label" for="input-id-02">
                    <div style="width:200px;" class="slds-form-element__control">
                        <lightning:input aura:id="LeadField" label="Last Name" value="{!v.Lead.LastName}" required ="true"  />
                    </div>
                </label>
                            <h3 class="slds-section-title--divider">Lead Details</h3>
                <label class="slds-form-element__label" for="input-id-01">
                    <div style="width:200px;" class="slds-form-element__control">
                        <lightning:input aura:id="LeadField" label="Lead Name" value="{!v.Lead.Lead_Name__c}" />
                    </div>
          

                            <lightning:select name="parentPicklist" label="Lead Status" required= "true" aura:id="parentPicklist" onchange="{!c.PickChange}">
                                <option value="">None</option>
                                <aura:iteration items="{!v.parentOptions}" var="p">
                                    <option value="{!p.value}" default= "New">{!p.text}</option>
                                </aura:iteration>
                            </lightning:select>
                            
                             
                            <lightning:select name="dependentPicklist" label="Reason For Disqualification" disabled="{!v.disabledPick}">
                                <option value="">None</option>
                                <aura:iteration items="{!v.dependentOptions}" var="d">
                                    <option value="{!d.value}">{!d.text}</option>
                                </aura:iteration>
                            </lightning:select>
                          
                <label class="slds-form-element__label" for="input-id-01">
                    <div style="width:200px;" class="slds-form-element__control">
                        <lightning:input aura:id="LeadField" label="Reason Description" value="{!v.Lead.Reason__c}"/>
                    </div>
                </label>
                            </b>
                            </p>
                    </div>
                    <!--Modal Box Button-->
                    <div class="slds-modal__footer">
                        <button class="slds-button slds-button--brand" onclick="{!c.handleCloseModal}">Cancel</button>
                        <button class="slds-button slds-button--brand" onclick="{!c.doSave}">Submit</button>
                    </div>
                </div>
            </div>
            <div class="slds-backdrop slds-backdrop--open"></div>            
        </aura:if>
    </div>
</aura:component>

LeadParentPageController.js
({  
   doInit : function(component, event, helper) {
             var pVals = [
            {text:"New", value: "New"},
            {text:"Qualified", value: "Qualified"},
            {text:"Unqualified", value: "Unqualified"}
        ];
 
        var dPick = {
            "Unqualified" : [
                {text:"Change in Fleet / Not Applicable", value: "Change in Fleet / Not Applicable"},
                      
            ]
        };
 
        component.set('v.parentOptions', pVals);
        component.set('v.dependentPicklist', dPick);

       helper.getAllRecords(component);
       
       
    },
    
doSave : function(component, event, helper) {
    var Lead = component.get("v.Lead");
    helper.doSave(component, Lead);
        

    },
 
    PickChange : function(component, event, helper) {
        var parentValue = component.find('parentPicklist').get('v.value');
        component.set('v.dependentOptions', component.get('v.dependentPicklist')[parentValue]);
 
        if(parentValue != '')
        component.set('v.disabledPick',false);
        else
        component.set('v.disabledPick',true);
    },
    
    handleOpenModal: function(component, event, helper) {
        //For Display Modal, Set the "openModal" attribute to "true"
        component.set("v.openModal", true);
    },
     
    handleCloseModal: function(component, event, helper) {
        //For Close Modal, Set the "openModal" attribute to "fasle"  
        component.set("v.openModal", false);
    },
 
})

LeadParentPageHelper.js

({
    getAllRecords: function(component){
        var action = component.get("c.getAllRecords");
        action.setCallback(this, function(response){
            var state = response.getState();
            if(component.isValid() && state =="Success"){
                component.set("v.recordDetails", response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    
    doSave: function(component, recordDetail){
        this.upsertRecord(component, recordDetails, function(a){
                          var recordDetails = component.get("v.recordDetails");
        recordDetails.push(a.getReturnValue());
            component.set("v.recordDetails", recordDetails);
                          });
    },
    upsertRecord : function(component, recordDetail, callback){
        var action = component.get("c.saveRecord");
        action.setParams({
            "recordDetail": recordDetail
        });
        if(callback){
            action.setCallback(this, callback);
            
        }
        $A.enqueueAction(action);
    }
           
})

LeadLightningApexController.apxc

public with sharing class LeadLightningApexController {
    
    @AuraEnabled
    public static List<Lead> getAllRecords(){
        return [Select id, Name, Status From Lead];
    }
    
    @AuraEnabled
    public static Lead saveRecord(Lead recordDetail){
        upsert recordDetail;
        return recordDetail;
    }
    

    
}

 
Hi Team,

I am trying to create a renewal opportunity along with the product, based on some condition. I have written a trigger, however the opportunity is getting renewed but the products are not. Is there anything that I am missing. Require some help. Below is my code

trigger RenewalOpportunityProcess on Opportunity (after insert,after update) {
      Map<Opportunity,List<OpportunityLineItem>> OpportunityLineItemsMapping = new Map<Opportunity,List<OpportunityLineItem>>();

List<Opportunity> listOpp = new List <Opportunity>(); //List of Opportunity to store all the renewal Opportunities
     

    
    //Create Renewal Opportunity when stage is 'Closed Won ' and 'Create Future Renewal Opportunity' is Yes.
    for (Opportunity opp:Trigger.new){
        opp = [Select Name,StageName,AccountId, (SELECT Quantity, TotalPrice, PricebookEntry.Name, PricebookEntry.Product2.Family FROM OpportunityLineItems) from Opportunity where id=:opp.Id LIMIT 1 ];
        
        
         if(opp.StageName == 'Closed Won' && opp.AccountId != null && opp.Create_Future_Renewal_Opportunity__c == 'Yes' && opp.HasOpportunityLineItem == true)
         {          
             Opportunity oppNew = opp.clone(false,true);  //This clone method Creates a copy of the sObject record.
             oppNew.StageName = 'Qualification';
             oppNew.Name = opp.Name + ' - ' + 'RENEWAL';
             listOpp.add(oppNew);
             OpportunityLineItemsMapping.put(oppNew,opp.OpportunityLineItems.deepClone(false,false,false));
           
            }
        insert listOpp;
         
        
          
        }
    }
      
 
    
    


 
Hi Team,

On Lead, we have an Accounts as a Look up, we have a requirement that whenver the user selects an Account, the Company name should be populated with the Account Name in Real time, without saving the record. I have created the below VF page and Extension controller, however not able to achieve the result. Any help is appreciated.

Visualforce Page

<apex:page lightningStylesheets="true" standardController="Lead" extensions="LeadControllerExtension" tabStyle="Lead">
    <apex:form id="form1">
        <apex:sectionheader title="Lead Edit" subtitle="{!if(Lead.Id==null,'New Lead',Lead.Name)}">
        </apex:sectionheader>
        <apex:pageblock mode="edit" id="leadPB" title="Lead Edit">
         <apex:pageblockbuttons >
             <apex:commandbutton action="{!save}" value="Save">
             </apex:commandbutton>
          <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
             </apex:pageblockbuttons>
            <apex:pagemessages ></apex:pagemessages>
            <apex:pageblocksection id="LeadInformationPBS" title="Lead Information">
            <apex:inputfield value="{!Lead.Phone}"></apex:inputfield>
                
            <apex:pageblocksectionitem >
                <apex:outputlabel value="{!$ObjectType.Lead.Fields.FirstName.label}"></apex:outputlabel>
                <apex:outputpanel >
                <apex:inputfield value="{!Lead.Salutation}"></apex:inputfield>
                <apex:inputfield value="{!Lead.FirstName}"></apex:inputfield>
                </apex:outputpanel>
                </apex:pageblocksectionitem>
                <apex:inputfield value="{!Lead.MobilePhone}"></apex:inputfield>
                <apex:inputfield value="{!Lead.LastName}"></apex:inputfield>
                <apex:inputfield value="{!Lead.Fax}"></apex:inputfield>
                <apex:inputField value="{!Lead.Company}">
                <!---<apex:actionSupport event="onchange" action="{!getAcc}" reRender="form1"/> -->
                </apex:inputField>
                                                                <apex:inputfield value="{!Lead.Account__c}">
                  <apex:actionSupport event="onchange" action="{!getAcc}" reRender="{!pageBlockList}"/>
                    <apex:messages />
                </apex:inputfield>
                <apex:inputfield value="{!Lead.Email}"></apex:inputfield>
                <apex:inputfield value="{!Lead.Title}"></apex:inputfield>
                <apex:inputfield value="{!Lead.Website}"></apex:inputfield>
                <apex:inputfield value="{!Lead.Leadsource}"></apex:inputfield>
     <apex:inputfield value="{!Lead.Status}"></apex:inputfield>
                
     <apex:pageblocksection id="AddressInformationPBS" title="Address Information">
                <apex:inputfield value="{!Lead.Street}"></apex:inputfield>
                <apex:outputtext value=""></apex:outputtext>
                <apex:inputfield value="{!Lead.City}"></apex:inputfield>
     <apex:outputtext value=""></apex:outputtext>
                <apex:inputfield value="{!Lead.State}"></apex:inputfield>
     <apex:outputtext value=""></apex:outputtext>
                <apex:inputfield value="{!Lead.PostalCode}"></apex:inputfield>
                <apex:outputtext value=""></apex:outputtext>
                <apex:inputfield value="{!Lead.Country}"></apex:inputfield>
                <apex:outputtext value=""></apex:outputtext>
                                                   
      </apex:pageblocksection>
      </apex:pageblocksection>
         
    </apex:pageblock>
  </apex:form>
       
</apex:page>

Extension Controller:

public with sharing class LeadControllerExtension
{
public Lead LR{get;set;}
public Account con{get;set;}
    
public ApexPages.StandardController stdcntrl{get;set;}
public LeadControllerExtension(ApexPages.StandardController cntrl){
stdcntrl=cntrl;
this.LR = (Lead) stdcntrl.getRecord();
}
    
 public string getAcc(){
     //apexpages.addMessage(new ApexPages.message(ApexPages.Severity.INFO, 'Company Value' ));
//Lead new l1=new Lead();
LR=[Select id,name,Account__c,Company from Lead LIMIT 1];
con=[select name from Account where id= :LR.Account__c];

 LR.Company=con.Name;
return LR.Company;

    }

                }

 
Component Code:

    <aura:component >
  <aura:attribute name="newItem" type="Camping_Item__c"

         default="{ 'sobjectType': 'Camping_Item__c',

                        'Name': '',

                        'Quantity__c': 0,

                        'Price__c': 0,

                        'Packed__c': false }"/>

         

        <aura:attribute name="items" type="Camping_Item__c[]"/>

         

        <ol>

        <li>Bug Spray</li>

        <li>Bear Repellant</li>

        <li>Goat Food</li>

        </ol>

         

        <!-- CREATE NEW ITEM FORM -->

        <form class="slds-form--stacked">

    

          <div class="slds-form-element slds-is-required">

              <div class="slds-form-element__control">

                  <lightning:input aura:id="itemname" label="Name"

                      class="slds-input"

                      

                      value="{!v.newItem.Name}"

                      required="true"/>

              </div>

         </div>

    

         <div class="slds-form-element slds-is-required">

              <div class="slds-form-element__control">

                 <lightning:input type="number" label="Quantity"
                                        class="slds-input"
                                        name="quantity"
                                        min="1"
                                        value="{!v.newItem.Quantity__c}"
                                        required="true" aura:id="quantity"/>

    

              </div>

          </div>

    

          <div class="slds-form-element">

              <div class="slds-form-element__control">

                  <lightning:input type= "number" aura:id="price" label="Price"
                                   formatter="currency"

                      class="slds-input"

                     value="{!v.newItem.Price__c}" />

              </div>

          </div>
    

          <div class="slds-form-element">

              <lightning:input type = "checkbox" aura:id="itemform" label="Packed?"

                  class="slds-checkbox"

                  

                  checked="{!v.newItem.Packed__c}"/>

          </div>

    

          <div class="slds-form-element">

              <lightning:button label="Create Camping Item"

                  class="slds-button slds-button--brand"

                  onclick="{!c.clickCreateItem}"/>

          </div>

    

        </form>

        <!-- / CREATE NEW ITEM FORM -->

         

        

    

        <div class="slds-card slds-p-top--medium">

            <header class="slds-card__header">

                <h3 class="slds-text-heading--small">Items</h3>

            </header>

             

            <section class="slds-card__body">

                <div id="list" class="row">

                    <aura:iteration items="{!v.items}" var="items">

                        <c:campingListItem item="{!item}"/>

                    </aura:iteration>

                </div>

            </section>

        </div>

    

    </aura:component>

Controller code:
({
clickCreateItem: function(component, event, helper) {

    // Simplistic error checking
    var validItem = true;

    // Name must not be blank
    var nameField = component.find("itemname");
    var itemname = nameField.get("v.value");
    if ($A.util.isEmpty(itemname)){
        validItem = false;
        nameField.set("v.errors", [{message:"Item name can't be blank."}]);
    }
    else {
        nameField.set("v.errors", null);
    }

    // Quantity must not be blank
    var quantityField = component.find("quantity");
    var quantity = nameField.get("v.value");
    if ($A.util.isEmpty(quantity)){
        validItem = false;
        quantityField.set("v.errors", [{message:"Quantity can't be blank."}]);
    }
    else {
        quantityField.set("v.errors", null);
    }

    var priceField = component.find("price");
    var price = priceField.get("v.value");
    if ($A.util.isEmpty(price)){
        validItem = false;
        priceField.set("v.errors", [{message:"Price can't be blank."}]);
    }
    else {
        quantityField.set("v.errors", null);
    }


    if(validItem){
        var newItem = component.get("v.newItem");
        console.log("Create item: " + JSON.stringify(newItem));
        //helper.createItem(component, newItem);
        //        var theItems = component.get("v.items");

    // Copy the expense to a new object
    // THIS IS A DISGUSTING, TEMPORARY HACK
    var newItem = JSON.parse(JSON.stringify(item));

    console.log("Items before 'create': " + JSON.stringify(theItems));
    theExpenses.push(newItem);
    component.set("v.expenses", theItems);
    console.log("Items after 'create': " + JSON.stringify(theItems));
    theItems.push(newItem);
    component.set("v.items", theItems);

    }
}

})


Requesting your help to let me know what is wrong with the code?
Hi Team,

I have created a lightning component on leads, however I am not able to save the record. Below is my code:

LeadParentPage.cmp

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,lightning:actionOverride,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller = "LeadLightningApexController" >

<aura:attribute name="recordDetails" type="Lead[]"/>
    <aura:attribute name="simpleNewLead" type="Object"/>
    <aura:attribute name="newLeadError" type="String"/>
    <aura:attribute name="Lead"
                    type="Lead"
                    default="{ 'sobjectType': 'Lead', 'LastName': 'Unknown', 'Status':''}"/>
    <aura:attribute name="er" type="boolean" default="false"/>
    
   <!--  <force:recordData aura:id="leadRecordCreator"
                      layoutType="FULL"
                      targetRecord="{!v.newLead}"
                      targetFields="{!v.simpleNewLead}"
                      targetError="{!v.newLeadError}" />  -->
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
   <aura:attribute name="SIPEligibleReferral" type="String[]" default="None,Yes,No"/>  
    <aura:attribute name="parentOptions" type="List"/>
    <aura:attribute name="dependentPicklist" type="Object"/>
    <aura:attribute name="dependentOptions" type="List"/>
    <aura:attribute name="disabledPick" type="Boolean" default="true"/>
    
  <aura:attribute name="openModal" type="boolean" default="true"/>
    <div class="slds-m-around--xx-large">
       
    <aura:if isTrue="{!v.openModal}">
            <!--Modal Box Start-->
            <div role="dialog" class="slds-modal slds-fade-in-open ">
                <div class="slds-modal__container">
                    <div class="slds-modal__header">   
                        <button class="slds-button slds-modal__close slds-button--icon-inverse" title="Close" onclick="{!c.handleCloseModal}">
                            X
                            <span class="slds-assistive-text">Close</span>
                        </button>
                        <h1 class="slds-text-heading--medium">Lead Page</h1>
                    </div>  
                     
                    <!--Modal Box Header-->
                    <div class="slds-modal__content slds-p-around--medium">
                        <p><b>
                           <h1 class="slds-section-title--divider">Account Information</h1>
                <label class="slds-form-element__label" for="input-id-01">
                    <div style="width:200px;" class="slds-form-element__control">
                        Account  <force:inputField aura:id="Lead Field" value="{!v.Lead.Account__c}"/>
                    </div>
                </label>
                            <label class="slds-form-element__label" for="input-id-02">
                    <div style="width:200px;" class="slds-form-element__control">
                        <lightning:input aura:id="LeadField" label="Customer Company Name" value="{!v.Lead.Company}" />
                    </div>
                </label>
                            <h2 class="slds-section-title--divider">Contact Information</h2>
                <label class="slds-form-element__label" for="input-id-01">
                    <div style="width:200px;" class="slds-form-element__control">
                        Contact  <force:inputField aura:id="Lead Field" value="{!v.Lead.Contact__c}"/>
                    </div>
                </label>
                            <br></br>
                        <label class="slds-form-element__label" for="input-id-01">
                    <div style="width:200px;" class="slds-form-element__control">
                        <lightning:input aura:id="LeadField" label="First Name" value="{!v.Lead.FirstName}"/>
                    </div>
                </label>
                            <label class="slds-form-element__label" for="input-id-02">
                    <div style="width:200px;" class="slds-form-element__control">
                        <lightning:input aura:id="LeadField" label="Last Name" value="{!v.Lead.LastName}" required ="true"  />
                    </div>
                </label>
                            <h3 class="slds-section-title--divider">Lead Details</h3>
                <label class="slds-form-element__label" for="input-id-01">
                    <div style="width:200px;" class="slds-form-element__control">
                        <lightning:input aura:id="LeadField" label="Lead Name" value="{!v.Lead.Lead_Name__c}" />
                    </div>
          

                            <lightning:select name="parentPicklist" label="Lead Status" required= "true" aura:id="parentPicklist" onchange="{!c.PickChange}">
                                <option value="">None</option>
                                <aura:iteration items="{!v.parentOptions}" var="p">
                                    <option value="{!p.value}" default= "New">{!p.text}</option>
                                </aura:iteration>
                            </lightning:select>
                            
                             
                            <lightning:select name="dependentPicklist" label="Reason For Disqualification" disabled="{!v.disabledPick}">
                                <option value="">None</option>
                                <aura:iteration items="{!v.dependentOptions}" var="d">
                                    <option value="{!d.value}">{!d.text}</option>
                                </aura:iteration>
                            </lightning:select>
                          
                <label class="slds-form-element__label" for="input-id-01">
                    <div style="width:200px;" class="slds-form-element__control">
                        <lightning:input aura:id="LeadField" label="Reason Description" value="{!v.Lead.Reason__c}"/>
                    </div>
                </label>
                            </b>
                            </p>
                    </div>
                    <!--Modal Box Button-->
                    <div class="slds-modal__footer">
                        <button class="slds-button slds-button--brand" onclick="{!c.handleCloseModal}">Cancel</button>
                        <button class="slds-button slds-button--brand" onclick="{!c.doSave}">Submit</button>
                    </div>
                </div>
            </div>
            <div class="slds-backdrop slds-backdrop--open"></div>            
        </aura:if>
    </div>
</aura:component>

LeadParentPageController.js
({  
   doInit : function(component, event, helper) {
             var pVals = [
            {text:"New", value: "New"},
            {text:"Qualified", value: "Qualified"},
            {text:"Unqualified", value: "Unqualified"}
        ];
 
        var dPick = {
            "Unqualified" : [
                {text:"Change in Fleet / Not Applicable", value: "Change in Fleet / Not Applicable"},
                      
            ]
        };
 
        component.set('v.parentOptions', pVals);
        component.set('v.dependentPicklist', dPick);

       helper.getAllRecords(component);
       
       
    },
    
doSave : function(component, event, helper) {
    var Lead = component.get("v.Lead");
    helper.doSave(component, Lead);
        

    },
 
    PickChange : function(component, event, helper) {
        var parentValue = component.find('parentPicklist').get('v.value');
        component.set('v.dependentOptions', component.get('v.dependentPicklist')[parentValue]);
 
        if(parentValue != '')
        component.set('v.disabledPick',false);
        else
        component.set('v.disabledPick',true);
    },
    
    handleOpenModal: function(component, event, helper) {
        //For Display Modal, Set the "openModal" attribute to "true"
        component.set("v.openModal", true);
    },
     
    handleCloseModal: function(component, event, helper) {
        //For Close Modal, Set the "openModal" attribute to "fasle"  
        component.set("v.openModal", false);
    },
 
})

LeadParentPageHelper.js

({
    getAllRecords: function(component){
        var action = component.get("c.getAllRecords");
        action.setCallback(this, function(response){
            var state = response.getState();
            if(component.isValid() && state =="Success"){
                component.set("v.recordDetails", response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
    
    doSave: function(component, recordDetail){
        this.upsertRecord(component, recordDetails, function(a){
                          var recordDetails = component.get("v.recordDetails");
        recordDetails.push(a.getReturnValue());
            component.set("v.recordDetails", recordDetails);
                          });
    },
    upsertRecord : function(component, recordDetail, callback){
        var action = component.get("c.saveRecord");
        action.setParams({
            "recordDetail": recordDetail
        });
        if(callback){
            action.setCallback(this, callback);
            
        }
        $A.enqueueAction(action);
    }
           
})

LeadLightningApexController.apxc

public with sharing class LeadLightningApexController {
    
    @AuraEnabled
    public static List<Lead> getAllRecords(){
        return [Select id, Name, Status From Lead];
    }
    
    @AuraEnabled
    public static Lead saveRecord(Lead recordDetail){
        upsert recordDetail;
        return recordDetail;
    }
    

    
}

 
Hi Team,

I am trying to create a renewal opportunity along with the product, based on some condition. I have written a trigger, however the opportunity is getting renewed but the products are not. Is there anything that I am missing. Require some help. Below is my code

trigger RenewalOpportunityProcess on Opportunity (after insert,after update) {
      Map<Opportunity,List<OpportunityLineItem>> OpportunityLineItemsMapping = new Map<Opportunity,List<OpportunityLineItem>>();

List<Opportunity> listOpp = new List <Opportunity>(); //List of Opportunity to store all the renewal Opportunities
     

    
    //Create Renewal Opportunity when stage is 'Closed Won ' and 'Create Future Renewal Opportunity' is Yes.
    for (Opportunity opp:Trigger.new){
        opp = [Select Name,StageName,AccountId, (SELECT Quantity, TotalPrice, PricebookEntry.Name, PricebookEntry.Product2.Family FROM OpportunityLineItems) from Opportunity where id=:opp.Id LIMIT 1 ];
        
        
         if(opp.StageName == 'Closed Won' && opp.AccountId != null && opp.Create_Future_Renewal_Opportunity__c == 'Yes' && opp.HasOpportunityLineItem == true)
         {          
             Opportunity oppNew = opp.clone(false,true);  //This clone method Creates a copy of the sObject record.
             oppNew.StageName = 'Qualification';
             oppNew.Name = opp.Name + ' - ' + 'RENEWAL';
             listOpp.add(oppNew);
             OpportunityLineItemsMapping.put(oppNew,opp.OpportunityLineItems.deepClone(false,false,false));
           
            }
        insert listOpp;
         
        
          
        }
    }
      
 
    
    


 
Hi Team,

On Lead, we have an Accounts as a Look up, we have a requirement that whenver the user selects an Account, the Company name should be populated with the Account Name in Real time, without saving the record. I have created the below VF page and Extension controller, however not able to achieve the result. Any help is appreciated.

Visualforce Page

<apex:page lightningStylesheets="true" standardController="Lead" extensions="LeadControllerExtension" tabStyle="Lead">
    <apex:form id="form1">
        <apex:sectionheader title="Lead Edit" subtitle="{!if(Lead.Id==null,'New Lead',Lead.Name)}">
        </apex:sectionheader>
        <apex:pageblock mode="edit" id="leadPB" title="Lead Edit">
         <apex:pageblockbuttons >
             <apex:commandbutton action="{!save}" value="Save">
             </apex:commandbutton>
          <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
             </apex:pageblockbuttons>
            <apex:pagemessages ></apex:pagemessages>
            <apex:pageblocksection id="LeadInformationPBS" title="Lead Information">
            <apex:inputfield value="{!Lead.Phone}"></apex:inputfield>
                
            <apex:pageblocksectionitem >
                <apex:outputlabel value="{!$ObjectType.Lead.Fields.FirstName.label}"></apex:outputlabel>
                <apex:outputpanel >
                <apex:inputfield value="{!Lead.Salutation}"></apex:inputfield>
                <apex:inputfield value="{!Lead.FirstName}"></apex:inputfield>
                </apex:outputpanel>
                </apex:pageblocksectionitem>
                <apex:inputfield value="{!Lead.MobilePhone}"></apex:inputfield>
                <apex:inputfield value="{!Lead.LastName}"></apex:inputfield>
                <apex:inputfield value="{!Lead.Fax}"></apex:inputfield>
                <apex:inputField value="{!Lead.Company}">
                <!---<apex:actionSupport event="onchange" action="{!getAcc}" reRender="form1"/> -->
                </apex:inputField>
                                                                <apex:inputfield value="{!Lead.Account__c}">
                  <apex:actionSupport event="onchange" action="{!getAcc}" reRender="{!pageBlockList}"/>
                    <apex:messages />
                </apex:inputfield>
                <apex:inputfield value="{!Lead.Email}"></apex:inputfield>
                <apex:inputfield value="{!Lead.Title}"></apex:inputfield>
                <apex:inputfield value="{!Lead.Website}"></apex:inputfield>
                <apex:inputfield value="{!Lead.Leadsource}"></apex:inputfield>
     <apex:inputfield value="{!Lead.Status}"></apex:inputfield>
                
     <apex:pageblocksection id="AddressInformationPBS" title="Address Information">
                <apex:inputfield value="{!Lead.Street}"></apex:inputfield>
                <apex:outputtext value=""></apex:outputtext>
                <apex:inputfield value="{!Lead.City}"></apex:inputfield>
     <apex:outputtext value=""></apex:outputtext>
                <apex:inputfield value="{!Lead.State}"></apex:inputfield>
     <apex:outputtext value=""></apex:outputtext>
                <apex:inputfield value="{!Lead.PostalCode}"></apex:inputfield>
                <apex:outputtext value=""></apex:outputtext>
                <apex:inputfield value="{!Lead.Country}"></apex:inputfield>
                <apex:outputtext value=""></apex:outputtext>
                                                   
      </apex:pageblocksection>
      </apex:pageblocksection>
         
    </apex:pageblock>
  </apex:form>
       
</apex:page>

Extension Controller:

public with sharing class LeadControllerExtension
{
public Lead LR{get;set;}
public Account con{get;set;}
    
public ApexPages.StandardController stdcntrl{get;set;}
public LeadControllerExtension(ApexPages.StandardController cntrl){
stdcntrl=cntrl;
this.LR = (Lead) stdcntrl.getRecord();
}
    
 public string getAcc(){
     //apexpages.addMessage(new ApexPages.message(ApexPages.Severity.INFO, 'Company Value' ));
//Lead new l1=new Lead();
LR=[Select id,name,Account__c,Company from Lead LIMIT 1];
con=[select name from Account where id= :LR.Account__c];

 LR.Company=con.Name;
return LR.Company;

    }

                }

 
Component Code:

    <aura:component >
  <aura:attribute name="newItem" type="Camping_Item__c"

         default="{ 'sobjectType': 'Camping_Item__c',

                        'Name': '',

                        'Quantity__c': 0,

                        'Price__c': 0,

                        'Packed__c': false }"/>

         

        <aura:attribute name="items" type="Camping_Item__c[]"/>

         

        <ol>

        <li>Bug Spray</li>

        <li>Bear Repellant</li>

        <li>Goat Food</li>

        </ol>

         

        <!-- CREATE NEW ITEM FORM -->

        <form class="slds-form--stacked">

    

          <div class="slds-form-element slds-is-required">

              <div class="slds-form-element__control">

                  <lightning:input aura:id="itemname" label="Name"

                      class="slds-input"

                      

                      value="{!v.newItem.Name}"

                      required="true"/>

              </div>

         </div>

    

         <div class="slds-form-element slds-is-required">

              <div class="slds-form-element__control">

                 <lightning:input type="number" label="Quantity"
                                        class="slds-input"
                                        name="quantity"
                                        min="1"
                                        value="{!v.newItem.Quantity__c}"
                                        required="true" aura:id="quantity"/>

    

              </div>

          </div>

    

          <div class="slds-form-element">

              <div class="slds-form-element__control">

                  <lightning:input type= "number" aura:id="price" label="Price"
                                   formatter="currency"

                      class="slds-input"

                     value="{!v.newItem.Price__c}" />

              </div>

          </div>
    

          <div class="slds-form-element">

              <lightning:input type = "checkbox" aura:id="itemform" label="Packed?"

                  class="slds-checkbox"

                  

                  checked="{!v.newItem.Packed__c}"/>

          </div>

    

          <div class="slds-form-element">

              <lightning:button label="Create Camping Item"

                  class="slds-button slds-button--brand"

                  onclick="{!c.clickCreateItem}"/>

          </div>

    

        </form>

        <!-- / CREATE NEW ITEM FORM -->

         

        

    

        <div class="slds-card slds-p-top--medium">

            <header class="slds-card__header">

                <h3 class="slds-text-heading--small">Items</h3>

            </header>

             

            <section class="slds-card__body">

                <div id="list" class="row">

                    <aura:iteration items="{!v.items}" var="items">

                        <c:campingListItem item="{!item}"/>

                    </aura:iteration>

                </div>

            </section>

        </div>

    

    </aura:component>

Controller code:
({
clickCreateItem: function(component, event, helper) {

    // Simplistic error checking
    var validItem = true;

    // Name must not be blank
    var nameField = component.find("itemname");
    var itemname = nameField.get("v.value");
    if ($A.util.isEmpty(itemname)){
        validItem = false;
        nameField.set("v.errors", [{message:"Item name can't be blank."}]);
    }
    else {
        nameField.set("v.errors", null);
    }

    // Quantity must not be blank
    var quantityField = component.find("quantity");
    var quantity = nameField.get("v.value");
    if ($A.util.isEmpty(quantity)){
        validItem = false;
        quantityField.set("v.errors", [{message:"Quantity can't be blank."}]);
    }
    else {
        quantityField.set("v.errors", null);
    }

    var priceField = component.find("price");
    var price = priceField.get("v.value");
    if ($A.util.isEmpty(price)){
        validItem = false;
        priceField.set("v.errors", [{message:"Price can't be blank."}]);
    }
    else {
        quantityField.set("v.errors", null);
    }


    if(validItem){
        var newItem = component.get("v.newItem");
        console.log("Create item: " + JSON.stringify(newItem));
        //helper.createItem(component, newItem);
        //        var theItems = component.get("v.items");

    // Copy the expense to a new object
    // THIS IS A DISGUSTING, TEMPORARY HACK
    var newItem = JSON.parse(JSON.stringify(item));

    console.log("Items before 'create': " + JSON.stringify(theItems));
    theExpenses.push(newItem);
    component.set("v.expenses", theItems);
    console.log("Items after 'create': " + JSON.stringify(theItems));
    theItems.push(newItem);
    component.set("v.items", theItems);

    }
}

})


Requesting your help to let me know what is wrong with the code?