0

I am trying to use the invocable method on Public MergeCaseController(ApexPages.StandardsetController controller) so that i can call this from a flow.. But i am having issues doing so,


    public without sharing class MergeCaseController {
    
      
      private static final integer LIMIT_CASES = 25;
        
          public class wrapperCase {
            public Case caso {get;set;}
            public boolean atribuir {get;set;}
            private list< EmailMessage > email{get;set;}
            Public list< Attachment > anexo{get;set;}
                    
          }
        
    
        public list<wrapperCase> lstCase {get;set;}
        //private list<Case> lstSearchCase;
        private map<id,Case> lMapCase;
        public String localizarid {get;set;}
        public String caseId {get;set;}
        public String msg {get;set;}
        @TestVisible private Case casoController;
        private ApexPages.StandardsetController lController;
      
       
        @InvocableMethod(label='Merge')
        Public MergeCaseController(ApexPages.StandardsetController controller)
          
      {
           
        lController = controller;
        casoController = (Case) controller.getRecord();
        String lIdPage = ApexPages.currentPage().getParameters().get('Refid');
          
          
    
        if(lIdPage != null)
        {   
     
           list<Case> lstIdpage = [SELECT CaseNumber FROM Case WHERE id =:lIdPage];
           if ( !lstIdpage.isEmpty())
           {
           caseId = lstIdpage.get(0).CaseNumber;
           localizarid = caseId;
           }
        }
        InternalLocalizarCase( true, controller.getSelected() );
      }
       private void carregar( boolean aFlag )
        {   
    map <id, list< EmailMessage > > mapEmail = new map <id, list< EmailMessage> >();
      
    for(EmailMessage email: [SELECT id,Subject, BccAddress, MessageDate, ParentId, TextBody, Status, 
       CcAddress,  ToAddress ,FromAddress, Incoming
       FROM EmailMessage WHERE ParentId =: lMapCase.keyset()]){
       
      list< EmailMessage > lListEmail = mapEmail.get( email.ParentId );
      if ( lListEmail == null )
      {
          lListEmail = new list< EmailMessage >();
          mapEmail.put( email.ParentId, lListEmail );
      }
      lListEmail.add(email);
    }  
    
    lstCase = new list<wrapperCase>(); 
    
    for(id lcasoId: mapEmail.keySet())
    {
     
     wrapperCase lwp = new  wrapperCase();
     lwp.caso = lMapCase.get(lcasoId);  
     lwp.atribuir = aFlag;
     lwp.email = mapEmail.get(lcasoId);
     lstCase.add(lwp);
        
    }
    
    if ( lstCase.isEmpty() )
    {
        adicionaErro('Selected cases do not meet the criteria for merge.');
    }
    
  }
2
  • I am trying to use the invocable method on Public MergeCaseController(ApexPages.StandardsetController controller) so that i can call this from a flow.. But i am having issues doing so, any help will be much appreciated thank you Jul 17, 2020 at 18:20
  • 1
    The annotation @InvocableMethod is used on methods, not constructors. You can pass the required ID as a parameter to the Invocable method and use it to implement further logic in the method. developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… Jul 17, 2020 at 19:12

1 Answer 1

0

You may want to look at some of the code of these invocable actions. They show common patterns: https://unofficialsf.com/flow-actions/ (generally there's a link to source code at the bottom of each piece of documentation)

basically, set up a new apex class called something like MergeCase. Give it a method like 'execute' and put the invocable method on that. Then inside that execute method, call your merge code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.