How to invoke Salesforce Apex REST using MuleSoft?

Flow:



Listener Configuration:





Transform Message Configuration:



Invoke Apex Rest Method Configuration:




Apex Class:


  1. @RestResource(urlMapping='/MuleSoft/*')  
  2. global with sharing class MuleSoftHandler {  
  3.     
  4.     @HttpPost  
  5.     global static String callEmail( String msgbody, String subject ) {  
  6.       
  7.         system.debug( 'Inside the callEmail' );  
  8.       
  9.         try {  
  10.   
  11.             Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();       
  12.             mail.setTargetObjectId( UserInfo.getUserId() );         
  13.             mail.setSaveAsActivity( false );  
  14.             mail.setSubject( 'Important: ' + subject );            
  15.             mail.setHtmlBody( 'From MuleSoft<br/>' + msgbody );          
  16.             Messaging.sendEmail( new Messaging.SingleEmailMessage[] { mail } );           
  17.             return 'Email Sent successfully';  
  18.               
  19.         } catch( Exception e ) {  
  20.           
  21.             return e.getMessage();  
  22.               
  23.         }  
  24.           
  25.     }  
  26.       
  27. }  

Output:



No comments:

Post a Comment