You need to sign in to do that
Don't have an account?
eswarsf
Autonumber field in test class giving null
Hi,
I have a class in which I am updating a field for a custom object.For this class i have written a test class.In this test class i was creating new record for my custom object.
The problem is for this custom object,Name field is an Autonumber field.
So in my test class after inserting i was trying to send this Name to my Apex class.But surprisingly it is giving me NULL after insert in Test class.
Kindly let me know if this is a Salesforce defect.
Thanks,
Eswar.
Hi eswarsf,
As far as I'm aware the only field on a sobject to be populated automatically after an insert is the ID, I believe to get the auto-number value for the name field you'll need to query the object:
Matt
All Answers
Hi eswarsf,
As far as I'm aware the only field on a sobject to be populated automatically after an insert is the ID, I believe to get the auto-number value for the name field you'll need to query the object:
Matt
Hi,
Try something like this..
List<CustomObject__c> newBranches = new List<CustomObject__c>{
new Branch__c(autonumbername='Enterprise', code__c='ES'),
new Branch__c(autonumbername='Banking', code__c='BCM') };
insert newBranches;
Hope this helps!
Hi Matt,
Thanks .It works for me.
Good to hear, glad to be of help!
The marked answer is incorrect. The transaction is not committed. Hence the fetching fails.