APEX学习笔记(三)

Apex - DML

INSERT操作

APEX_Customer__c objCust = new APEX_Customer__C();
objCust.Name = 'Test ABC';
insert objCust;

更新操作

List invoiceList = [SELECT id, Name, APEX_Status__c, createdDate FROM APEX_Invoice__c];
List updatedInvoiceList = new List();
invoiceList[0].APEX_Status__c = 'Pending';
updatedInvoiceList.add(invoiceList[0]);
update updatedInvoiceList;

检索操作

List invoiceList = [SELECT id, Name, APEX_Status__c, createdDate FROM APEX_Invoice__c WHERE createdDate = today];

Upsert操作

List CustomerList = new List();
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 invoiceListToDelete = [SELECT id FROM APEX_Invoice__c WHERE APEX_Customer__r.Name = 'Test'];
delete invoiceListToDelete;

取消删除操作

List 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;

你可能感兴趣的:(SFDC)