Problems with SingleEmailMessage and cc - salesforce

I have an app that works fine if all destination fields (To:, cc:, and bcc:) are filled in, but if one of them is blank, I get an error stating there is an invalid email address. I am using text input fields and multiple email address are separated by semicolon (;). If the input field is blank I do not assign anything to that option. Any idea why this might happen? What value do I use for setCcAddress and setBccAddresses functions to show nothing. I have tried several(null, empty list).
See the code below.
Extension:
public class AffEngpdfExtension
{
public ID callersId;
private String transferUrl;
public String recipientEmail { get; set; }
public String ccEmail { get; set; }
public String bccEmail { get; set; }
public String subjectEmail { get; set; }
public String bodyEmail { get; set; }
public String docName { get; set; }
// Constructor
public AffEngpdfExtension(ApexPages.StandardController stdController) {
stdController.addFields(new List<String>{ 'Name', 'User_Email__c', 'Oversight_Email__c', 'Sales_Rep_Email__c' });
Affiliate_Consulting_Engagement__c affEngage;
affEngage = (Affiliate_Consulting_Engagement__c)stdController.getRecord();
callersId = stdController.getRecord().id;
this.recipientEmail = affEngage.User_Email__c;
ccEmail = affEngage.Oversight_Email__c + ';' + affEngage.Sales_Rep_Email__c;
List<Contact> senderEmail = [SELECT Id, Email FROM Contact WHERE pse__Salesforce_User__c=:UserInfo.getUserId() LIMIT 1];
bccEmail = senderEmail[0].Email;
subjectEmail = 'Affiliate Consulting Engagement ' + affEngage.Name + ' - ' + affEngage.Engagement_Code__c;
docName = affEngage.Name + '-' + affEngage.Engagement_Code__c;
}
public String TransferPage { get; set; }
// Action method to transfer to a PDF version of the current page !!!
// MUST set the value of TransferPage as part of this Action call !!!
public PageReference transferTopage() {
transferUrl = '/apex/' + TransferPage + '?scontrolCaching=1&id=' + callersId;
PageReference pdfPage = new PageReference(transferUrl);
System.Debug('transferTopage-transferUrl: ' + transferUrl);
return pdfPage;
}
// Email content...
public PageReference emailPdf() {
System.Debug('EmailPDF-TransferPage: ' + TransferPage);
if(String.isBlank(this.TransferPage)) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,
'Internal Error: missing TransferPage in pdfExtension'));
return null; // early out
}
if(String.isBlank(this.recipientEmail)) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,
'You must enter a Send To email address !'));
return null; // early out
}
if(String.isBlank(this.subjectEmail)) {
subjectEmail = TransferPage;
}
String tempstr = this.bodyEmail;
tempstr = tempstr.replaceall('[^\\W\\D]*','');
if (String.isBlank(tempstr)) {
bodyEmail = 'Document(s) attached for your review.';
}
// PageReference reportPage = ApexPages.currentPage();
transferUrl = '/apex/' + TransferPage + '?scontrolCaching=1&id=' + callersId;
PageReference pdfPage = new PageReference(transferUrl);
Blob reportPdf;
try {
reportPdf = pdfPage.getContentAsPDF();
}
catch (Exception e) {
reportPdf = Blob.valueOf(e.getMessage());
}
// Create email
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
List<String> addresses = new List<String>();
addresses.clear();
if (String.isBlank(this.recipientEmail)) {
addresses = this.recipientEmail.split(';');
message.setToAddresses(addresses);
} else
addresses.clear();
if (String.isBlank(this.ccEmail)) {
addresses = this.ccEmail.split(';');
message.setCcAddresses(addresses);
} else
addresses.clear();
if (String.isBlank(this.bccEmail)) {
addresses = this.bccEmail.split(';');
message.setBccAddresses(addresses);
} else
addresses.clear();
message.setSubject(subjectEmail);
message.setHtmlBody(bodyEmail);
// Attach PDF to email and send
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setContentType('application/pdf');
attachment.setFileName(TransferPage + '_' + docName + '.pdf');
attachment.setInline(false);
attachment.setBody(reportPdf);
message.setFileAttachments(new Messaging.EmailFileAttachment[]{ attachment });
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ message });
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,
'Email with PDF attachment sent to ' + this.recipientEmail));
return null;
}
}
VF Page:
<apex:page sidebar="false" showHeader="false" tabStyle="Account"
standardController="Affiliate_Consulting_Engagement__c"
extensions="AffEngpdfExtension"
applyHtmlTag="false" applyBodyTag="false" >
<apex:form >
<apex:pageBlock >
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockSection columns="1" >
<apex:pageBlockSectionItem dataStyle="text-align:left;">
<apex:outputLabel for="recipientEmail" value="To:"/>
<apex:inputText value="{!recipientEmail }" size="100"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem dataStyle="text-align:left;">
<apex:outputLabel for="ccEmail" value="cc: "/>
<apex:inputText value="{!ccEmail }" size="100"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem dataStyle="text-align:left;">
<apex:outputLabel for="recipientEmail" value="bcc:"/>
<apex:inputText value="{!bccEmail }" size="100"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem dataStyle="text-align:left;">
<apex:outputLabel for="subjectEmail" value="Email Subject (Optional)"/>
<apex:inputText value="{!subjectEmail }" size="100" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem dataStyle="text-align:left;">
<apex:outputLabel for="bodyEmail" value="Email Text (Optional)" />
<apex:inputTextarea value="{!bodyEmail}" rows="6" cols="20" richText="true" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem dataStyle="text-align:left;">
<apex:commandLink action="{!emailPdf }" value="Email PDF" styleClass="btn" id="btnEmail">
<apex:param name="TransferPage"
assignTo="{!TransferPage}"
value="AffiliateEngagementPdf" />
</apex:commandLink>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<c:AffEngComponent Engage="{!Affiliate_Consulting_Engagement__c }" />
</apex:page>

