You need to sign in to do that
Don't have an account?
SFDC_Developer
How to display update Name in vf page
I have one VF page which has one field Name having default value of 'filled by trigger'. In the same page, I have one lookup field to object B. When we select this field and click on save button then our trigger will fire and it will update the Name value with the name of Selected record of object A.
I have checked the record created from vf page in standard page, where it is correctly displaying the field name, but when it comes to vf page it is not displaying the update name.
I am guessing this may be because of getter and setter.
VF Page:
Controller:
I have checked the record created from vf page in standard page, where it is correctly displaying the field name, but when it comes to vf page it is not displaying the update name.
I am guessing this may be because of getter and setter.
VF Page:
<apex:page standardController="ObjectA" extensions="objectAController" > <apex:form > <apex:pageBlock title="ObjectA Edit" mode="edit"> <apex:pageMessages /> <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!save}" /> </apex:pageBlockbuttons> <apex:pageBlockSection title="ObjectA Name" columns="2" > <apex:inputField value="{!ObjectA__c.Name}" required="true"/> </apex:pageBlockSection> <apex:pageBlockSection title="Product Information"> <apex:inputField value="{!ObjectA__c.Product2Id__c}" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Controller:
public class objectAController { ApexPages.StandardController stdCtrl; public objectAController(ApexPages.StandardController controller) { this.obj = (ObjectA)controller.getRecord(); obj.Name = 'Filled by Trigger'; this.stdCtrl= controller; } public PageReference save() { ObjectA__c objA =(ObjectA__c)stdCtrl.getRecord(); try { upsert(objA); } catch(System.DMLException e) { ApexPages.addMessages(e); } return null; } }
As you are using standard Controller, objectA__c.Name, in order to show its value, the page needs an url, so after saving, instead of return null, you would need to return your page with the id as parameter. In addition, you would need to check in the constructor if the record has Id in order to populate it with the Productname__c value or your default one.
Another option is to override the edit button of your ObjectA__c with this page.
And return edit standard fucntionality in the save method
All Answers
I added this line to the vf page in order to be sure that a new record was created, and yes, after clicking on save, the Id value appears in the vf page.
Apart from that, your code looks fine. I have tried setting the new Name value directly and works for me, so maybe the issue is in your trigger. Could your share it here?
Thanks for your reply.
I have added the output field
in my code and after saving record it is showing record it also.
Here ProductName__c is formula field.
As you are using standard Controller, objectA__c.Name, in order to show its value, the page needs an url, so after saving, instead of return null, you would need to return your page with the id as parameter. In addition, you would need to check in the constructor if the record has Id in order to populate it with the Productname__c value or your default one.
Another option is to override the edit button of your ObjectA__c with this page.
And return edit standard fucntionality in the save method
Now its working
Thanks,
Agustina