You need to sign in to do that
Don't have an account?
Jayamaruthyraman Jaganath
StandardController's Save method
I have a custom object called DummyObject and it has just one column called DESCR (text, 50 characters length). When I execute the following anonymous block, the ID field is null. Calling the Insert method works, however. Is it safe to assume that the Save method does not update the ID field unlike the Insert method?
dummyobject__c doobj = new dummyobject__c();
doobj.Descr__c = 'test';
ApexPages.StandardController controller = new ApexPages.StandardController(doobj);
controller.save();
controller = new ApexPages.StandardController(doobj);
system.debug(doobj.id);
dummyobject__c doobj = new dummyobject__c();
doobj.Descr__c = 'test';
ApexPages.StandardController controller = new ApexPages.StandardController(doobj);
controller.save();
controller = new ApexPages.StandardController(doobj);
system.debug(doobj.id);
I see that when you execute this code in anonymous block record is not created in the model that is the reason id is null.
I don't think You can use save method in Anonymous block we generally use save() method in the controller as this is a controller method.
Please refer below link for more information.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardController_methods.htm
Hope this helps you!
If this helps you please mark it as solved.
Thanks and Regards
Sandhya
However, the Insert method behaves completely, irrespective of where it is called from.
Jay