VisualForce Page to render list of selected contacts - salesforce

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

Related

How to call parameterized controller in apex command button in visualforce?

I have a apex class of the following type
public standardcontroller(){
List<account> accountList = [SELECT Name FROM Account LIMIT 20];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountList);
List<Account> selected=ssc.getSelected();
}
public PageReference save(List<Account> selected){
if(code logic)
}
The visual force page contains a command button
<apex:commandButton action="{!save}" value="Save" id="theButton"/>
How to pass the parameter List selected when calling save method from vf page
You have to retrieve the Id of that record (In case of the detail button)
Id recordId = standardController.getId();
Account record = (Account) standardController.getRecord();
PageReference pdfPage = new PageReference('/apex/YOURVFPAGENAME');
pdfPage.getParameters().put('id',recorded);
Now you have the Id of that record, now you can perform any action in the controller base on that ID.

How to especify a current key-node in xamarin with firebase?

I’m working with Xamarin and FireBase, I have the next problem:
I have Users in my database and each one has a list of items. I need to retrieve the list of items of the current user, and the problem is that I don’t know how to replace the key of each user in the tree, (I just hard-wrote it). This is the snippet :
var products = (await client.Child("Users").Child("-MXf6T19md1UOTVvHWRU").Child("Items")
.OnceAsync<Item>())
.Select(f => new Item
{ . . .
Here is a picture of the database tree.
How do I replace the Child("-MXf6T19md1UOTVvHWRU") by the current branch where I’m at?, taking into account that I have to access another Child next to that. Of course I have access to the Username value that is stored in preferences.
I would appreciate some enlightenment, thanks in advance.
I need to retrieve the list of items of the current user, and the problem is that I don’t know how to replace the key of each user in the tree, (I just hard-wrote it).
You could use the code below to get all the items first and then get the specific item.
public async Task<List<User>> GetAllUsers()
{
return (await firebase
.Child("Users")
.OnceAsync<User>()).Select(item => new User
{
Name = item.Object.Name,
UserId = item.Object.UserId,
}).ToList();
}
public async Task<User> GetUser(int userId)
{
var allUsers = await GetAllUsers();
await firebase
.Child("Users")
.OnceAsync<User>();
return allUsers.Where(a => a.UserId == userId).FirstOrDefault();
}
Model:
public class User
{
public int UserId { get; set; }
public string Name { get; set; }
}
You could download the similar source code from the GitHub.
https://github.com/susairajs/Xamarin-Firebase-RealtimeDatabase

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

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

Resources