I have a custom object Vehicle__c with a lookup field Car__c which is also a custom object. Type of field Car__c is String. Car__c has just two fields - 'Car Name' with value 'FourWheeler' and 'ExteralId' also with value 'FourWheeler' I am instantiating Vehicle and then I am trying to assign value to the field which is causing an exception -
Vehicle__c vehicleObj = new Vehicle__c(); vehicleObj.Car__c = "FourWheeler";
The exception I am getting is -
exp:'common.apex.runtime.impl.ExecutionException: Invalid id: FourWheeler'
For a non lookup field this type of assignment works without any issues. What is wrong with the way I am assigning the value to the lookup ? What is the correct way ?