Is there any way to check the apex class ApiVersion Before deploying it?
For example, let's say a developer is trying to save an apex class with API Version 25, We need to show an error message 'The API version must be above 40'
As per knowledge, its not possible to show API version error message while saving the apex class.
When classes and methods are added to the Apex language, those classes and methods are available to all API versions your Apex code is saved with, regardless of the API version (Salesforce release) they were introduced in. For example, if a method was added in API version 33.0, you can use this method in a custom class saved with API version 33.0 or another class saved with API version 25.0.
Refer the help article.
sfdx
. You would need to incorporate some custom scripting before the deployment, like XML parsing of the.cls-meta.xml
files from the repository. But this would require educating users to do the deployment only via this script and never manually or blocking manual deployments entirely and performing such only via CI.