function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ManjusrinuManjusrinu 

Display Input Fields on Page and when user fills the data ,It should be saved and navigate to record id of Opportunity

I  am able to pass the record id into lightning-component(From Vf page) ,but in the output page i am just getting Empty Form without any data populating .I should get Currrent Opp Details

I have seen that in console i am getting the Opportunity Id,But why data is not populating in input fields

Visualforce-Page : 

<apex:page standardController="Opportunity" extensions="PassingParaFromVfPageToCmp">
    <apex:includeLightning />
    <div  id="LightningCompContainer" />  <!--Used to display lightning component-->
     
    <script>
        $Lightning.use("c:EnrollemetFormApp", function() {
            $Lightning.createComponent("c:EnrollemetForm", {
            OppIdfromVfPage:"{!JSENCODE(Opportunity.Id)}"},
            "LightningCompContainer",
            function(cmp) {
               
            });
        });
    </script>
</apex:page>

Controller Method : 

public class PassingParaFromVfPageToCmp {
   public Id oppId;
public  PassingParaFromVfPageToCmp(Apexpages.StandardController stdcontroller) {
       oppId = Apexpages.currentPage().getParameters().get('id');
    system.debug('OPPPPP' +oppId);
}
}

Aura : Component :

<aura:component  controller="EnrollementFormCmp" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" 
                access="global" >
    <b> Details </b>
    <aura:attribute name="OppIdfromVfPage" type="string"/>
   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
     <aura:attribute name="Opp" type="Opportunity" default="{'SobjectType' : 'Opportunity'}"/>
    <div class="slds-p-around_Small">
            <lightning:recordEditForm objectApiName="Opportunity"
                                          recordId= '{!v.recordId}'>
                <lightning:messages />
                <lightning:inputField fieldName="Name" value="{!v.Name}" />
                <lightning:inputField fieldName="Actual_Cost__c" value="{!v.Actual_Cost__c}"/>
                <lightning:inputField fieldName="Requested_For_Loan_Assistance__c" value="{!v.Requested_For_Loan_Assistance__c}" />
                 <lightning:inputField fieldName="Account.Name" value="{!v.Account.Name}"/>
                 <lightning:inputField fieldName="Discount__c" value="{!v.Discount__c}" />
                 <lightning:inputField fieldName="Batch__c" value="{!v.Batch__c}" />
                <lightning:inputField fieldName="Course_Interest__c"  value="{!v.Course_Interest__c}"/>
                <center>
               <lightning:button variant="brand" label="Save" title="Brand action" />
                </center>
            </lightning:recordEditForm>
        </div>      
</aura:component>

Js.Method :

({
    doInit : function(component, event, helper) {
       var oppFromVfPage =component.get('v.OppIdfromVfPage');
        console.log('aaaaaaaaa'+ oppFromVfPage);
        var action = component.get("c.GetOpportunityDetails");
       action.setParams({ currentOppId : oppFromVfPage });
       $A.enqueueAction(action);
    }
})

Aura-Enabled Method :
public class EnrollementFormCmp {
    @AuraEnabled
    public static void  GetOpportunityDetails(Id currentOppId) {
        Opportunity opp = [SELECT Actual_Cost__c, Id,
                           Requested_For_Loan_Assistance__c,
                           Account.Name,
                           Discount__c,
                           Batch__c,Course_Interest__c FROM Opportunity where Id =:currentOppId ];
    }
}

 

Note : Vf-page is being called from cutom button from Opportunity Detail page . Can any one help me how to solve this issue

Maharajan CMaharajan C
Hi Manju,

You have to set the recordId to load the record edit form:

Change the doInit method like below and try: 

No need of apex class and call back functions to load the date in UI.
({
    doInit : function(component, event, helper) {
        var oppFromVfPage =component.get('v.OppIdfromVfPage');
        console.log('aaaaaaaaa'+ oppFromVfPage);
        component.set('v.recordId', oppFromVfPage);
    }
})

Also add the below highlighted chanes in compnent:
 
<aura:component  controller="EnrollementFormCmp" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" 
                access="global" >
    <b> Details </b>
    <aura:attribute name="OppIdfromVfPage" type="string"/>
   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
     <aura:attribute name="Opp" type="Opportunity" default="{'SobjectType' : 'Opportunity'}"/>
    <div class="slds-p-around_Small">
            <lightning:recordEditForm objectApiName="Opportunity"
                                          recordId= '{!v.recordId}'>
                <lightning:messages />
                <lightning:inputField fieldName="Name" value="{!v.Name}" />
                <lightning:inputField fieldName="Actual_Cost__c" value="{!v.Actual_Cost__c}"/>
                <lightning:inputField fieldName="Requested_For_Loan_Assistance__c" value="{!v.Requested_For_Loan_Assistance__c}" />
                 <lightning:inputField fieldName="AccountId" value="{!v.AccountId}"/>
                 <lightning:inputField fieldName="Discount__c" value="{!v.Discount__c}" />
                 <lightning:inputField fieldName="Batch__c" value="{!v.Batch__c}" />
                <lightning:inputField fieldName="Course_Interest__c"  value="{!v.Course_Interest__c}"/>
                <center>
               <!-- <lightning:button variant="brand" label="Save" title="Brand action" />  -->
                <lightning:button variant="brand" type="submit" name="save" label="Save" />
                </center>
            </lightning:recordEditForm>
        </div>      
</aura:component>


Thanks,
Maharajan.C
Suraj Tripathi 47Suraj Tripathi 47

Hi,

Please make this update this method like the below i.e. change return type

@AuraEnabled
    public static Opportunity  GetOpportunityDetails(Id currentOppId) {
        Opportunity opp = [SELECT Actual_Cost__c, Id,
                           Requested_For_Loan_Assistance__c,
                           Account.Name,
                           Discount__c,
                           Batch__c,Course_Interest__c FROM Opportunity where Id =:currentOppId ];
system.debug('data coming? '+opp);

return opp;

    }
doInit : function(component, event, helper) {
       var oppFromVfPage =component.get('v.OppIdfromVfPage');
        console.log('aaaaaaaaa'+ oppFromVfPage);
        var action = component.get("c.GetOpportunityDetails");
       action.setParams({ currentOppId : oppFromVfPage });
      if(response.getReturnValue()!=null){
      component.set("v.Opp",response.getReturnValue());
      }
       $A.enqueueAction(action);
    }

and change your input like the below

<lightning:inputField fieldName="Name" value="{!Opp.Name}" />

Please mark it as the best answer if your queries are solved.

Thank You