Id is present result object which is returned after insertion of a record.
Database Method Syntax • SaveResult insert(sObject recordToInsert, Boolean opt_allOrNone) • SaveResult[] insert(sObject[] recordsToInsert, Boolean opt_allOrNone) The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that can be used to verify which records succeeded, which failed, and why. For example: Database.SaveResult[] MySaveResult = Database.Insert(MyAccounts, false);
SaveResult Object An array of SaveResult objects is returned with the insert and update database methods. Each element in the SaveResult array corresponds to the sObject array passed as the sObject[] parameter in the database method, that is, the first element in the SaveResult array matches the first element passed in the sObject array, the second element corresponds with the second element, and so on. If only one sObject is passed in, the SaveResults array contains a single element .
Another example:-
Account inst = new Account(RecordTypeId = RecInst,Familiar_Name__c='@isTest1',Name='@isTest1'); insert inst;
inst.id will give you the id of the inserted object.
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Id is present result object which is returned after insertion of a record.
Database Method Syntax
• SaveResult insert(sObject recordToInsert, Boolean opt_allOrNone)
• SaveResult[] insert(sObject[] recordsToInsert, Boolean opt_allOrNone)
The optional opt_allOrNone parameter specifies whether the operation allows partial success. If you specify false for this
parameter and a record fails, the remainder of the DML operation can still succeed. This method returns a result object that
can be used to verify which records succeeded, which failed, and why.
For example:
Database.SaveResult[] MySaveResult = Database.Insert(MyAccounts, false);
SaveResult Object
An array of SaveResult objects is returned with the insert and update database methods. Each element in the SaveResult array corresponds to the sObject array passed as the sObject[] parameter in the database method, that is, the first element in the SaveResult array matches the first element passed in the sObject array, the second element corresponds with the second element, and so on. If only one sObject is passed in, the SaveResults array contains a single element .
Another example:-
Account inst = new Account(RecordTypeId = RecInst,Familiar_Name__c='@isTest1',Name='@isTest1');
insert inst;
inst.id will give you the id of the inserted object.
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.