You need to sign in to do that
Don't have an account?
Matthias Kimmig
How can I define a Button that directly executes a link on a VisualForce page?
Hey,
I have created the following Apex class and the Visualforce page:
Apex-Class:
VisualForce Page
The link in the Visualforce page should be immediately executed when the user clicks on the button. How can I implement it?
It is important that the parameters of the Apex class passed the link previously.
Regards,
Matthias
I have created the following Apex class and the Visualforce page:
Apex-Class:
public class MailOppController{ public List<OpportunityContactRole>cRole{get; set;} public List<OpportunityContactRole>pRole{get; set;} public String oppID; public MailOppController(ApexPages.StandardController controller){ Opportunity currentobject = (Opportunity) controller.getRecord(); oppID = currentobject.Id; cRole = [SELECT ContactId, OpportunityId, IsPrimary FROM OpportunityContactRole WHERE OpportunityId = :oppID AND IsPrimary=false]; pRole = [SELECT ContactId, OpportunityId, IsPrimary FROM OpportunityContactRole WHERE OpportunityId = :oppID AND IsPrimary=true]; } public String getCarbonCopy(){ String carbonCopy; for (Integer i=0; i<crole.size();i++) { Contact mail_temp = [SELECT Email FROM Contact WHERE Id = :cRole.get(i).ContactId]; if(i==0){ carbonCopy = mail_temp.Email; } else { carbonCopy = carbonCopy +', '+ mail_temp.Email; } } return carbonCopy; } public String getPrimary(){ String primary; Contact mail_temp = [SELECT Email FROM Contact WHERE Id = :pRole.get(0).ContactId]; primary = mail_temp.Email; return primary; } }
VisualForce Page
<apex:page standardController="Opportunity" extensions="MailOppController" tabStyle="Opportunity"> <apex:outputLink value="https://mail.google.com/mail/u/0/?view=cm&fs=1&tf=1&source=mailto&to={!primary}&cc={!carbonCopy}" target="_blank" id="theLink">GMail</apex:outputLink> </apex:page>
The link in the Visualforce page should be immediately executed when the user clicks on the button. How can I implement it?
It is important that the parameters of the Apex class passed the link previously.
Regards,
Matthias
I made few changes to the Controller and visualforce page.
The controller has an action method sendEmail that is called from Visualforce Page's action. So as soon as page load it calls the method and redirects to the gmail. Basically you dont need getters anymore, but I left them (and calling from constructor). in case you are using for something else.
The visualforce page is much simplified now with just one <apex:page> tag
When you add this as standard button, please make sure you choose open in new window property.
Hope this helps.
Thank you
All Answers
I made few changes to the Controller and visualforce page.
The controller has an action method sendEmail that is called from Visualforce Page's action. So as soon as page load it calls the method and redirects to the gmail. Basically you dont need getters anymore, but I left them (and calling from constructor). in case you are using for something else.
The visualforce page is much simplified now with just one <apex:page> tag
When you add this as standard button, please make sure you choose open in new window property.
Hope this helps.
Thank you
thanks for your help. It seems to be in the right direction.
However, the e-mail addresses do not arrive in the form. There is "null" output.
Do you have any idea what might to be the reason for this?
Regards,
Matthias