how can i make my visualforce custom buttons work? - salesforce

I have a test visualforce page that I'm trying to get working. It's just a blank page with 2 buttons that should open the url in the iframe. Below is the code that I have behind the page.
Apex Class:
public class OnLoadController {
public String Page {get; set;}
public String OpenPageURL {get; set;}
public void OnLoadController()
{
Page = '' ;
OpenPageURL = '' ;
}
public PageReference redirect()
{
if(Page == 'google')
{
OpenPageURL = 'http://www.google.com' ;
}
if(Page == 'mpay')
{
OpenPageURL = 'http://www.yahoo.com/' ;
}
return null;
}
}
VisualForce Page:
<apex:page id="pg" controller="OnLoadController">
<apex:form>
<apex:actionFunction action="{!redirect}" name="OpenPage" reRender="pb,theIframe">
<apex:param assignTo="{!Page}" value="" name="param1"/>
</apex:actionFunction>
<apex:pageBlock id="pb">
<apex:pageBlockButtons>
<apex:commandButton value="Google" onclick="OpenPage('google'); return false;"/>
<apex:commandButton value="Yahoo" onclick="OpenPage('blog'); return false;"/>
</apex:pageBlockButtons>
<apex:iframe id="theIframe" src="{!OpenPageURL}" scrolling="true"/>
</apex:pageBlock>
</apex:form>
</apex:page>
The page loads fine and the buttons show perfectly but when I click them nothing happens. I just want to be able to click the button and have the url open in the iframe of the page.

Your apex code and visualforce are ok, but you need to look into the browser console where you can find the following errors:
The page at 'https://c.ap1.visual.force.com/apex/test' was loaded over HTTPS, but ran insecure content from 'http://www.yahoo.com/': this content should also be loaded over HTTPS.
After fixing this error you'll face the following error:
Refused to display 'https://www.google.com/?gws_rd=cr&ei=IhiYUoCsOcWdhAedlIKwDg' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
As you understand it's security trouble.
This page will works fine OpenPageURL = 'http://www.youtube.com/embed/' ;

Related

List has no rows for assignment to SObject error although query returns rows

