Customize "Send With Docusign" in Salesforce Lightning - salesforce

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

Related

VisualForce Page to render list of selected contacts

Here is a scenario , I am stuck in.
//edited post to elaborate more details.
Requirement: I need to email bulk of selected contacts. When there is no email to selected contacts, we are required to populate the name of contacts on UI who do not have the email. I am able to accomplish first part of requirement but stuck on displaying contact names on visual force page .
List button : BulkEmailTest which calls firstVF visual force page.
firstVF code:
<apex:page standardController="Contact" extensions="FirstController" recordSetVar="listRecs"
action="{!send}">
Emails are being sent!
window.history.back();
</apex:page>
FirstController code: for simplified code, I have edited snippet for contacts with email as our priority is only related to contacts with no email.
public with sharing class FirstController
{
public List noEmail {get;set;}
public Contact contact;
public List allcontact {get; set;}
Id test;
public Contact getAllContact() {
return contact;
}
ApexPages.StandardSetController setCon;
ApexPages.StandardController setCon1;
public static Boolean err{get;set;}
public FirstController(ApexPages.StandardController controller)
{
setCon1 = controller;
}
public FirstController(ApexPages.StandardSetController controller)
{
setCon = controller;
}
public PageReference cancel()
{
return null;
}
public FirstController()
{
}
public PageReference send()
{
noEmail = new List();
set ids = new set();
for(Integer i=0;i<setCon.getSelected().size();i++){
ids.add(setCon.getSelected()[i].id);
}
if(ids.size() == 0){
err = true;
return null;
}
List allcontact = [select Email, Name, firstName , LastName from Contact where Id IN :ids];
for(Contact current : allcontact)
{
system.debug(current);
if (current.Email!= null)
{
PageReference pdf = Page.pdfTest;
pdf.getParameters().put('id',(String)current.id);
system.debug('id is :'+current.id);
pdf.setRedirect(true);
return pdf;
}
else //No email
{
system.debug('in else current'+current );
noEmail.add(current);
// noEmail.add(current);
system.debug('in else noemail'+noEmail );
}//e
}
if(noEmail.size()>0 ) {
PageReference pdf1 = Page.NoEmailVF;
pdf1.getParameters().put('Name', String.valueOf(noEmail));
system.debug('pring noEmail' +noEmail);
pdf1.setRedirect(false);
return pdf1;
}
return null;
}
}
NoEmailVF visual force page code
<apex:page controller="FirstController">
Emails are not sent to below contacts :
Name
<apex:repeat var="cx" value="{!allcontact}" rendered="true">
{!cx.name}
Please note that emails are not sent to selected Donors only when
they did not make any donation for that year or if they do not have email address listed.
If you still wish to retrieve donations made in this year, then you may use "Hard Copy" button listed on the Donor record to have the data printed.
.
It doesn't look like your apex:commandButton has any action. If it doesn't have an action prop, no contact is being made with your Apex code. So no oncomplete should fire.
Also, when you want to refresh some data after completing some Apex call, you can use reRender prop. Put your dynamic data in an apex:outputPanel (docs), give the apex:outputPanel an id and pass that id to the reRender of your button.
See apex:commandButton docs

ASP.NET MVC | ActionResult not getting called when going back to previous page

I understand that the title of the question may be vague but then that's the best way I could come up with to explain my issue at hand.
I'm overriding the OnActionExecuting function to manage my session related activities and allow/ deny requests to authorized/ unauthorized users, respectively. Along with tracking of the session, I'm also using the OnActionExecuting to load user available features for the current page into a temporary class and accessing from the view using ajax call.
namespace MyApp.Controllers
{
public class TESTController : Controller
{
[SessionTimeout]
public ActionResult Index()
{
return this.View();
}
}
}
public class SessionTimeoutAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
if (ctx.Session["AppUser"] == null)
{
// Redirect to the login page
// Or deny request
}
else
{
var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
var actionName = filterContext.ActionDescriptor.ActionName;
var methodType = ((ReflectedActionDescriptor)filterContext.ActionDescriptor).MethodInfo.ReturnType;
if (methodType == typeof(ActionResult))
{
// Load all user access rights for the current page into a temporary memory
// by using the Action and Controller name
}
}
base.OnActionExecuting(filterContext);
}
}
The above works like a charm.. But the issue is when the user clicks on the back button of the browser or hits the backspace key. In that case, the OnActionExecuting function is never called for the ActionResult and further I am unable to load the current page access rights for the user.
Thanks & Regards,
Kshitij
Adding the following to my ActionResult made the above code to work.
[SessionTimeout]
[OutputCache(Duration = 0, NoStore = true)]
public ActionResult SomeView()
{
return this.View();
}

How to put value in Controller from another Class?

I would like to call PageReference from VF Page in another class (Class A) so that it can generate a PDF and set as attachment. The VF Page is getting the ID from its Controller. I want to put the ID from Class A to VF Page so that it will the one to be used rather than the controller.
VF Page Name: ContactDocument
public class DocuGenerate {
public Contact ccc {get;set;}
public CaseClosureDocumentController(ApexPages.StandardController controller)
{
ccc = (Contact) controller.getRecord();
ccc = [SELECT ID, NAME FROM CONTACT WHERE ID =: ccc.id];
//GENERATE A PDF WITH THE ID RETRIEVED.
}
}
public class SendEmail {
public static void SendMessage() {
List<Contact> con = [SELECT ID FROM CONTACT LIMIT 1];
for(Contact c : con){
Pagereference vfpage1 = Page.ContactDocument;
//HOW WILL I PASS CON.ID TO VF PAGE SO THAT IT WILL BE THE ONE TO PROCESS, NOT THE ONE IN VFPAGE?
}
}
}
EXPECTED: GENERATE A PDF FILE WHEREIN THE INFO IS ABOUT CONTACT ID I HAVE IN ANOTHER CLASS, INSTEAD THE ONE BEING GENERATED IN VF PAGE.
From what I can make out you want to be sending the Id of the contact from the controller of the page your on now to the PDF Rendering page... You can do this through the page reference and URL Parameters. Adding a parameter to the page reference means that any controller for that page (standard or extension) can get this id and use the record. Here's how you add a parameter to a page reference...
public class SendEmail {
public static void SendMessage() {
List<Contact> con = [SELECT ID FROM CONTACT LIMIT 1];
for(Contact c : con){
Pagereference vfpage1 = Page.ContactDocument;
vfpage1.getParameters().put('id', c.id);
return vfpage1; //You probably need to return the page reference
//in order to redirect to it
}
}
}
Your question is not clear. What I have understand is, You want to access the contact from another class rather than the standard controller of the VF page.
You can do this by adding an extension controller which refers class A in the visualforce page. Then, In the DocuGenerate class, create another constructor which receive a class A type parameter.
<apex:page standardController="yourStandardController" extensions="A">
---
</apex:page>

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();
}
}

how can i make my visualforce custom buttons work?

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/' ;

Resources