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
mamanmaman 

MyProfilePageController Apex test failure

We are getting an error when running a test on the MyProfilePageController Apex class, as follows: 

System.DmlException: Insert failed.
First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, A first name is required.[Full_Name__c]
Stack Trace Class.MyProfilePageController.testSave: line 93, column 1


Since Apex tests are run when deploying change sets, we cannot deploy a set until this error is resolved. Problem is, we didn't write the code, and we're not developers. Looks like it's Salesforce.com code. Unfortunately, we don't have Premium support, and Salesforce will not assist and have directed us to this forum.

Help!
 
Best Answer chosen by maman
James LoghryJames Loghry
Maman,

From the looks of it you introduced a validation rule that broke the unit test provided by Salesforce.  Therefore, you'll need to address it by modifying the testSave method in your MyProfilePageController.  Looking at what I have in my org (also auto generated by Salesforce), I would try updating lines 91 - 93 from
Contact c = new Contact();
c.LastName = 'TestContact';
insert c;

To:

Contact c = new Contact();
c.LastName = 'TestContact';
c.Full_Name__c = 'Test Contact';
insert c;
 

If Full_Name__c is a text field, this should work.  If it's a formula field, then you would need to set the fields that are used by that formula instead.

Hope that helps.
:

 

All Answers

James LoghryJames Loghry
Well the error is telling you exactly where the issue is coming from.  Line 93 in your MyProfilePageController class.  It also tells you the exact error, that you need to specify the Full_Name__c field.  It sounds like your test method is inserting a record, and that you need to specify the Full_Name__c field on that record, and that should fix this particular issue.

Also, you are in for a world of hurt if you don't have any developers on your team and are running into Apex issues.  If you haven't already, your team should check out Trailhead for a primer on Apex and development: https://developer.salesforce.com/en/trailhead/.  Additionally, I suggest you look into bringing someone onto your team, either a FT employee, contractor, or consultant that understands Apex and Salesforce development. 
mamanmaman
I guess the question is, even if we had a developer team, why would we have to fix this code if it's been developed by Salesforce.com? Isn't this Salesforce.com code?

Comments from the code:
/**  * An apex class that keeps updates of a portal user in sync with its corresponding contact. Guest users are never able to access this page.  */

Dependent components are a ChangePassword Visualforce page and controller called ChangePasswordController.

Let me reiterate that we didn't write this code or its dependant components, so it's not our test method. How can we determine the author of this code?

If it is Salesforce.com code, don't other orgs have this problem? Or, did we inadvertantly break this code in our org with the installation of a third-party app?
 
James LoghryJames Loghry
Maman,

From the looks of it you introduced a validation rule that broke the unit test provided by Salesforce.  Therefore, you'll need to address it by modifying the testSave method in your MyProfilePageController.  Looking at what I have in my org (also auto generated by Salesforce), I would try updating lines 91 - 93 from
Contact c = new Contact();
c.LastName = 'TestContact';
insert c;

To:

Contact c = new Contact();
c.LastName = 'TestContact';
c.Full_Name__c = 'Test Contact';
insert c;
 

If Full_Name__c is a text field, this should work.  If it's a formula field, then you would need to set the fields that are used by that formula instead.

Hope that helps.
:

 

This was selected as the best answer
mamanmaman
Thanks James. It was helpful to know this code was provided by Salesforce which confirmed that we somehow had broken it. Awhile back we had introduced a validation rule to make the first name required on a Contact record.

Since we wanted to keep the first name required, we hacked around and figured out how to modify the class in the sandbox and uploaded a new version to the live org. Solution was:

91 Contact c = new Contact();
92 c.LastName = 'Contact';
92 c.FirstName = 'Test';
93 insert c;

Frustrating that we could innocently break Salesforce code in this way using out-of-the-box tools, then be unable to get Basic support.
Brian Hopkins 25Brian Hopkins 25
We're encountering this issue too now.  This is F**king unbelievable.  Salesforce is getting worse and worse all the time