I'm a bit new to apex and I am trying to display a selectList in a visualforce page using a custom controller i built.
I get a "List has no rows for assignment to SObject" error when trying to preview the visualforce page, but running the query in the developer console, returns the rows.
here is my page:
<apex:page Controller="BpmIcountPayment">
<apex:form >
<apex:selectList value="{!productsTitle}" multiselect="false">
<apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>
</apex:selectList>
</apex:form>
</apex:page>
and my controller:
public class BpmIcountPayment{
private final Account account;
public String productsTitle {
get { return 'products for sale'; }
set;
}
public BpmIcountPayment() {
account = [SELECT Id, Name, Site FROM Account
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public Account getAccount() {
return account;
}
public List<SelectOption> getProductsLov() {
List<SelectOption> products = new List<SelectOption>();
List<Product2> productsList = [SELECT Id, Name, Family
FROM Product2
WHERE (Family = 'ShopProduct')
OR (Family = 'CourseParent')
OR (Family = 'SFCourseProgram')];
for (Product2 currProduct : productsList) {
products.add(new SelectOption(currProduct.Id, currProduct.Name));
}
return products;
}
}
Just to clarify the query i'm referring to is the query in getProductsLov().
My API version is 40 and i am working in a sandbox environment.
Impossible. If you're getting "list has no rows to assign to sObject" it means you're assigning to single object. This eliminates getProductsLov(unless you didn't post whole code) because there you assign to a list.
Humo(u)r me and System.debug(JSON.serializePretty(ApexPages.currentPage().getParameters())); in your constructor before firing that query...
You're viewing the page with valid Account Id passed in the URL? And that Account is visible for your current user? If the page is account-specific, try using <apex:page standardController="Account" extensions="BpmIcountPayment">... (you'll have to provide a different constructor in apex first). This could simplify your code a lot.
public BpmIcountPayment(ApexPages.StandardController sc){
if(String.isBlank(sc.getId()){
System.debug('you screwed up passing the valid acc id');
} else {
acc = (Account) sc.getRecord();
}
}

Creating a VF page ‘Registration Form’ for Account object is Salesforce

I have below requirement to Create a VF page – ‘Registration Form’ having
1.Name field
2.Attachment area – where we can browse and add any document there
Expected UI-UI
Below is my VF code-
<apex:page standardController="Account" extensions="InputFileControllerExtension">
<apex:messages />
<apex:form id="theForm">
<apex:pageBlock >
<apex:pageBlockSection columns="2" showHeader="true" title="Personal Details" >
<apex:inputField value="{!Account.Name}" />
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/>
<apex:commandButton value="Upload and save" action="{!save}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Below is the APEX Class-
public class InputFileControllerExtension
{
private final Account acct;
public Attachment attachment {get;set;}
public PageReference save()
{
attachment.parentid = acct.id;
insert attachment;
return stdController.save();
}
public InputFileControllerExtension(ApexPages.StandardController stdController)
{
attachment = new Attachment();
this.acct = (Account)stdController.getRecord();
this.stdController = stdController;
}
ApexPages.StandardController stdController;
}
Error I am getting-
Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Parent]: [Parent]
Error is in expression '{!save}' in component in page file_upload_test: Class.InputFileControllerExtension.save: line 8, column 1
could you please help me to resolve this?
Thanks
Why are you saving the Account record at the end of your save() method? Why not just view it using
stdController.view()

Customize "Send With Docusign" in Salesforce Lightning

I was able to pre-populate recipients list using javascript button by setting CRL parameter in SF Classic.
Now I would like to achieve the same in Lightning.
I tried creating a VF page that would redirect user to dsfs__DocuSign_CreateEnvelope page and add desired ur parameters (much like in JS button).
It partly works - it pre-populates recipients list, it allows to send the email. But finally throws an error: "Javascript proxies were not generated for controlled dsfs.EnvelopeController: may not use public remoted methods inside an iframe"
What is the proper way to achieve such functionality in lightning?
Is it even possible?
UPDATE:
VF Page:
<apex:page standardController="Opportunity"
extensions="CTRL_DocusignRedirect"
sidebar="false"
showHeader="false"
action="{!autoRun}"
>
<apex:sectionHeader title="DocuSign"/>
<apex:outputPanel >
You tried calling an Apex Controller from a button.
If you see this page, something went wrong.
Please notify your administrator.
</apex:outputPanel>
</apex:page>
Controller:
global class CTRL_DocusignRedirect
{
private static final STRING PARAM_DSEID = 'DSEID';
private static final STRING PARAM_SOURCE_ID = 'SourceID';
private static final STRING PARAM_CRL = 'CRL';
private Opportunity anOpportunity = null;
public CTRL_DocusignRedirect(ApexPages.StandardController stdController)
{
Id opportunityId = stdController.getRecord().Id;
this.anOpportunity = DAL_Opportunity.getById(opportunityId);
}
public PageReference autoRun()
{
if (this.anOpportunity == null)
{
return null;
}
PageReference pageRef = Page.dsfs__DocuSign_CreateEnvelope;
pageRef.getParameters().put(PARAM_DSEID, '0');
pageRef.getParameters().put(PARAM_SOURCE_ID, this.anOpportunity.Id);
pageRef.getParameters().put(PARAM_CRL, this.getCRL());
pageRef.setRedirect(true);
return pageRef;
}
private String getCRL()
{
return 'Email~' + anOpportunity.Payer_Email__c +
';FirstName~' + anOpportunity.Payer_First_Name__c +
';LastName~' + anOpport`enter code here`unity.Payer_Last_name__c +
';RoutingOrder~1;Role~Pay`enter code here`er;';
}
}
Thanks in advance

Unable to clear the fileds after saving the data using apex code

//Apex page
<apex:page controller="MyController" tabStyle="Account" showChat="false" >
<apex:form >
<apex:pageBlock title="Congratulations {!$User.FirstName}">
You belong to Account Name: <apex:inputField value="{!account.name}"/>
Annual Revenue: <apex:inputField value="{!account.AnnualRevenue}" required="true"/>
<apex:commandButton action="{!save}" value="save"/></apex:pageblock>
</apex:form>
</apex:page>
My code is saving the data to my account successfully.But,the fields are not clearing until i press refresh button
//Apex Class
public class MyController {
private Account account; public Account getAccount(){
if(account == null)
account=new Account();
return account;
}
public PageReference save(){
insert account;
return null;
}
}
My code is saving the data to my account successfully.But,the fields are not clearing until i press refresh button.
So, anyone can guide me to clear the page after saving my data?
Because the account value is still available in the view state.
add another line in the pagereference method and that should help. something like this:
public PageReference save(){
insert account;
account=null;
return null;
}

Accessing Email templates in VisualForce

Hi i created an object in which onefield is lookup to user and other field is id of email template .
i have to create a visualforce page in which i have to assign different email templates to different users and then save records of custom object. can u please tell me how to get all email templates Name and id created in MyTemplates in picklist of VF page??
APEX CONTROLLER
public class TemplateSelectorController {
public String selectedTemplateId { public get; public set; }
public List<SelectOption> getMyPersonalTemplateOptions() {
List<SelectOption> options = new List<SelectOption>();
for (EmailTemplate t : [
select Id,Name
from EmailTemplate
// Each User has a 'My Personal Templates' folder
// of EmailTemplates, whose Id is the User's Id
where FolderId = :UserInfo.getUserId()
]) {
options.add(new SelectOption(t.Id,t.Name));
}
return options;
}
}
VISUALFORCE PAGE
<apex:page controller="TemplateSelectorController">
<apex:form>
<apex:selectList value="{!selectedTemplateId}">
<apex:selectOptions value="{!myPersonalTemplateOptions}"/>
</apex:selectList>
</apex:form>
</apex:page>

Resources