Wednesday 15 May 2013


Insert

The Insert statement adds up to 200 records of a single object type to the database.
When all records succeed, they contain their new unique identifiers. If any record fails, a
DmlException is raised and the database is returned to its state prior to the Insert statement.
For example, the code in Listing 5-33 inserts a Contact record and uses it as the
parent of a new Resource record.

Listing 5-33 Inserting a Record

try {
Contact c = new Contact(FirstName = 'Justin', LastName = 'Case');
insert c;
Resource__c r = new Resource__c(
Contact__c = c.Id, Hourly_Cost_Rate__c = 75, Region__c = 'West');
insert r;
} catch (DmlException e) {
System.debug(LoggingLevel.ERROR, e.getMessage());
}

No comments:

Post a Comment