+ Start a Discussion
Ravali RPRavali RP 

How to get selected records from list view in Lightning and add those to other object?

I have custom object called 'Mall'. Once users have selected the Malls, there would be a button on the top right that says "Add to Account".
When the user clicks the button, it will ask them to select an account (they will be able to search accounts). Once they select an Account, there will be a button that says 'Add'. 
When they click add, the Malls that they selected on the list view would be added to the selected account they chose. 





How can I achieve this functionality in Lightening ?User-added image
sunny.sfdcsunny.sfdc
Did you find any solution to this? I have similar requirement but it seems this is not achievable from lightning using the standard list views just like in visualforce.

The only way appears to me is using the visualforce page with lightning css.
Ganesh RajputGanesh Rajput
you can handle all this thing using visualforce page by adding it to button, I have done the same thing in my org for RFQ(Custom Object ) to Quote.
when user clicks on the button on Opportunity related RFQ List it will generate Quote related to the same Opportunity if you are still stuck with a problem then I can send code, reply if you want a code.
Ganesh RajputGanesh Rajput
Visualforcce Page:
<apex:page standardController="RFQ__c" recordSetVar="RFQ"
           lightningStylesheets="true"
           showHeader="false"
           standardStylesheets="false"
           sidebar="false"
           applyHtmlTag="false" applyBodyTag="false"
           docType="html-5.0"
           action="{!genrateRFQQoute}"
           extensions="QuoteCreatorController">
    <apex:form >
        <apex:pageBlock title="Create Quotes" mode="maindetail">
            <center>
                <apex:outputLabel rendered="{!msg}" style="color:Green"><H3>
                    Quote Created..!
                    </H3></apex:outputLabel>
                <apex:outputLabel rendered="{!err}" style="color:red"><H3>
                    Select at least One RFQ
                    </H3></apex:outputLabel>
            </center>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex controller
public class QuoteCreatorController {
    public static Boolean msg{get;set;}
    public static Boolean err{get;set;}
    public static ApexPages.StandardSetController setRFQ;
    public QuoteCreatorController(ApexPages.StandardSetController controller){
        setRFQ = controller;
    }
    public static pageReference genrateRFQQoute(){
        set<id> ids = new set<id>();
        List<Quote> quoteListToInsert = new List<Quote>();
       // System.debug('setRFQ.getSelected() == '+setRFQ.getSelected());
       for(Integer i=0;i<setRFQ.getSelected().size();i++){
            ids.add(setRFQ.getSelected()[i].id); 
        }
         if(ids.size() == 0){
            err = true;
            return null;
        }
        List<RFQ__c> RFQList = [SELECT id,(SELECT id from Quotes__r),Name,Contacted__c, CurrencyIsoCode, Draft_in_Outlook__c, Email_Body__c,
                                RFQ__c, Send_Email__c, Status__c, To_Email_s__c, Parent_Inquiry__c,Operator__c,
                                OutlookAction__c FROM RFQ__c where Id IN :ids];
        
        
        for(RFQ__c rfq:RFQList){
            Quote quote = new Quote();
            if(rfq.Quotes__r.size() > 0){
                quote.Id = rfq.Quotes__r[0].id;
            }
            quote.RFQ_Name__c = rfq.Id;        
            quote.Name = rfq.Name; 
            quote.OpportunityId = rfq.Parent_Inquiry__c;
            quote.Operator__c = rfq.Operator__c;
            quote.OutlookAction__c = rfq.OutlookAction__c;
            quote.CurrencyIsoCode = rfq.CurrencyIsoCode;
            quote.Contacted__c = rfq.Contacted__c;
            quote.Draft_in_Outlook__c =  rfq.Draft_in_Outlook__c;
            quote.Email_Body__c = rfq.Email_Body__c;
            quote.RFQ__c = rfq.RFQ__c;
            quote.Send_Email__c = rfq.Send_Email__c;
            quote.Status__c = rfq.Status__c;
            quote.To_Email_s__c = rfq.To_Email_s__c;  
            quoteListToInsert.add(quote);
        }
        
        try{
            upsert quoteListToInsert;
            msg = true;
        }catch(Exception e){
            System.debug('Excepton == '+ e);
        }
        return null;
    }
    
}

Mark Best it solve your problem 
IT运维(韩敏)IT运维(韩敏)
@Ganesh This method can be implemented in lightning, but not in the portal.
Because the Behavior setting for custom buttons and links isn’t supported. When users click custom buttons in published sites, the Visualforce page is always displayed in the current window.

Does anyone know how to solve this problem?