Skip to main content
Hi Team,

I want to convert below constructor to static method in lightning server class.

public  newOpportunity(ApexPages.StandardController controller) {

       recordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('test Opportunity').getRecordTypeId();

        

       Opp=(opportunity)controller.getRecord();

       system.debug('opp=='+opp);

       strObject='Opportunity';

}

Please help me how to convert static method i want to call this method to lightning component.
1 réponse
  1. 7 mai 2020, 12:47
    Hi, 

    It appears that you are trying to get the record ID primarily using the standard controller anotation in your constructor

    The force:hasRecordId interface indicates the current record Id should be injected in the component’s recordId attribute so you can define recordId attribute as follows instead of converting your constructor to auraEnabled

    <aura:attribute name="recordId" type="Id" />

    When the component is instantiated on the page, the current record Id is automatically injected in the recordId attribute. You can then make calls to the server passing the recordId as a parameter to retrieve or save data for that specific record.

    Example Code: 

     

    action.setParams({

                "accountId": component.get("v.recordId")

            });

    Reference: https://developer.salesforce.com/blogs/developer-relations/2015/11/building-context-aware-lightning-components.html

    If you still intend to convert this auraEnabled, you need to declare a static method. Please see examples in the below document

    http://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_apex_auraenabled_annotation.htm

    Anudeep
0/9000