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
CBNCBN 

Create lightning component that contains button which calls action to create new Campaign member record populating few field values from existing cm record in another campaign.

User-added image
Best Answer chosen by CBN
Saravanan RajarajanSaravanan Rajarajan
Hi,

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

Example 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;
    }

 

All Answers

Meghna Vijay 7Meghna Vijay 7
Hi,
Create a quick actionwhich will be visible on the highlight Panel  using force:lightningQuickAction interface  lightning component . Use force:createRecord event to create a new campaign record and set defaultFieldValues attribute to populate few field values. For Example:-
({ 
doInit : function(component, event, helper) { var createnewRec = $A.get("e.force:createRecord"); 
createnewRec.setParams({ 
"entityApiName": "Campaign", 
"defaultFieldValues": { Name : 'Test Record1',  
                        Description__c :'test description',
                        ParentPicklist_field__c : 'a', 
                        ChildPicklist_Field__c : '1' } }); 
createnewRec.fire(); 
 } 
})

Hope it helps,if it does then mark it as solved.
Thanks
 
Saravanan RajarajanSaravanan Rajarajan
Hi,

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

Example 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;
    }

 
This was selected as the best answer