我有一个自定义按钮“提交订单”,它可以简单地更改机会阶段。
但我想在更改阶段之前添加一些验证检查
这是我的顶级课程
global class SubmitOrder {
public SubmitOrder(ApexPages.StandardController controller)
{
}
Webservice static string Submit(string oppId)
{
string message = '';
try
{
List<Opportunity> listOpp = new List<Opportunity>();
Opportunity oppNew = [SELECT id, StageName, Destination_Zone__c, Sold__c FROM Opportunity WHERE Id = :oppId];
boolean flag = true;
if(oppNew.StageName!= 'To Be Searched' && oppNew.StageName != 'Search')
{
oppNew.StageName.addError('Stage should be \'To Be Searched\' or \'Presentation\' or \'Search');
flag = false;
}
if( oppNew.Destination_Zone__c == '')
{
oppNew.Destination_Zone__c.addError('Destination Zone is required');
flag = false;
}
if(oppNew.Sold__c < 0)
{
oppNew.Sold__c.addError('Sold is required');
flag = false;
}
if(flag)
{
oppNew.StageName = 'Ticketing';
listOpp.add(oppNew);
if (listOpp != null && !listOpp .isEmpty())
{
Database.update(listOpp);
}
message ='Saved Successfully';
}
catch(System.CalloutException e)
{
message = e.getMessage();
}
return message;
}
}
并要求自定义按钮是
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var oppId= "{!Opportunity.Id}";
var result = sforce.apex.execute("SubmitOrder","Submit",{oppId:oppId });
但出现以下错误
SObject 行不允许出错
任何帮助,将不胜感激
提前致谢