I'm with and strange issue then moving data from a custom objecto to other.
Custom Object A has a custom field of type "String" and length 2 called State.
Custom Object B has a custom field of type "picklist" called State. It's posible values are US states like: AL, SF, AZ, etc
My code is something like next sample:
ObjectB__c objectB = [SELECT bla bla FROM ObjectB__c where bla bla];
...
ObjectA objectA = new ObjectA();
objectA.State__c = objectB.State__c;
...
objectAList.add(objectA);
...
System.debug(objectA);
insert objectAList; //On my code this line is literaly next to System.debug
System.debug throws next:
(objectb1__c:{bla1=bla1, State__c=ES, bla2:bla2}, objectb2__c:{bla1=bla1, State__c=AZ, bla2:bla2})
insert line throws the next error
EXCEPTION_THROWN [42]|System.DmlException: Insert failed. First exception on row 0; first error: STRING_TOO_LONG, State: data value too large: AL;AK;AZ;AR;CA;CO;CT;DE;FL;GA;HI;ID;IL;IN;IA;KS;KY;LA;ME;MD;MA;MI;MN;MS;MO;MT;NE;NV;NH;NJ;NM;NY;NC;ND;OH;OK;OR;PA;RI;SC;SD;TN;TX;UT;VT;VA;WA;WV;WI;WY (max length=2): [State__c]
I'm not sure the reason why salesforce is trying to insert all the available values from the picklist into my String field knowing that whefield to be inserted has only the 2 state chars .
Any Ideas?
Interesting. Would you mind sharing what the rest of the code is after setting the state on ObjectA?