Need assistance with how can I read apex class lines? which API should I use for accomplishing this REST or SOAP? Please help.

  • You can use SOAP, REST, Tooling, Metadata SOAP, Metadata REST, SFDX CLI, etc. It really depends on what technology options you have available to you.
    – sfdcfox
    Mar 11 at 11:02
  • @sfdcfox I checked with salesforce rest API I did not get any endpoint that I can use to read apex class code. so basically what I need to know is how to read apex class code from an outside system if I choose rest API? Mar 11 at 11:05
  • /services/data/sobjects/ApexClass/01p5000000xxxxxAAA or /services/data/sobjects/ApexClass/Name/MyClassName. It gives you a response including the Body of the code.
    – sfdcfox
    Mar 11 at 11:13
  • @sfdcfox In my case, I will not have the class name of any Id to pass and get info. I will have only credentials of salesforce org. The purpose of implementation is to check vulnerabilities in code. Mar 11 at 11:15
  • You can use a query: /services/data/v50.0/query?q=SELECT+Name,Body+From+ApexClass, listMetadata from the Metadata API, etc.
    – sfdcfox
    Mar 11 at 11:19

Hitting endpoint -> /services/data/v50.0/query?q=SELECT+Name,Body+From+ApexClass

will give the list of classes and we can check the content of the apex class using its body attribute.

As @sfdcfox specified in the above conversation body of classes from managed packaged will be hidden.

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.