+ Start a Discussion
chandarchandar 

Can we call apex class using workflow rules

I had a requirement need to call apex class from workflow rules. If there is any possibilities please suggest
SIVASASNKARSIVASASNKAR
Hi Chandar,

Yes you can call the Apex class from Wrokflow using Outbound message.  please follow the steps.

Step 1 : Create the Site in Setup --> App Setup --> Develop --> Sites
Step 2 : Create the REST based class using @RestResource(urlMapping='/<<Name>>/*')
Step 3 : Provide the class access for the Site created above and provide the objects and class permission for the profile.
Step 4 : Copy the URL of the Site including urlmapping of the class.
Step 5 : Create Outbound message past the URL
Step 6 : Activate the Workflow
// URL for Outbound message
// => http://DomainName/SiteName/services/apexrest/<urlMappingName>/notification

@RestResource(urlMapping='/<Name>/*')
global with sharing class ClassName{

   @HttpPost
    global static void methodName()
    {
     // do your logic
   }

}

Testing : 
https://workbench.developerforce.com/restExplorer.php

place the URL from
/services/apexrest/<urlMappingName>/notification 
the Execute it.


Thanks
Sivasankar
chandarchandar
hi sivashankar,
 Thanks for your reply,in URL mapping which url need to be given if u had any example please post it.
Ravi Dutt SharmaRavi Dutt Sharma
You can use process builder here instead of using workflow. Process builder provides you an option to call your apex code directly
SIVASASNKARSIVASASNKAR
Hi Chandar,

Site URL : User-added image

URL : Site URL/services/apexrest/<urlMappingName>/notification


Thanks
sivasankar
Nuevo9763Nuevo9763
Hi Ravi Dutt,
can you please post an example/steps to call apex from process builder direcly?
Thanks,
MK7