005_重写 Standard Delete Button
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")} var record = new sforce.SObject("Opportunity"); record.Id = '{!Opportunity.Id}'; //copy opportunity line items result = sforce.connection.query("Select PricebookEntry.Product2.Name, Quantity, TotalPrice From OpportunityLineItem WHERE OpportunityId = '{!Opportunity.Id}' and (NOT Name like '%Discount%')"); records = result.getArray("records"); var strProductNames = ''; for(var i=0; i<records.length ; i++){ strProductNames += 'PRODUCT NAME: ' + records[i].PricebookEntry.Product2.Name + ' --- QUANTITY: ' + records[i].Quantity + ' --- TOTAL PRICE: $ ' + records[i].TotalPrice +',\n'; } if(strProductNames.length>0){ strProductNames = strProductNames.substring(0,strProductNames.length-2); } record.Samples_Sent__c = strProductNames; //delete opportunity line items var lineItems = sforce.connection.query("select id from opportunitylineitem where opportunityid = '{!Opportunity.Id}'") var oliIds = [] var qri = new sforce.QueryResultIterator(lineItems) while(qri.hasNext()) oliIds.push(qri.next().Id) sforce.connection.deleteIds(oliIds) sforce.connection.update([record]); window.location.reload();
-------------------------------------------------------------------以下的方法是以传统的,适用于较多的业务逻辑的方式。页面->Controller
以后会用JS直接删除,但是在加载.js时候出现问题,会在以后进一步追踪完善:
<apex:page standardController="Opportunity" >
<!--extensions="accountDelete" action="{!deleterecord}"-->
<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<script src="../../soap/ajax/35.0/connection.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = setupPage;
function setupPage() {
if('{!Opportunity.Name}'=='ddd33'){
alert('{!Opportunity.Name}');
window.top.location = '/' + '{!Opportunity.Id}';
} else{
sforce.connection.deleteIds('{!Opportunity.Id}');
alert('123456');
window.top.location = '/' + '001/o'; }
}
</script>
</apex:page>
——————————————————————————————————————————————————————————
<apex:page standardController="Account" extensions="accountDelete" action="{!deleterecord}"> <apex:pageMessages /> </apex:page>
public with sharing class accountDelete {
apexpages.standardcontroller controller;
public accountDelete(ApexPages.StandardController controller) {
this.controller = controller;
}
public pagereference deleteRecord() {
try {
delete controller.getRecord();
return new pagereference('/home/home.jsp'); //return new pagereference('/001/o'); ----------执行完controller 后跳转到的页面;
} catch(exception e) {
apexpages.addmessages(e);
}
return null;
}
}