i have one custom field called Unique_Vendor_Id__c on account object (external id checkbox checked) and its auto-number.

now in test class when i create account for test data Unique_Vendor_Id__c should be automatically created as soon as account created, and in controller i am fetching data from that Unique_Vendor_Id__c if available.

now when i run test class it gives me following error :

System.StringException: Invalid id: null

and in stack trace :

External entry point Class.VendorAndChargeCreationControllerTest.VendorAndChargeCreationControllerTestMethod1: line 45, column 1

so from this error i think autonumber field is not generating id at a time of account creation am i right?

please let me know do i have to change any thing in field for generating that autonumber field in test data?

thank you in advance.


As you haven't supplied any code this is only a guess based on a typical problem...

When something happens in the database changed field values (with the exception of object Id fields when records are created) are not automatically brought back into the Apex code. So you have to requery the data to see the new values.

  • yes that was the problem, i mean it wasn't returning full object with auto number and other fields thats why it was coming null, now i query that record and boom got the data. thank you very much. – patelkiran3090 May 2 '18 at 8:12
  • @Keith C , i am also getting the same, but in my case i have custom fields, with unique checked. in the debug logs i have checked it's not null.when it comes page it saying: Invalid id: 00013 Error is in expression '{!method1}' in component <apex:commandButton> in page SomeClassName: External entry point, <--- custom_object__c (text,unique checked). – Umesh Beti Jun 18 at 6:44
  • okay i found, the mapping key issue i was checking with another custom_field1__c as a key, actually it was custom_field2__c as key of the map – Umesh Beti Jun 18 at 10:41

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.