Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7832531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:16:05+00:00 2026-06-02T12:16:05+00:00

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

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:16:06+00:00Added an answer on June 2, 2026 at 12:16 pm

    The problem is that you are taking the ID and passing that to a method which retrieves the OLD row with that ID that is already in the database, and trying to use addError() on that. It won’t work because addError() will not work on rows that are already in the database.

    Without knowing your exact requirements I would make this suggestion – put validation rules on the Opportunity object. Then you can code your button to just simply update the record. The validation rules will take care of the rest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a custom cell i want to delete it when a button is
I have a button that has custom code which sends the form data to
I have a search on site. It is simple text input with submit button.
Hi, I have some problems with an implementations off custom submit buttons. pleas take
I have coded custom form validation. validation is working fine all browser but when
Within an ASP.NET AJAX UpdatePanel on my page I have a submit button which
I have made a custom suface button according this example: <Button> <Button.Template> <ControlTemplate TargetType=Button>
I have custom server control contains templatefield when an out button clicked the field
I have a sheet with a custom button on it from where I control
I'm making a custom button (Winforms Control Library) and have the code below so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.