I want to get my visualforce page apex code through rest API. I tried metadata API like /services/data/v41.0/sobjects/{sobjectName}/describe/layouts and I am able to access fields information but I want to access apex code of the page where define all fields and triggers.
Any guidance would be appreciated. Thanks
You can get the body of Apex classes (that aren't part of managed packages) from a query on the ApexClass
standard object:
curl \
-H 'X-PrettyPrint: 1' \
-H 'Authorization: Bearer <session-id>' \
https://ap4.salesforce.com/services/data/v43.0/tooling/query?q=SELECT+Body+FROM+ApexClass+LIMIT+1
Visualforce pages can be retrieved similarly through a query on the ApexPage
standard object to retrieve the Markup
:
curl \
-H 'X-PrettyPrint: 1' \
-H 'Authorization: Bearer <session-id>' \
https://ap4.salesforce.com/services/data/v43.0/tooling/query?q=SELECT+Markup+FROM+ApexPage+LIMIT+1
For more information on available standard fields and objects to query, check out the Object Reference