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
Velmani RVelmani R 

Create lightning component that contains button which calls action to create new Campaign member record populating few field values

Create lightning component that contains button which calls action to create new Campaign member record populating few field values How can achieve this?
Best Answer chosen by Velmani R
Saravanan RajarajanSaravanan Rajarajan
Hi,

create new Campaign member record populating few field values from existing cm record in another campaign. 

Please Try This Code:
 
<aura:component implements="forceCommunity:availableForAllPageTypes,force:lightningQuickActionWithoutHeader,force:hasRecordId" controller="Apex Class Name" access="global" >
     <aura:attribute name="acccountId" type="Id" />
     <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> 
                      
</aura:component>
 
//Create record for Campaign with prepopulated values start
({
doInit: function(component, event, helper) {

                       component.set("v.acccountId", response.getReturnValue().Campaign.Account__c);
                        accountIdVar=component.get("v.acccountId");

                            var createRecordEvent = $A.get("e.force:createRecord");                             
                            
                            createRecordEvent.setParams({
                               "entityApiName": 'Campaign',
                               
                                    'defaultFieldValues': {
                                                    
                                                     'AccountId':accountIdVar,  
                                                    'Name' :'Tester',
                                                   //populating few field values
                                                }
}
})
 
@AuraEnabled
    //get Campaign details
    public static Campaign getordDetails(Id CampaignId){
        Campaign newWO;
        newWO=[Select Id, Name, ParentId, Campaign.Account__c from Campaign where Id=:CampaignId];
        return newWo;
    }

Please mark it best answer if it helps you.