Disregard this question. My conditions for checking the email addresses were backwards. I have resolved it.

Related

System.LimitException: DML currently not allowed Class.Calloutcontroller.getperformcallout: line 49, column 1

public class Calloutcontroller {
List<Tutor__c> TutorList ;
// public Calloutcontroller() {
// }
// public Calloutcontroller(Tutor controller) {
// }
//public Calloutcontroller(ApexPages.StandardController controller) {
public List<consolewrap> ConsoleWrapperList{get;set;}
public List<consolewrap> getperformcallout(){
TutorList = new List<Tutor__c>();
ConsoleWrapperList = new List<consolewrap>();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('http://www.itutorindia.com/angularjs/api/smallWidget/tutorHourSalesForce');
//req.setEndpoint('http://52.24.111.14/angularjs/api/smallWidget/tutorHourSalesForce');
req.setMethod('GET');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Accept','application/json');
res = http.send(req);
if(res.getstatusCode() == 200 && res.getbody() != null){
system.debug('Response body result is+++: ' + res.getBody());
ConsoleWrapperList=(List<consolewrap>)json.deserialize(res.getbody(),List<consolewrap>.class);
/* To save Aoi data in custom object tutor*/
Tutor__c tutorObj;
system.debug('test1++++++++');
for (integer i = 0; i<ConsoleWrapperList.size(); i++)
{
system.debug('test2++++++++');
tutorObj = new Tutor__c();
tutorObj.Class_ID__c = Integer.valueOf(ConsoleWrapperList[i].class_id);
tutorObj.Tutor_ID__c = Integer.valueOf(ConsoleWrapperList[i].tutor_id);
tutorObj.Class_Time__c =date.ValueOf(ConsoleWrapperList[i].class_time);
//system.debug('time is++++ '+tutorObj.Class_Time__c);
//system.debug('Time values entered');
tutorObj.Name = ConsoleWrapperList[i].tutor_name;
tutorObj.E_Mail__c = ConsoleWrapperList[i].tutor_email;
tutorObj.Tutor_Phone__c = ConsoleWrapperList[i].tutor_phone;
TutorList.add(tutorObj);
// system.debug('test3++++++++');
}
//system.debug('TutorList++++++++'+TutorList);
}
//system.debug('Time values entered222');
upsert TutorList;
system.debug('Time values entered+++++++');
return ConsoleWrapperList;
}
}
Wrapper class
public class consolewrap {
public String class_id{get;set;}
public String class_time{get;set;}
public String tutor_id{get;set;}
public String tutor_name{get;set;}
public String tutor_email{get;set;}
public String tutor_phone{get;set;}
}
VF PAGE
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!performcallout}" var="wrap">
<apex:column headerValue="Class Id" value="{!wrap.class_id}"/>
<apex:column headerValue="Class Time" value="{!wrap.class_time}"/>
<apex:column headerValue="Tutor Id" value="{!wrap.tutor_id}"/>
<apex:column headerValue="Tutor Name" value="{!wrap.tutor_name}"/>
<apex:column headerValue="Tutor Email" value="{!wrap.tutor_email}"/>
<apex:column headerValue="Tutor Phone" value="{!wrap.tutor_phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

VisualForce page does not display a list of records or any records BUT it can display the list size

VisualForce page not displaying a list of records - title says it all.
How do I get the VF page to display the records that it is obviously counting (as it says 1-15 of 7549 records).
Looks like this:
http://i.imgur.com/KuChyJn.png - 'Wells' page
However, this is what we want it to look like (the one that we currently have working!):
http://i.imgur.com/uwXOsHS.png - 'Modems' page (I blacked out some fields, as the company we work for may not want this information disclosed)
My team is working on a salesforce.com application and we have an object, 'Modem', that contains approximately 7,500 records.
ModemController
We have created a custom controller, ModemController:
public class ModemController {
public apexpages.standardsetcontroller con {get;set;}
public Integer noOfRecords{get; set;}
public Integer size{get; set;}
public Modem__c modems {get; set;}
public List<Modem__c> AllSearchModems
{
get
{
if (con!= null)
return (List<Modem__c>)con.getRecords();
else
return null;
}
set;
}
public ModemController() {
AllSearchModems = new List<Modem__c>();
modems = new Modem__c();
String Name = ApexPages.currentPage().getParameters().get('Name');
List<Modem__c> modems = [SELECT Name FROM Modem__c WHERE ID= :Name];
}
public PageReference save()
{
update modems;
return new PageReference('/' + modems.Name);
}
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 15;
string queryString = 'SELECT Name, ModemActive__c, ModemCarrier__c, ModemCarrierData__c, DataPlanName__c, ESNNumber__c, ModemICCID__c, IMEINumber__c, IMSINumber__c, ModemIPEXT__c, ModemJob__c, ModemManufacturer__c, ModemModel__c, ModemPhone__c, PortForwarding__c, ModemIPPort__c, SIMNumber__c, ModemIPSlave__c, ModemStaticIP__c, ModemFirmwareVersion__c FROM Modem__c ORDER BY Name';
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}
set;
}
public List<Modem__c> getModems()
{
List<Modem__c> modemList = new List<Modem__c>();
for(Modem__c w : (List<Modem__c>)setCon.getRecords())
modemList.add(w);
return modemList;
}
public PageReference refresh() {
setCon = null;
getModems();
setCon.setPageNumber(1);
return null;
}
public PageReference Search()
{
if (modems.Name != null)
{
con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name, ModemActive__c,ModemCarrier__c,ModemCarrierData__c,DataPlanName__c,ESNNumber__c,ModemICCID__c, IMEINumber__c,IMSINumber__c,ModemIPEXT__c,ModemJob__c, ModemManufacturer__c,ModemModel__c,ModemPhone__c, PortForwarding__c, ModemIPPort__c,SIMNumber__c,ModemIPSlave__c,ModemStaticIP__c, ModemFirmwareVersion__c FROM Modem__c Modem__c WHERE Name= :modems.Name]));
con.setPageSize(10);
}
else
{
con = null;
}
return null;
}
public Boolean hasNext {
get {
return setCon.getHasNext();
}
set;
}
public Boolean hasPrevious {
get {
return setCon.getHasPrevious();
}
set;
}
public Integer pageNumber {
get {
return setCon.getPageNumber();
}
set;
}
public void first() {
setCon.first();
}
public void last() {
setCon.last();
}
public void previous() {
setCon.previous();
}
public void next() {
setCon.next();
}
}
Custom VF page for 'Wells' page
Here is the custom visualforce page for the 'Wells' page:
<apex:page controller="ModemController">
<apex:form >
<apex:pageBlock id="pb">
<apex:pageBlockTable value="{!Modems}" var="m">
<apex:column value="{!m.Name}" />
<apex:column value="{!m.ModemManufacturer__c}"/>
<apex:column value="{!m.ModemModel__c}"/>
<apex:column value="{!m.ModemICCID__c}"/>
<apex:column value="{!m.ModemIPEXT__c}"/>
<apex:column value="{!m.ModemCarrier__c}"/>
<apex:column value="{!m.ModemActive__c}"/>
</apex:pageBlockTable>
<apex:panelGrid columns="7">
<apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page"/>
<apex:outputText >{!(pageNumber * size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText>
<apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
<apex:outputPanel style="color:#4AA02C;font-weight:bold">
<apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
</apex:outputPanel>
</apex:panelGrid>
</apex:pageBlock>
</apex:form>
This controller works for other tabs, (see the 'Wells' page, it uses an identical controller and it works!) but does not work for 'Modems' page.
We see that 'Modems' page is at least reading in the 7,549 records (by looking at a variable noOfRecords to count how many there are) but not displaying them. I have even tried adding LIMIT to the SOQL query, to no avail. (limited it to 2,000, 1999, 1001, 1000, 999, and even 30,20, and 10)
I don't think the amount of records is the issue, I could be wrong.
If anyone has any tips, it would be greatly appreciated!
WellController
If anyone requests, here is the working code for the 'Wells' page, both VisualForce and Apex code:
WellController:
public class WellController {
public apexpages.standardsetcontroller con {get;set;}
public Integer noOfRecords{get; set;}
public Integer size{get; set;}
public Well__c wellz {get; set;}
public List<Well__c> AllSearchWells
{
get
{
if (con!= null)
return (List<Well__c>)con.getRecords();
else
return null;
}
set;
}
public WellController() {
AllSearchWells = new List<Well__c>();
wellz = new Well__c();
String Name = ApexPages.currentPage().getParameters().get('Name');
List<Well__c> wellz = [SELECT Name FROM Well__c WHERE ID = :Name];
}
public PageReference save()
{
update wellz;
return new PageReference('/' + wellz.Name);
}
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 15;
string queryString = 'SELECT Name, WellLocActivationDate__c, Active__c, AntennaType__c, WellLocBillTo__c, CompanyName__c, CompanyName_del__c, WellLocCompanyName__c, ConnectedCarrier__c, ContactReponsible__c, DataNetwork__c, WellLocSPOCDataPlan__c, WellSiteEquipHistory__c, WellLoclPD__c, WellLocKillDate__c, ModemConnectedTo__c, Name__c, WellLocModemSerial__c, SignalQuality__c, SignalStrength__c, SimCardNumber__c, TechResponsible__c, Action__c, ActionDate__c, WellLocName__c, WellLocOwningCompanyName__c FROM Well__c ORDER BY Name';
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}
set;
}
public List<Well__c> getWells()
{
List<Well__c> wellList = new List<Well__c>();
for(Well__c w : (List<Well__c>)setCon.getRecords())
wellList.add(w);
return wellList;
}
public PageReference refresh() {
setCon = null;
getWells();
setCon.setPageNumber(1);
return null;
}
public PageReference Search()
{
if (wellz.Name != null)
{
con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name, WellLocActivationDate__c, Active__c, AntennaType__c, WellLocBillTo__c, CompanyName__c, CompanyName_del__c, WellLocCompanyName__c, ConnectedCarrier__c, ContactReponsible__c, DataNetwork__c, WellLocSPOCDataPlan__c, WellSiteEquipHistory__c, WellLoclPD__c, WellLocKillDate__c, ModemConnectedTo__c, Name__c, WellLocModemSerial__c, SignalQuality__c, SignalStrength__c, SimCardNumber__c, TechResponsible__c, Action__c, ActionDate__c, WellLocName__c, WellLocOwningCompanyName__c FROM Well__c Well__c where Name = :wellz.Name]));
con.setPageSize(10);
}
else
{
con = null;
}
return null;
}
public Boolean hasNext {
get {
return setCon.getHasNext();
}
set;
}
public Boolean hasPrevious {
get {
return setCon.getHasPrevious();
}
set;
}
public Integer pageNumber {
get {
return setCon.getPageNumber();
}
set;
}
public PageReference make()
{
return Page.wellCreate;
}
public void first() {
setCon.first();
}
public void last() {
setCon.last();
}
public void previous() {
setCon.previous();
}
public void next() {
setCon.next();
}
}
VF page - 'Wells'
And the VisualForce page associated with the 'Wells' object:
<apex:page controller="WellController">
<apex:form >
<apex:pageBlock title="Wells" id="pb">
<apex:pageBlockSection >
<apex:commandButton action="{!make}" value="Create New"/>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!Wells}" var="w">
<apex:column headerValue="Well Name">
<apex:outputLink value="/apex/wellEdit?id={!w.id}">{!w.WellLocName__c}</apex:outputLink>
</apex:column>
<apex:column value="{!w.WellLocModemSerial__c}" />
<apex:column value="{!w.WellLocCompanyName__c}" />
<apex:column value="{!w.WellLocOwningCompanyName__c}" />
<apex:column value="{!w.WellLocBillTo__c}" />
<apex:column value="{!w.Active__c}" />
</apex:pageBlockTable>
<apex:panelGrid columns="7">
<apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page"/>
<apex:outputText >{!(pageNumber * size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText>
<apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
<apex:outputPanel style="color:#4AA02C;font-weight:bold">
<apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
</apex:outputPanel>
</apex:panelGrid>
</apex:pageBlock>
</apex:form>
The issue here is likely because the Profile of the user who you are logged in as does not have access to any of the fields on the Well__c object.
VF pages, when using <apex:outputField /> bindings, enforces field level security and will hide the fields which the user does not have access to.
If you look at field level security for this object, I suspect you will find that your profile does not have access to any of the fields which you're using in the columns. Security on the Modem__c object has probably been set correctly for its fields.

Unable to save image in salesforce

I'm trying to save and display a image for each contact individually. I was able to save the image successfully at respective contact. But, when i refreshed the page the photo i have attached is not displaying.
Here is the code:
<apex:page standardController="Contact" extensions="photo_attachmentcls">
<apex:pageBlock >
<apex:form >
<apex:inputFile value="{!attach}" fileName="{!fileName}"></apex:inputFile>
<apex:commandButton value="Load" action="{!loader}" />
<apex:actionSupport event="onchange" />
</apex:form>
<apex:outputPanel id="iidd1">
<img id="theImage" src="/servlet/servlet.FileDownload?file={!dsa}" width="100" height="100" />
</apex:outputPanel>
</apex:pageBlock>
</apex:page>
public class photo_attachmentcls {
public Attachment asd{get;set;}
public string purl{get;set;}
public blob attach{get;set;}
public String fileName{get;set;}
public Id recId{get;set;}
public String dsa {get;set;}
public photo_attachmentcls(ApexPages.StandardController ctrl) {
recId = ApexPages.currentPage().getParameters().get('id');
asd = new Attachment();
}
public void loader()
{
asd.body = attach;
asd.Name = fileName;
asd.ParentId = recId;
insert asd;
system.debug('nnnn'+asd);
dsa = asd.id;
system.debug('ddddd'+dsa);
}
}
Thanks in Advance.
You need to check for the existence of the attachment for that record when the page loads:
public class photo_attachmentcls {
public Attachment asd{get;set;}
public string purl{get;set;}
public blob attach{get;set;}
public String fileName{get;set;}
public Id recId{get;set;}
public String dsa {get;set;}
public photo_attachmentcls(ApexPages.StandardController ctrl) {
recId = ApexPages.currentPage().getParameters().get('id');
// check if the contact already has an attachment:
Contact thisRecord = [select id, (Select Id From NotesAndAttachments) from Contact where Id =: recId];
if(!thisRecord.NotesAndAttachments.isEmpty()){
dsa = thisRecord.NotesAndAttachments[0].Id;
} else{
asd = new Attachment();
}
}
public void loader()
{
asd.body = attach;
asd.Name = fileName;
asd.ParentId = recId;
insert asd;
system.debug('nnnn'+asd);
dsa = asd.id;
system.debug('ddddd'+dsa);
}
}
I'll recommend to choose better variable names as well, but I recognize is a prototype of some sort.

Salesforce - cant pass visualforce inputtext values to apex class

I have the following Visualforce page, and apex class as controller.
I would like to pass valus in the input text boxes contain th ids inputText1 and InputText2 to the same variable in the following apex class.
Everytime, the inputText1 and inputText2 in the apex class is null, and I don't know why!
Iv'e bin sitting on it all day long, and I couldn't figgure out why it happens!
Please help me with that, because I'm feeling hopeless with that.
<apex:page controller="LoginPages" rendered="true" showHeader="false" sidebar="false" standardStylesheets="true">
<apex:Pagemessages id="msg"/>
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlock >
<apex:form >
<p><b>Login Page</b><br /></p>
<apex:panelGrid columns="2" style="margin-top:1em;">
<p><b>UserName</b><br />
<apex:inputtext required="true" id="inputText1" value="{!inputText1}"/>
</p>
<p><b>Password</b><br />
<apex:inputtext id="inputText2" value="{!inputText2}"/>
</p>
<apex:commandButton action="{!loginUser}" value="login" id="login" immediate="true"/>
</apex:panelGrid>
</apex:form>
</apex:pageBlock>
</apex:page>
public class LoginPages{
public String inputText1;
public String inputText2;
public String getInputText1(){
return inputText1;
}
public void setInputText1(String str1){
inputText1 = str1;
}
public String getInputText2(){
return inputText2;
}
public void setInputText2(String str2){
inputText1 = str2;
}
public PageReference registerUser() {
PageReference newPage = new PageReference('/apex/newPage');
newPage.setRedirect(true);
return newPage;
}
public void loginUser() {
ApexPages.Message mymsg = new ApexPages.Message(ApexPAges.Severity.INFO, 'sdsdf' + inputText1);
apexpages.addMessage(mymsg);
// PageReference newPage = new PageReference('/apex/login');
System.debug('sdfsdf' + inputText1);
List<User__c> users = [Select Name, Password__c from User__c Where Name = :inputText1];
if (users.size() > 0){
for (User__c user : users){
if (user.Password__c == inputText2){
//newPage.setAnchor('/apex/catalog');
//newPage.setRedirect(true);
}
}
}
//return newPage;
}
}
Remove immediate="true". "Immediate" results in no data being passed from the form to the server.
Also - you could write your variables bit simpler and then you won't need the explicit getXYZ/setXYZ methods:
public String inputText1 {get;set;}

Failing to alter the options using radio button

<!--Visual force page code-->
<apex:page controller="prgrm9cls"><apex:form >
<apex:pageBlock >
<apex:pageblockSection >
<apex:selectRadio value="{!paymentstatus}" id="paymentstatus">
<apex:selectOption itemValue="Credit" itemLabel="credit card" ></apex:selectOption>
<apex:selectOption itemValue="Po" itemLabel="PO"></apex:selectOption>
<apex:selectOption itemValue="Invoice" itemLabel="Invoice"></apex:selectOption>
<apex:actionSupport event="onchange" reRender="opid2" action="{!act}"/></apex:selectRadio></apex:pageblockSection>
<apex:pageBlockSection >
<apex:outputPanel id="opid2">
<apex:pageBlockSection rendered="{!cardz}" columns="1">
<apex:pageblockSectionItem >
<apex:outputLabel value="Credit Card Name"></apex:outputLabel><apex:inputText value="{!creditname}" />
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="Credit CardNumber"></apex:outputLabel><apex:inputText value="{!CardNumber}" />
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="CVV"></apex:outputLabel><apex:inputText value="{!CVV}" />
</apex:pageblockSectionItem></apex:pageBlockSection>
<apex:pageBlockSection rendered="{!invoicess}">
<apex:outputLabel value="Invoice"></apex:outputLabel><apex:inputText value="{!Invoice}" />
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!pozz}">
<apex:outputLabel value="Routing Number"></apex:outputLabel><apex:inputText value="{!porder}" required="true"/></apex:pageBlockSection></apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form></apex:page>
public class prgrm9cls {
public String CVV { get; set; }
public Integer CardNumber { get; set; }
public String creditname { get; set; }
public String porder { get; set; }
public boolean pozz { get; set; }
public String paymentstatus { get; set; }
public String Invoice { get; set; }
public boolean invoicess { get; set; }
public boolean cardz { get; set; }
public PageReference act() {
if(paymentstatus == 'Credit'){
cardz = true;
invoicess = false;
pozz = false;
}
if(paymentstatus == 'Invoice'){
cardz = false;
invoicess =true;
pozz = false;
}
if(paymentstatus == 'po'){
cardz = false;
invoicess =false;
pozz = true;
}
return null;
}
}
When i click on either one of the radio option then it should display it's relevant text. It was executing only for first two times and failing to work continously.
Can any one explain the mistake have done
Thanks in advance.
Sorry, i figured out the error. It is causing due the usage of 'Required' option in the panel. Removed that option at 'Routing Number'
<apex:outputLabel value="Routing Number"></apex:outputLabel><apex:inputText value="{!porder}" required="true"/>
which has resolved the issue.
Thanks,
Ravindra,
Salesforce Engineer.

Resources