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
Leo DarkstarLeo Darkstar 

Lightning Component Cloning Quick Action not working

Needless to say, this is my first venture into Components.....

 

I'm attempting to use this to create a clone of an Opp. It's set map over two fields. But I can't get it to work. It will only produce a blank square dialog box when the action is used.
Here are the different pieces.


Component :
 

<aura:component controller="CloneOpp" implements="force:lightningQuickActionWithoutHeader,lightning:actionOverride">
    <ltng:require styles="/resource/SLDS202/assets/styles/salesforce-lightning-design-system.css"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="oppName" type="String" />
    <aura:attribute name="typePick" type="String" />
    <aura:attribute name="campaign" type="String" />
  
     <aura:dependency resource="c:createRecord"/>
    <!-- Load the navigation events in the force namespace. -->
    <aura:dependency resource="markup://force:*" type="EVENT"/>
    
    
</aura:component>
 

Controller : 

({
     doInit: function(component, event, helper) {
      //call the helper function with pass [component, Controller field and Dependent Field] Api name 
     // alert('Hi');
      helper.queryOpp(component, event, helper);
   },
   
})
 

Helper : 

({
    queryOpp: function(component,  event, helper) {
      var recordId = component.get("v.recordId");
        if(recordId!=undefined){
        
        
        alert(recordId);
        var action = component.get("c.getDetailsFromOpp");
        action.setParams({
            recordId: recordId
        });
        action.setCallback(this, function(response){
            var state = response.getState();
           
            if (state === "SUCCESS") {
                var opp = response.getReturnValue();
                component.set("v.oppName", opp.Name); 
                component.set("v.typePick", opp.pcikListTest__c);
                component.set("v.campaign", opp.CampaignId);
               
                helper.createOppRecord(component, event, helper);
              
            }
           
        });
        
        $A.enqueueAction(action);
        }
    },
     createOppRecord : function (component, event, helper) {
       var name=  component.get("v.Name"); 
       var picklist = component.get("v.typePick"); 
        var campaign=  component.get("v.campaign");
        // alert(picklist);
       //  alert(campaign);
    var createOpportunityEvent = $A.get("e.force:createRecord");
    createOpportunityEvent.setParams({
    "entityApiName": "Opportunity",
    "defaultFieldValues": {
        'Name' : 'New Opp',
        'Type' : 'Existing Customer - Upgrade',
        'pcikListTest__c' : picklist,
        'CampaignId' : campaign
        }
    });
    createOpportunityEvent.fire();
    },
    
})
 

Class :

public class CloneOpp {
 @AuraEnabled 
    public static Opportunity getDetailsFromOpp(string recordId){
       Opportunity opp = [select Id,Name,CampaignId,TrackingNumber__c,pcikListTest__c
        from Opportunity Where Id = :recordId limit 1];
       return opp ;
    }

}
 

Does anything stand out as out of place ? Any help you can give would be appreciated.


Thank you.

Best Answer chosen by Leo Darkstar
David Zhu 🔥David Zhu 🔥
My understanding is the quick action is on Opportunity record page. It clones the opportunity. In that case, you need to add force:hasRecorId interface.
<aura:component controller="CloneOpp" implements="force:lightningQuickActionWithoutHeader,lightning:actionOverride,force:hasRecordId">

Otherwise,  recordId will always be undefined.

var recordId = component.get("v.recordId");   //recordId is always undefined without force:hasRecordId interface
 if(recordId!=undefined){
    ........
}

All Answers

David Zhu 🔥David Zhu 🔥
You are trying to call another helper method from a helper method. You may have to add one line to the calling method.

   queryOpp: function(component,  event, helper) {
      var self = this;
      var recordId = component.get("v.recordId");

       ........
     self.createOppRecord(component, event, helper);
Leo DarkstarLeo Darkstar
@David Zhu - thank you so much for your input. I made the changes to the Helper you indicated by adding 'var self = this' line and adding 'self' to line 46 (although it doesn't show here because I am unable to edit my post). But I'm still getting the same result. Any other ideas...?
David Zhu 🔥David Zhu 🔥
My understanding is the quick action is on Opportunity record page. It clones the opportunity. In that case, you need to add force:hasRecorId interface.
<aura:component controller="CloneOpp" implements="force:lightningQuickActionWithoutHeader,lightning:actionOverride,force:hasRecordId">

Otherwise,  recordId will always be undefined.

var recordId = component.get("v.recordId");   //recordId is always undefined without force:hasRecordId interface
 if(recordId!=undefined){
    ........
}
This was selected as the best answer
Leo DarkstarLeo Darkstar

That produced a new error : 

 

User-added image

Any ideas....? 

Leo DarkstarLeo Darkstar

Also - I just noticed that I added your 'self' to the wrong line - and when I attempted to put it in line 31 of the Helper instead I was unable to save the code. I was given this error : 

 

User-added image

Leo DarkstarLeo Darkstar

And I'm also getting this error when attempting to use the Quick Action as well (I didn't notice it at first because it was blocked by the other one) : 

 

User-added image

Leo DarkstarLeo Darkstar
ok - it's working now. Very weird. BUT I'm still getting that 2nd error pop up which says 'Name' of component....Once I close that the rest of it works as it should. Any idea on that 2nd error ? 
Leo DarkstarLeo Darkstar

here's the full error : 

 

Access Check Failed! AttributeSet.get(): attribute 'Name' of component 'markup://c:CloneOpp_beta {32:6771;a}' is not visible to 'markup://c:CloneOpp_beta {32:6771;a}'.
David Zhu 🔥David Zhu 🔥
line 31 should be change to 
var name=  component.get("v.oppName");
Leo DarkstarLeo Darkstar
oh ! That did it ! Thank you so much David !