当前位置:K88软件开发文章中心编程语言非主流编程语言Apex → 文章内容

Apex - DML

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 16:30:51

c objNewInvoice = new APEX_Invoice__c();objNewInvoice.APEX_Status__c = 'Pending';objNewInvoice.APEX_Amount_Paid__c = 1000;objNewInvoice.APEX_Customer__c = objCust.id;//DML which is creating the new recordinsert objNewInvoice;System.debug('New Invoice Id is '+objNewInvoice.id);//Deleting the Test invoices from Database//fetch the invoices which are created for Testing, Select name which Customer Name is Test.List<apex_invoice__c> invoiceListToDelete = [SELECT id FROM APEX_Invoice__c WHERE APEX_Customer__r.Name = 'Test'];//DML Statement to delete the Invoicesdelete invoiceListToDelete;System.debug('Success, '+invoiceListToDelete.size()+' Records has been deleted');取消删除操作您可以取消删除已删除并存在于回收站中的记录。 删除的记录具有的所有关系也将被恢复。 例如: 假设,您要恢复上一个示例中删除的记录。 这可以使用以下示例来实现。 我们修改了前面的例子,并在这里添加了一些额外的代码。 //fetch the invoice created todayList<apex_invoice__c> invoiceList = [SELECT id, Name, APEX_Status__c, createdDate FROM APEX_Invoice__c WHERE createdDate = today];List<apex_invoice__c> updatedInvoiceList = new List<apex_invoice__c>();APEX_Customer__c objCust = new APEX_Customer__C();objCust.Name = 'Test';//Inserting the Customer Recordsinsert objCust;for (APEX_Invoice__c objInvoice: invoiceList) {if (objInvoice.APEX_Status__c == 'Pending') {objInvoice.APEX_Status__c = 'Paid';updatedInvoiceList.add(objInvoice);}}//DML Statement to update the invoice statusupdate updatedInvoiceList;//Prints the value of updated invoicesSystem.debug('List has been updated and updated values are'+updatedInvoiceList);//Inserting the New Records using insert DML statemntAPEX_Invoice__c objNewInvoice = new APEX_Invoice__c();objNewInvoice.APEX_Status__c = 'Pending';objNewInvoice.APEX_Amount_Paid__c = 1000;objNewInvoice.APEX_Customer__c = objCust.id;//DML which is creating the new recordinsert objNewInvoice;System.debug('New Invoice Id is '+objNewInvoice.id);//Deleting the Test invoices from Database//fetch the invoices which are created for Testing, Select name which Customer Name is Test.List<apex_invoice__c> invoiceListToDelete = [SELECT id FROM APEX_Invoice__c WHERE APEX_Customer__r.Name = 'Test'];//DML Statement to delete the Invoicesdelete invoiceListToDelete;system.debug('Deleted Record Count is '+invoiceListToDelete.size());System.debug('Success, '+invoiceListToDelete.size()+'Records has been deleted');//Restore the deleted records using undelete statementundelete invoiceListToDelete;System.debug('Undeleted Record count is '+invoiceListToDelete.size()+'. This should be same as Deleted Record count');

上一页  [1] [2] 


Apex - DML