You need to sign in to do that
Don't have an account?
Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION
Trying to modify a test trigger for the Chat Up app as advised in the documentation, but my test fails.
/* Create 1 test recurring donation */ npe03__Recurring_Donation__c a = new npe03__Recurring_Donation__c(name = 'testRecurringDonation',npe03__Contact__c = '003J0000006W3j4',npe03__Organization__c ='001J0000007ZAD7'); insert a;
I get this error:
Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You must select an Organization or Contact: []
The code provided in the documentation only included adding the name field, so after the first time I got this error, I added the fields for Contact and Organization, but I still get the same error.
Additional info: in the form, Contact and Organization (aka Account) are lookup fields, and you would normally enter a Contact or an Organization, but not both- I'm using the Nonprofit Starter Pack, so there is a person Account associated with each Contact. The IDs used in the code reflect the ID of the Contact and the Contact's associated Account (aka Organization)
The sample code for the test trigger is provided in this documentation:
What am I missing?
Thanks, Amanda
Hi,
Looking at this "Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You must select an Organization or Contact: []" error, there might be a validation rule on that object, which is causing record insert problem.
Thanks,
Devendra
All Answers
Hi,
I think you need to append Namespace prefix for Name field as well,
npe03__name = 'testRecurringDonation'
Thanks,
Devendra
But I gave it a try anyway, and got this error:
Error: Compile Error: Invalid field npe03__name for SObject npe03__Recurring_Donation__c at line 9 column 90
Must be something else...
Hi,
Looking at this "Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You must select an Organization or Contact: []" error, there might be a validation rule on that object, which is causing record insert problem.
Thanks,
Devendra
Thanks, Devendra, it’s a move in the right direction!
There were no validation rules on the custom object; however, I looked at the page layout for the object and found 7 fields that were required on the layout.
So after adding values for those 7 fields, the code changed to:
and when I ran the test, I got a different error:
ChatterOpptyOnRecurringDonation: execution of AfterInsert
caused by: System.SObjectException: Invalid field npe03__Recurring_Donation__c.id for Opportunity
Class.ChatterUpHelper.chatterUp: line 63, column 1
Trigger.ChatterOpptyOnRecurringDonation: line 36, column 1: []
For this forum, would the etiquette be to drop this post here, and start a new one for the different error, or continue? (I can modify code, but I'm not an Apex programmer per say. Still hammering at trying to figure out myself)
In case of continuing, here's the code, I'm honestly not sure if the problem is the first or second reference to a.id or npe03__Recurring_Donation__c.id:
The error you're getting most likely boils down to the chatter config that you're setting up. I've highlighted the line in bold:
Chatter_Up__c setting = new Chatter_Up__c();
setting.name = 'Opportunity Settings';
setting.object_api_name__c = 'Opportunity';
setting.parent_id_field__c = 'npe03__Recurring_Donation__c.id';
setting.chatter_post_body__c = 'This is a test';
setting.chatter_link_title__c = 'This is test title';
return setting;
This is most likely causing some of you're code to look at an incorrect field on the Opportunity object. This most likely needs to be changed simply to:
setting.parent_id_field__c = 'npe03__Recurring_Donation__c';
I'd also be careful about hardcoding Id's in your test methods, it's not really good practice and all depedencies and test data should be managed in the test class itself.
That was it. The test passed successfully.
I'm not at all surprised that hard-coding the id fields is not ideal, it was just the fastest work-around. Would you suggest creating a Contact and an Account in my test code (in a similar way the Recurring Donation was created), and then using those values to plug into the Recurring Donation required fields? I think there's enough sample code here for me to figure it out, although there's bound to be a hurdle or two.
Thanks, A
Yes what you described is the right way of handling it. Inserting you're own Contact / Account and plugging the Id's is what should be done assuming you have the time to do it.