0

the error message was shown initially when model ,discount values are not entered. after entering the values and clicking save button the values are inserted but my page redirects to another page which displays

"sales force no longer URL exists"

controller

public void Newlinesave() {
    system.debug('>>>>>>>>>>new value'+proo);
    if(proo.Model__c==null && proo.Discount__c==null){
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the Model,Discount values');
        ApexPages.addMessage(myMsg);

    }  
    else{   
    insert proo;
    refreshPage=true;
     }

}

vf

<div id="dipslaydiv" style="display:none;" >
    <apex:pageBlock mode="maindetail" >
     <apex:pageMessages id="showmsg"></apex:pageMessages>
      <apex:pageBlockSection columns="2"> 

 <apex:inputField value="{!proo.Model__c}" />

<apex:inputField value="{!proo.Discount__c}" />

   </apex:pageBlockSection>

    <apex:pageBlockButtons location="bottom">
    <apex:commandButton action="{!Newlinesave}" value="{!$Label.Save3}" reRender="showmsg"/>
    <apex:commandButton action="{!Cancel}" value="Cancel" />
    </apex:pageBlockButtons>
    </apex:pageBlock>
</div>
1

If you are redirecting to the same page, then just return null as the PageReference. Also, verify that the apex:pageMessages tag is rerendered which you have done already. I have added a success message also in case there is successful insert.

What your action may look like in Apex:

public PageReference Newlinesave() {
    PageReference pageRef = null;
    system.debug('>>>>>>>>>>new value' + proo);
    if (proo.Model__c == null && proo.Discount__c == null) {
        ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the Model,Discount values'));
        ApexPages.addMessage(myMsg);
    } else {
        insert proo;
        ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!'));
    }
    return pageRef;
}
  • the record is successfully inserted.but the page shows the error.It is not redirected to the home page. – Mahi Sep 25 '15 at 3:43
  • pageRef = ApexPages.currentPage('/id'); i passed the id.the previous error gone.but now it shows "Missing_OAuth_Token"in the page – Mahi Sep 25 '15 at 5:02
  • Why you are using OAuth? – Saroj Bera Sep 25 '15 at 5:42
  • am not using OAuth but it showing this error.I dont know y this error is coming – Mahi Sep 25 '15 at 6:39
0

Your controller method should return a PageReference that is null if there is an error.

  public PageReference Newlinesave() {
     PageReference pageRef = null;
     system.debug('>>>>>>>>>>new value'+proo);
     if(proo.Model__c==null && proo.Discount__c==null){
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please fill the Model,Discount values');
        ApexPages.addMessage(myMsg);
     }  
     else{   
        insert proo;
        pageRef = ApexPages.currentPage();    
     }
     return pageRef;
  }
  • still it showing the same error – Mahi Sep 24 '15 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.