0

I have a visualforce page with custom controller. I have added apex:pagemessages tag below pageblock. I have a method say method1 which updates a record in obj A which inturn updates obj B via trigger. But a validation rule in obj B fails.

My code is as follows:

public void method1(){
 try{ 
  update rec;
 }
 catch(System.DmlException e){ 
   ApexPages.Message msg = new apexPages.Message(Apexpages.Severity.ERROR, e.getdmlMessage(0));
   ApexPages.addMessage(msg);
 }
}

But this error message is not shown in vf page. This error is seen as excpetion in the debug logs.

7
  • How you are calling method1() from vf page. Try changing the return type on method1() as PageReference instead of void. Hope this may work.
    – Nebula
    Commented May 27, 2015 at 10:16
  • tried using pagereference.. but the error is still not appearing in visualforce page Commented May 27, 2015 at 10:27
  • Can you post your VF code as well where you call method1? Are you rerendering the page message component there?
    – highfive
    Commented May 27, 2015 at 10:32
  • Please share the vf code where you are showing the message.
    – Nebula
    Commented May 27, 2015 at 10:32
  • <apex:page controller="some controller"> <apex: form> <apex:pageblock> <apex:pagemessages/> <apex:pageblocktable>................... </apex:pageblocktable></apex:form></apex:page> I am also using some jquery pulgins for sorting the columns Commented May 27, 2015 at 10:51

2 Answers 2

1

I tried with your VF page and it is working for me. Click the reload button to see the message.

VF Page - testerrorpage

<apex:page controller="TestErrorClass">
<apex:form >
    <apex:pageblock >
        <apex:pagemessages />
        <apex:commandButton action="{!processtempcount}" value="Reload"/>
    </apex:pageblock>
</apex:form>

Controller

public class TestErrorClass {
  public Integer myInt { get; set; }
  public TestErrorClass (){
      myInt = 0;
  }
  public pagereference processtempcount(){
      pagereference p = apexpages.Currentpage();
      apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Total Number of reloads: ' + (myInt++));
      apexpages.addmessage(msg);
      return p; 
  }
}
0

Can you please post your VF page code, just check if you have added apexpage:messages attribute in your page

3
  • I have added the pagemessages attribute to the page. Will the usuge of jqueryUI interrupt the display of error messages Commented May 27, 2015 at 12:15
  • Please try to change the position of the error msg displayed, that is if it is displayed in top of the page change it to the field or vice versa Commented May 27, 2015 at 12:18
  • 1
    I changed the position of the pagemessages tag and it finally worked for one page. I had put the page messages tag after apex:form tag. I just moved it above form tag. and it worked now. Really wierd ! Let me try for others as well. Thanks all for your help! Commented May 27, 2015 at 12:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .