You need to sign in to do that
Don't have an account?

How to transfer ID from one Visualforce page to another
Hi Gurus,
I have a Visualforce page for a Survey form that saves entry in to a custom object (Survey) in Salesforce. Within this VF page, I have images of different countries flags which are links to the same survey but in a different language. i.e the french flag with be a link to another VF page but will be the same survey but in french.
Now my problem is that when the flag is click and goes to the different language page, the Survey ID in the web address bar is removed therefore the entry wouldnt be saved into the correct place in Salesforce.
So does any one please know I can transfer the ID from one VF page to another?
This is the Div Class for my UK Flag linking to the english version;
This is my Apex Class for keeping the ID in the address bar after clicking on the UK Flag but its not working:
Please if anyone know how I can resolve this issue, please let me know please!
Thanks!
I have a Visualforce page for a Survey form that saves entry in to a custom object (Survey) in Salesforce. Within this VF page, I have images of different countries flags which are links to the same survey but in a different language. i.e the french flag with be a link to another VF page but will be the same survey but in french.
Now my problem is that when the flag is click and goes to the different language page, the Survey ID in the web address bar is removed therefore the entry wouldnt be saved into the correct place in Salesforce.
So does any one please know I can transfer the ID from one VF page to another?
This is the Div Class for my UK Flag linking to the english version;
<div class="UK_Flag"> <a href="/apex/CustomerSatisfaction_EN"><apex:image id="UK_Flag" value=" {!URLFOR($Resource.UK_Flag)}" /></a> </div>
This is my Apex Class for keeping the ID in the address bar after clicking on the UK Flag but its not working:
public with sharing class CustomerSurvey{ public CustomerSurvey() { } public PageReference UK_Flag () { PageReference pageref = new PageReference('/apex/CustomerSurvey_UK'); pageref.getParameters().put('recordID', 'a0C3E000001yarn' + ''); pageref.setRedirect(true); return pageref; return pageref; } }
Please if anyone know how I can resolve this issue, please let me know please!
Thanks!
Yes, you've just misplaced it a bit :)
It should be like this :
All Answers
Maybe try writing your function in the following format :
Let me know if it worked for you.
Since you are using href to navigate to another page and that will just redirect you to that page without passing the parameter.
What you need to do is onclick on the flag call the apex method "UK_Flag" and from there it will redirect the user to right page along with the survey id.
In case you want to use the image to be click then you can use apex:action function to call your apex method.
How to use apex:actionfunction
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_actionFunction.htm
Please let me know in case it helps.
Regards,
Ashish Kr.
I'm getting error stating :
Do you know why this is by any chance?
Thanks!
Okat thanks ill look into it and hopefully it helps resolve the issue
Thanks!
Hello ola,
Try this
Thanks for your response. I tried your code and i recieved an error stating
This error appears when I add "CustomerSurvey" to the "extensions" tag within the standard controller.
Do you know why did this by any chance?
Thanks very much!
Just add a constructor to your CustomerSurvey controller that receives a standard controller as a parameter.
It should look something like this:
if you are using StandardController on vf page then you have to add this constructor in your apex class CustomerSurvey
Thanks,
Shubham
Thanks for the reply. I changes the 'ctrl' to 'controller' and im not recieving any errors. However when I switched pages, the ID doesnt transfer to the second page meaning the entry cant be saved.
Do you know what changes ill need to make to ensure that the ID is transfered?
Thanks very much again
you can have as many methods in your apex class but they are of no use until you execute/call them, same is the case here.
you have your method to redirect to another page along with id but you sre not calling that method from your vf page.
please take reference from my earlier answer to call this method onclick of flag.
let me know in case if you need any help.
Regards,
Ashish Kr.
Thanks. This is my onclick in my VF page:
& this is my Apex code:
The flag is showing on the however, nothing is happening when I click the flag - its not redirecting or transferring the ID.
Do you know what changes I could make to make the redirection and transferr happen?
Thanks for the help!
In this case you should use actionFunction element to call controller function.
In VF page add:
And also please fix your controller's constructor to initiate the controller correctly : this.ctrl = controller;
I hope this will help you
Thanks
You may even remove script tag and can call action function directly with onclick method name.
#Write less code while do more. :)
Regards,
Ashish Kr.
Yes, we can also do like this
Thank you
Thanks I tried your code. The ID is now remaining in the address bar but the page is’nt going to the English Visualforce page. So its also like it refreshing the page but not going to the second VF page.
I’m not sure why this is because the English VF page is in the page reference in the apex.
Thanks very much!
Thanks again for the support. I tried your code and the ID remains in the address bar but the page doesn’t go to the English VF which is in the apex code in the page reference.
Do you know the changes ill need to make as for the page does refresh but doesn’t go the other VF page.
Thanks so much for the help!
Please try writing the actionFunction as Ashish Kumar or Shubham saini 14 suggested but also add "immediate="true" to it so it will look like this :
If it won't work please share the VF and controller code with us.
Thanks
Thanks! the "immediate" tag allows the ID to be passed through to the second VF page!!
However there is one more problem before I stop bovering you gurus :D
In the apex code, it defines a specific ID therefore entry will only be saved into that ID in Salesforce. So is there a adaptation that I can make so that it keeps whatever ID is in the address, rather than this specific one?
because we'll have more than one person taking the survey and we dont it to be all saved in the same Customer ID.
Thanks very much people, I truly appricate the help and support!
Sure ! Just add a variable into the controller : public String currentRecordId {get;set;} and in the contructor with standard controller parameter add a line
Then,jus use this ID in you function (or functions) like this :
Also, please keep in mind that "immediate=true" on actionFunction bypasses validation (if you have any).
Regards,
Dmitry
The line
is no longer needed in the function body.
Thats great that it can be done! I made the adjustments that you mentioned to the best of my undertanding but im recieving several errors so im guessing ive made a mistake somewhere.
This is what my apex code looks like now:
Is this how its suppose to look like or did I put it in the wrong place?
Thanks very much!
Yes, you've just misplaced it a bit :)
It should be like this :
Yes its working now!! Big thanks to ypi and everyone in this thread that help me out, its much appreciated!! I wish i could best answer everyones response as you all helped :D
Again thanks very much!