You need to sign in to do that
Don't have an account?
B2000
CMSForce Test Code Errors-The Object API name is not correct
I ran all the Apex Unit Tests and 5 CMSForce classes are failing. They all come from the trigger checkObjectAPIName with the error "The Object API name is not correct." I believe it is not the code itself but some data in the system causing the problem. However, I'm not sure how to research "this happens when the object's API name doesn't exist, or has been removed from the profile access settings, Typically when admin's don't setup the webform editor correctly"
Thanks
trigger checkObjectAPIName on Web_Form__c (before insert, before update) { //Map that holds all the object names and tokens in your org Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); for(Web_Form__c form:Trigger.New) { //just for other tests, provide a bypass to this one if(form.Object_Name__c.contains('testbypassx')) continue; //get a reference to the token related to the object referenced in the webform SObjectType sot = gd.get(form.Object_Name__c); //instantiate an object of this type try { SObject sobjectInstance = sot.newSObject(); } //this happens when the object's API name doesn't exist, or has been removed from the profile access settings //Typically when admin's don't setup the webform editor correctly catch(System.NullPointerException ex) { form.addError('The Object API name is not correct.'); }
didnot return the right value.
Why not just use
SObjectType sot = gd.get('Web_Form__c');
Can you please post here the full error?
Thanks,
Adrian
Here are portions of the log files of the 5 test classes that are failing. CMSForce is a package so I'm not sure if I should change the code.
CMSFoldersController
15:22:39.920 (12920531000)|DML_BEGIN|[386]|Op:Insert|Type:Web_Form__c|Rows:1
15:22:39.924 (12924429000)|CODE_UNIT_STARTED|[EXTERNAL]|01qC000000011iv|checkObjectAPIName on Web_Form trigger event BeforeInsert for [new]
15:22:40.310 (13310533000)|VF_PAGE_MESSAGE|The Object API name is not correct.
16:03:35.800 (2800540000)|EXCEPTION_THROWN|[386]|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.: []
16:03:35.801 (2801418000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.: []
Class.CMSFoldersController.t1: line 386, column 1
16:03:35.801 (2801431000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.: []
FormController
15:56:23.690 (1690595000)|DML_BEGIN|[131]|Op:Insert|Type:Web_Form__c|Rows:1
15:56:23.693 (1693612000)|CODE_UNIT_STARTED|[EXTERNAL]|01qC000000011iv|checkObjectAPIName on Web_Form trigger event BeforeInsert for [new]
15:56:23.853 (1853890000)|VF_PAGE_MESSAGE|The Object API name is not correct.
16:01:13.422 (2422334000)|EXCEPTION_THROWN|[102]|System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, checkObjectAPIName: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.checkObjectAPIName: line 28, column 1
16:01:13.423 (2423566000)|VF_PAGE_MESSAGE|checkObjectAPIName: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.checkObjectAPIName: line 28, column 1
16:01:13.423 (2423660000)|USER_DEBUG|[111]|DEBUG|Exception occured Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, checkObjectAPIName: execution of BeforeInsert
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.checkObjectAPIName: line 28, column 1
FormItemIncludeController
15:58:37.207 (2207379000)|CODE_UNIT_STARTED|[EXTERNAL]|01qC000000011iv|checkObjectAPIName on Web_Form trigger event BeforeInsert for [new]
15:58:37.366 (2366983000)|VF_PAGE_MESSAGE|The Object API name is not correct.
15:58:37.370 (2370844000)|EXCEPTION_THROWN|[171]|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.: []
15:58:37.371 (2371597000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.: []
Class.FormItemIncludeController.t1: line 171, column 1
15:58:37.371 (2371617000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.: []
RenderFormComponentController
16:04:47.874 (1874988000)|DML_BEGIN|[155]|Op:Insert|Type:Web_Form__c|Rows:1
16:04:47.881 (1881129000)|CODE_UNIT_STARTED|[EXTERNAL]|01qC000000011iv|checkObjectAPIName on Web_Form trigger event BeforeInsert for [new]
16:04:48.046 (2046242000)|VF_PAGE_MESSAGE|The Object API name is not correct.
16:04:48.050 (2050539000)|EXCEPTION_THROWN|[155]|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.
16:04:48.051 (2051679000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.
Class.RenderFormComponentController.t1: line 155, column 1
16:04:48.051 (2051694000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.
WebFormEditorController
16:06:30.358 (7358703000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object
Class.WebFormEditorController.selectObject: line 131, column 1
Class.WebFormEditorController.t1: line 479, column 1
16:06:30.428 (7428979000)|DML_BEGIN|[546]|Op:Insert|Type:Web_Form__c|Rows:1
16:06:30.435 (7435030000)|CODE_UNIT_STARTED|[EXTERNAL]|01qC000000011iv|checkObjectAPIName on Web_Form trigger event BeforeInsert for [new]
16:06:30.440 (7440636000)|VF_PAGE_MESSAGE|The Object API name is not correct.
16:06:30.446 (7446956000)|EXCEPTION_THROWN|[546]|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.
16:06:30.448 (7448372000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.
Class.WebFormEditorController.t2: line 546, column 1
16:06:30.448 (7448394000)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Object API name is not correct.
Class.WebFormEditorController.t2: line 546, column 1
Seems the problem is in that try/catch block. There is a comment :
Have you setup the webform editor correctly?(whatever that means) Check the CMSForce documentation for that... My guess you have to setup somewhere the object name(that Object_Name__c field) for the sObject that you want to use the form for.
You could remove the try/catch to see exactly what error it throws.
You could also add some debug statements to see the values of the variables. Like:
Hope this helps,
Adi
That is what I thought too and was my next step. I will try and see what the debug statements produce.