0

Here I am unable to call apex method from Action function. I tried many ways but didn't work.

Vf Page :

<apex:page standardController="Contact" recordSetVar="accs" extensions="VFC_ProcessAccRecords"  > <!-- action="{!redirectToLC}"-->
<apex:includeScript value="/soap/ajax/18.0/connection.js"/>
<apex:includeLightning />
<script type="text/javascript"> 

var lstrecords = "{!accIds}";
var proceedfurther = "{!proceed}";
var lstselectedids = [];
if(lstrecords != null && lstrecords != '' && lstrecords != '[]')
    lstselectedids = lstrecords.split(',');

if (lstselectedids.length > 0){ 
    executeMainMethod();
}


</script>

The selected record IDs --- {!accIds}
<apex:form id="myform">
    <apex:actionFunction  immediate="true" name="executeMainMethod"  action="{!redirectToLC}" reRender="outpanel"/>
    <apex:pageBlock >
        <apex:pageBlockSection>
            <apex:outputpanel id="outpanel">
                
            </apex:outputpanel>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

Apex controller:

public class VFC_ProcessAccRecords {
public List<Contact> selAccLst;
public String accIds {get; set;}

  // Constructor
  public VFC_ProcessAccRecords(ApexPages.StandardSetController cntlr){
       selAccLst = cntlr.getSelected(); //get selected records from account list view
       accIds = '';  
       for(Contact acc : selAccLst){
           accIds += acc.Id + ','; //build list of ids string concatenated with comma                         
        }
       accIds = accIds.removeEnd(',');
  } 

  public PageReference redirectToLC(){
      system.debug('Inside redirectToLC from JSS');
        String returnUrl = '/lightning/cmp/c__ProcessListView?c__listofAccounts='+accIds;
        PageReference pgReturnPage = new PageReference(returnUrl);
        pgReturnPage.setRedirect(true);
        return pgReturnPage;
  } 

 public void updateAllCons(){
      system.debug('Inside redirectToLC from JSS');
 } 

}

Can anyone suggest/help what was the issue here.. I have tried these examples -- https://developer.salesforce.com/forums/?id=906F000000094lAIAQ

https://developer.salesforce.com/forums/?id=906F000000095KNIAY

Thank you

2
  • Do you need to call it as JavaScript, or are you okay with the standard action redirect?
    – sfdcfox
    Jan 17, 2023 at 19:36
  • @sfdcfox - I do want to call it as Javascript.
    – anji reddy
    Jan 17, 2023 at 19:45

0

You must log in to answer this question.

Browse other questions tagged .