function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KRITI LAHA 8KRITI LAHA 8 

Batch job on SecurityHealthCheck

Hi all,

Can anyone help me to write a batch class on SecurityHealthCheck which will calculate the score and risk cateory and an email needs to be sent with the result?

Query: 
1. SELECT SettingRiskCategory, RiskType, Setting, SettingGroup, OrgValue, StandardValue FROM SecurityHealthCheckRisks where RiskType != 'MEETS_STANDARD'
2. select score from SecurityHealthCheck

I have tried but getting below error: Invalid type: SecurityHealthCheck

Thanks
SwethaSwetha (Salesforce Developers) 
HI Kriti,
SecurityHealthCheckRisks and SecurityHealthCheckRisks are the objects that are only exposed via Tooling API.

The post https://salesforce.stackexchange.com/questions/359214/which-tooling-api-objects-can-be-queried-in-apex also says these objects are not available in the Schema namespace and cannot be queried.

In order to run a batch class on an object, the object must be accessible via one of the standard APIs. If the object is not exposed via the Salesforce REST API, SOAP API, or Bulk API, then you won't be able to use a batch class on it.

Related: 
https://salesforce.stackexchange.com/questions/224146/tooling-api-in-batch-apex

https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_securityhealthcheck.htm

https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_securityhealthcheckrisks.htm

If this information helps, please mark the answer as best. Thank you