0

I have a custom object called Orders that has a lookup field with another custom object called Product. I am assigning the product ID from product with the ID column in orders. Product's ID field is a text field and Orders' ID field is a lookup field with relationship to Product's ID field.

When assigning the id using the code below

Order__c newORD = new Order__c();
newORD.Item_Code__c = sku.Item_Code__c;

Where sku is of type Product and newORD is of type Order, the error System.StringException invalid ID appears. There are no validation rules on the lookup field.

1
  • 2
    Why don't you just use newORD.Item_Code__c = sku.Id; Jul 11, 2018 at 12:58

1 Answer 1

3

From what you said I think you are trying to assign a product code to a lookup field, but you need to assign its Id instead.

You are trying to assign, for example, 'ABC-1023' to a lookup field, but it is expecting a valid Id, like 'a1p230000000000AAA', which would be sku.Id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.