Apex - DML
INSERT操作
APEX_Customer__c objCust = new APEX_Customer__C();
objCust.Name = 'Test ABC';
insert objCust;
更新操作
List<apex_invoice__c> invoiceList = [SELECT id, Name, APEX_Status__c, createdDate FROM APEX_Invoice__c];
List<apex_invoice__c> updatedInvoiceList = new List<apex_invoice__c>();
invoiceList[0].APEX_Status__c = 'Pending';
updatedInvoiceList.add(invoiceList[0]);
update updatedInvoiceList;
检索操作
List<apex_invoice__c> invoiceList = [SELECT id, Name, APEX_Status__c, createdDate FROM APEX_Invoice__c WHERE createdDate = today];
Upsert操作
List<apex_customer__c> CustomerList = new List<apex_customer__c>();
for (Integer i=0; i< 10; i++) {
apex_customer__c objcust=new apex_customer__c(name='Test' +i, apex_external_id__c='1234' +i);
customerlist.add(objcust);
} //Upserting the Customer Records
upsert CustomerList;
删除操作
List<apex_invoice__c> invoiceListToDelete = [SELECT id FROM APEX_Invoice__c WHERE APEX_Customer__r.Name = 'Test'];
delete invoiceListToDelete;
取消删除操作
List<apex_invoice__c> invoiceListToDelete = [SELECT id FROM APEX_Invoice__c WHERE APEX_Customer__r.Name = 'Test'];
//DML Statement to delete the Invoices
delete invoiceListToDelete;
system.debug('Deleted Record Count is '+invoiceListToDelete.size());
System.debug('Success, '+invoiceListToDelete.size()+'Records has been deleted');
//Restore the deleted records using undelete statement
undelete invoiceListToDelete;
1499

被折叠的 条评论
为什么被折叠?



