function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Son Tung MaiSon Tung Mai 

Mergefield doesnt display value in visualforce page after updating codes

hi

our visualforce page for customer voucher requires to have a small change where it used to display the voucher value how much is gifted, we want it to now show how many hot laps gifted instead of $ amount

original code showing voucher value using merge field Voucher_Value__c with Formula (Currency) field type on object voucher:
<tr>
<td class="tdbordernobottom" width="300" align="right" bgcolor="#ffe383"><strong>No of V8 Laps:&nbsp;</strong></td>
<td class="tdbordernoleft">&nbsp;<apex:outputField value="{!voucher.Voucher_Value__c}"/></td>
</tr>

i made changes by replacing with merge field No_of_V8_Laps__c with Formula (Number) field type on object voucher:
<tr>
<td class="tdbordernobottom" width="300" align="right" bgcolor="#ffe383"><strong>No of V8 Laps:&nbsp;</strong></td>
<td class="tdbordernoleft">&nbsp;<apex:outputField value="{!voucher.No_of_V8_Laps__c}"/></td>
</tr>

it doesnt work however, just showing blank or the page doesnt even load properly

can anyone help and tell me what im doing wrong please?

thanks 
Best Answer chosen by Son Tung Mai
Anupama SamantroyAnupama Samantroy
Hi 
Please replace the code below 
voucher = [select Id,name,Voucher_Type__c,Voucher_Value__c,Courses__c,Courses__r.name,Gifted_To__c,Voucher_Message__c,
          Voucher_Expiry__c,Date_Purchased__c,Purchaser__c,Purchaser__r.name,No_of_V8_Laps__c
          from Vouchers__c where id = :voucherId];
Please mark this as answer if it solves.

Thanks
Anupama

All Answers

Anupama SamantroyAnupama Samantroy
Please check if the user has access to the formula field.

Thanks
Anupama
Son Tung MaiSon Tung Mai
sorry but what you mean by if the user has access to the formula field?
Anupama SamantroyAnupama Samantroy
Yes. Does the user have read permission for that field.
Son Tung MaiSon Tung Mai
yes they do
Anupama SamantroyAnupama Samantroy
Hi Son,
 There could be 2 reasons
1. If the user does not have permission to view this field. You can check this on the user's profile and then go to the Field-Level Security and check the object's field for permission.
2. You have the neccessary permission but you are not querying the field. This will give VF page error and the page will not load. You need to query this field as well.

Thanks
Anupama
Son Tung MaiSon Tung Mai
1. i did check the field level security of this merge field and tick all the available checkboxes so its visible for everyone. the visualforce page link is emailed to customer once the voucher is purchased so they click on the link in the email to retrieve their voucher, at which point they will see the visual force page in their internet browser displaying the relevant information to their specific voucher, from the merge fields on voucher object

2. what you mean by query the field? can you please explain? i dont actually know much about these codes

thanks 
Anupama SamantroyAnupama Samantroy
Is the page not loading at all?
Can you please check the controller of the page and check for the variable "voucher". It must be getting its value from a query.
Something like this, Voucher = [Select id, <som more field> from Voucher__c]; There you need to add the new field No_of_V8_Laps__c as well.

If possible for you can you post the controller here and also what is the error you are getting when trying to access the page then I can help you better.

Thanks
Anupama 
Lakshmi SLakshmi S
Hi Son,

Check the No_of_V8_Laps__c field data in Voucher Object whether the formula field is working or not.If you are getting data in the Voucher object, then you check the Visualforce page coding.


 
Son Tung MaiSon Tung Mai
No_of_V8_Laps__c formula field data in Voucher Object works all good, on the records, the field formula works fine and shows data all ok

also, going through the codes, i cannot seem to see any query as you explained but despite that, all other merge fields are working fine though. if i change it back to the voucher value to show $$$ amount now, it shows perfectly ok. its only when it change it to No_of_V8_Laps__c, the merge field goes blank?

 
Anupama SamantroyAnupama Samantroy
Can you post the Apex class "VoucherPDFCtrl" here please.

Thanks
Anupama
Anupama SamantroyAnupama Samantroy
Hi 
Please replace the code below 
voucher = [select Id,name,Voucher_Type__c,Voucher_Value__c,Courses__c,Courses__r.name,Gifted_To__c,Voucher_Message__c,
          Voucher_Expiry__c,Date_Purchased__c,Purchaser__c,Purchaser__r.name,No_of_V8_Laps__c
          from Vouchers__c where id = :voucherId];
Please mark this as answer if it solves.

Thanks
Anupama
This was selected as the best answer
Anupama SamantroyAnupama Samantroy
You cannot edit the Apex Class directly in Production. You need to make these changes in sandbox and then deploy the class and the page to Production
 
Son Tung MaiSon Tung Mai
i can see now the edit option in sandbox to modify the controller, thanks for putting me into the right direction

last silly question i hope please, once i finish editing the controller in sandbox and save it, how do i deploy the class to production to finalise the change and make it work hopefully?
Anupama SamantroyAnupama Samantroy
You can use change sets to deploy to PRODUCTION.

Please mark the answer.

Thanks
Anupama
Anupama SamantroyAnupama Samantroy
Please close this thread by marking the answer if it helped you

Regards
Anupama
Son Tung MaiSon Tung Mai
i am yet to finish this. still working out how to modify the code in sandbox since its prompting error message so havent yet deployed to production either
i mark to close off when done
Lakshmi SLakshmi S
HI Anupama, Please check the below mentioned query Q). . I have 200 records on a batch while loading the records using data loader, i need to stop the records insertion after 10 records are inserted? how to achieve this?