1,建立 Custom Button 在頁面上web
2, 建立CustomJs 代碼調用Webserviceajax
1 <!--參數名區分大小寫,對於跨層object直接在Object名後直接加參字段名便可--> 2 {!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 3 {!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")} 4 5 var OppID='{!Opportunity.Id}' 6 var OppName = '{!Opportunity.OwnerLastName},{!Opportunity.OwnerFirstName}' 7 var hello = sforce.apex.execute("WSReturn", "Hello", {id:OppID,username:OppName}); 8 alert(hello);
3,編寫Webservice代碼spa
1 global class WSReturn { 2 webservice static string Hello(string id,string username){ 3 string sayHello; 4 5 sayHello = 'Hi '+username+', your id is:'+id; 6 system.debug('say hello'); 7 8 return sayHello; 9 } 10 }