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
EPSWDEVEPSWDEV 

Database.update(custom_obj) fails

I have a controller extension for a custom object edit page, and what I am trying to do is update a different custom object as part of the save functionality.

Code:
CustomObj co = [Select Id,field1,field2,field3 from CustomObj where Id =:<id string>];
co.field1 = 'someval';
co.field2 = 'someval2';
Database.update(co);


 
However I get the following error when I execute the code:
Update failed. First exception on row 0 with id a0B80000002JH1yEEF; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, <field1_label> already exists. Please choose another: [<field1_name>]

strings in <> are substituted to origianl values. and there is no validation whatsoever on this custom obj and its fields.  Can please somebody explain whats wrong here ?

Thanks

werewolfwerewolf
Did you perhaps mark the Name field or some other field on the object as unique?  That would cause a validation exception.
EPSWDEVEPSWDEV
you are right Field3 is marked as unique. Field3 part is customobj's 'Standard Fields' essentially the name field.

BUT, still I am not changing the value of field3 in my code if you notice, so why does it give me an error. I am simply trying to modify the field2 and field1 for a existing customobj record.

Thanks,


Message Edited by EPSWDEV on 01-08-2009 10:53 AM
werewolfwerewolf
It's because you have field3 in your object implicitly as part of the select.  Take it out of the query.
EPSWDEVEPSWDEV
I actually had tried it before I posted thread. Anyways To get around it temporarily I disabled the rule on the field. One of the team members had created a rule for this field (remember its standard field so you cant specify it  as a unique field explictly) when he had created the object.

the rule was vlookup(field3,field3,name) and it seems like this constraint was being fired on update and insert.

Thanks