APEX学习笔记(三)

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;
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值