function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anil DuttAnil Dutt 

Opportunity Validation from Custom button

Hi,

 

I have a custom button "Submit Order" which simple change Opportunity Stage.

But i want to add some validation check before changing Stage

 

Here is my apex class

 

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;
    }
}

 

And call for custom button is

 

{!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 });

 

but getting following error

 

SObject row does not allow errors

 

Any help would be appreciated

Thanks in advance


sanjaypatidarsanjaypatidar

is the error coming on the button ?

SFDC_EvolveSFDC_Evolve

Please go through the link below :-

 

http://boards.developerforce.com/t5/Apex-Code-Development/addError-SObject-row-does-not-allow-errors/td-p/133224

 

In case   You are able to resolve it . . Please Post the Solution .. . 

 

Plesae Marked it solved  if it resolve the issue . . 

 

Thanks 

SFDC_Evolve

Anil DuttAnil Dutt

@sanjaypatidar, yes error coming on button click