2

I have an onclick javascript button and converted this button to an lightning component(full) using the Lightning Experience Configuration Converter tool.

But,when I'm testing the converted button,onclick of it is showing me this error.I'm unable to fix this.I did a lot of research on this,and I couldn't find any appropriate solution.

Please give me some suggestions to fix this issue.

LCC converted button error

component:

<aura:component extends="c:LCC_GenericLightningComponent">

    <aura:attribute name="partiallyConfirm" type="boolean" default="false"/>

    <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
        <aura:renderIf isTrue="{!v.partiallyConfirm}">
            <div class="slds-m-bottom_x-large">
                <span><lightning:icon iconName="utility:warning" size="small"/></span><span class="slds-m-left_xx-small">This Js Button has been partially migrated. Contact with your System Administrator to review the functionality.</span>
            </div>
        </aura:renderIf>
        <p>'The current PY / CY State Directors will be overwritten with users based on the current mappings. Is this OK?'</p>
    </div>
    <div class="slds-modal__footer">
        <lightning:button class="slds-button_neutral" onclick="{!c.yesResponse}" label="Yes" />
        <lightning:button class="slds-button_brand" onclick="{!c.noResponse}" label="No"/>
    </div>
</aura:component>

controller:

({

    yesResponse : function(component, event, helper) {

  sforce.apex.execute('OpportunityStateDirectorWS', 'setStateDirectors', {
  oppIds: [''+helper.idTruncate(component.get('v.sObjectInfo.Id'))+'']});
  window.location.reload();


        $A.get("e.force:closeQuickAction").fire();
    },

    noResponse : function(component, event, helper) {



        $A.get("e.force:closeQuickAction").fire();
    }
})

apex class:

global without sharing class OpportunityStateDirectorWS {

    webservice static void setStateDirectors(List<Id> oppIds) {
        List<Opportunity> opps = [
            SELECT
                Id,
                AccountId,
                Current_Event_Session__c,
                Current_Year_Session_Code__c,
                Previous_Event_Session__c,
                Previous_Year_Session_Code__c
            FROM Opportunity
            WHERE Id IN :oppIds ];

        OpportunityTriggerHelper.updateStateDirector(opps);
        update opps;
    }

}
2
  1. Add controller to your component
<aura:component extends="c:LCC_GenericLightningComponent" controller="OpportunityStateDirectorWS">
  1. Change your controller method
yesResponse : function(component, event, helper) {
    let action = component.get('c.setStateDirectors');
    action.setParams({oppIds: [''+helper.idTruncate(component.get('v.sObjectInfo.Id'))+'']});
    action.setCallback(this, function(response) {
        let state = response.getState();
        if (state === 'SUCCESS') {
            $A.get('e.force:refreshView').fire();
            $A.get("e.force:closeQuickAction").fire();
        } else if (state === 'ERROR') {
            //handle error
        }
    });
    $A.enqueueAction(action);
}
  1. Add @AuraEnabled descriptor to setStateDirectors method in OpportunityStateDirectorWS class.
global without sharing class OpportunityStateDirectorWS {
    @AuraEnabled
    webservice static void setStateDirectors(List<Id> oppIds) {
       // method code
    }
}
| improve this answer | |
  • Hi I'm again getting an error "Uncaught Unable to find action 'setStateDirectors' on the controller of c:LCC_Update_State_Director_Opportunity". – Maneesh J Aug 7 '19 at 8:42
  • Have you added 'controller="OpportunityStateDirectorWS"' to <aura:component> tag? Could you check if apex class 'OpportunityStateDirectorWS' exists? – BlackCat Aug 7 '19 at 8:55
  • Yes there is a class called OpportunityStateDirectorWS – Maneesh J Aug 7 '19 at 9:26
  • I think I know what the problem is. Please add @AuraEnabled descriptor to setStateDirectors method in OpportunityStateDirectorWS class. Also, I have updated description. – BlackCat Aug 7 '19 at 9:43
  • Thank you so much BlackaCat. It's working. – Maneesh J Aug 7 '19 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.