0

I have a standard field called Product Brief Number ({!Product_Brief__c.Name}). This field is Auto Number, after saving it will generate a number. I want show this field when some after click on the save button. Otherwise my page will break. I already using rerender properties in my page. if i used rendering for this part, it will break my page. Thanks

   <apex:outputText value="{!Product_Brief__c.Name}"></apex:outputText>

   <apex:pageblockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageblockButtons>
3
  • Why will rerendering break your page?
    – Eric
    Jul 20 '15 at 22:26
  • @ Eric, I already used rerendering option for Edit and View. When I add This one, it will break my page or my edit option will not work .
    – Suneth
    Jul 20 '15 at 22:28
  • What specifically happens that "breaks" your page when you add a serenader there? Unless something else is going on (required fields, etc) then it should not break your page. You are going to have to be more specific in your details
    – Eric
    Jul 20 '15 at 22:31
1

What you need is to be able to query the record from the database. Therefore, your solution depends on your page's design.

standardController + Extension

If you're using a standard controller, which it appears you are, you have to force a refresh of the entire page, because the record is only loaded once per view state. That looks like this:

public PageReference saveRecord() {
    // ApexPages.StandardController from constructor
    if(controller.save() == null) {
        return null;
    }
    PageReference ref = Page.myPage;
    ref.getParameters().put('id', controller.getId());
    ref.setRedirect(true);
    return ref;
}

If you're overriding the "view" action with your page, this isn't necessary, as a standard "{!save}" will effectively do the same thing.

controller

If you have your own controller, you can simply:

public void save() {
    upsert theRecord;
    theRecord = [SELECT Name, ... FROM ... WHERE Id = :theRecord.Id];
}

Of course, this doesn't cover error handling, so I'll leave that up to you.

1

Give id to your outputtext tag. Place oncomplete attribute on the command button.Call a javascript function from there. In the java script fetch the apex:outputText attribute by using the id after that just replace the html of the tag with the new value.

function updateText(){ var a=documnet.getElementById({!$Component.Path_To_The_OPTextTag}); a.html()='{!Product_Brief__c.Name}'; }

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.