Test class error for dynamically created custom field using Tooling API in Salesforce package

53 views Asked by At

Hi Stack Overflow community,

I'm new here,and I'm facing an issue with my Salesforce package where I dynamically create a custom field using the Tooling API in the post-installation package. The field is then used in my custom Apex functionality. However, when I try to create a test class, I encounter an "Invalid field" error because the field does not seem to exist in Salesforce during the test context.

I have ensured that the dynamically created field is properly created, and it works as expected in the Salesforce UI. However, the test class doesn't recognize the field, leading to the "Invalid field" error.

Error: System.SObjectException: Invalid field

Here's a simplified overview of what I'm trying to achieve:

  1. Confirming that the field is created successfully using the Tooling API.
  2. Ensuring that the API name and data type of the field match the usage in the Apex code.
  3. Custom Apex functionality references this dynamically created field.
  4. Test class encounters "Invalid field" error during execution.

Any suggestions on how to make the dynamically created field accessible during test execution would be greatly appreciated.

I've already attempted to create the field in test class and have enclosed the functionality within Test.StartTest(); and Test.StopTest(); blocks, and I'm still facing the "Invalid field" error.

0

There are 0 answers