You need to sign in to do that
Don't have an account?
teja swi 10
How can i send a mail attachment pdf when i clicked on a button using parameters passing in the url
This is my code .... I created a button in Vf when i click on that button my page should convert in to pdf and send a mail with that pdf for that i have written below code ... but my problem is how can i give values to the page , my page name is Stre
public void sendpdf()
{
string cname = ApexPages.currentPage().getParameters().get('pId');
string dname = ApexPages.currentPage().getParameters().get('cId');
string ename = ApexPages.currentPage().getParameters().get('chId');
string fname = ApexPages.currentPage().getParameters().get('chstnum');
string gname = ApexPages.currentPage().getParameters().get('chendnum');
string hname = ApexPages.currentPage().getParameters().get('commamount');
string iname = ApexPages.currentPage().getParameters().get('pcreated');
string jname = ApexPages.currentPage().getParameters().get('pcfailed');
string kname = ApexPages.currentPage().getParameters().get('totalcom');
Messaging.SingleEmailMessage email1=new Messaging.SingleEmailMessage();
String[] toadd=new string[]{'teja.sfdc99@gmail.com'};
email1.setToAddresses(toadd);
pageReference p=page.Stre;
Blob b=p.getContentAsPdf();
Messaging.EmailFileAttachment ef=new Messaging.EmailFileAttachment();
ef.SetFileName('Check Run PDF');
ef.SetBody(b);
Messaging.EmailFileAttachment[] attachments=new Messaging.EmailFileAttachment[]{ef};
email1.setFileAttachments(attachments);
email1.setSubject('PDF Attachment');
email1.SetPlainTextBody('This is sample test PDF');
Messaging.Email[] emails=new Messaging.Email[]{email1};
Messaging.SendEmail(emails);
}
sample page with parametes is https://c.cs1.visual.force.com/apex/Stre?pId=Phoenix%20Health%20Plans%20(Formerly%20Abrazo)&cId=14/03/2015&chId=369175.0&chstnum=22912&chendnum=22949&commamount=369175.0&pcreated=3240&pcfailed=399&totalcom=4324
how can i pass this in my code please tell me i have taken the values as strings in the code but how can i pass it in pageReference p=page.Stre?.......
please help me with this
public void sendpdf()
{
string cname = ApexPages.currentPage().getParameters().get('pId');
string dname = ApexPages.currentPage().getParameters().get('cId');
string ename = ApexPages.currentPage().getParameters().get('chId');
string fname = ApexPages.currentPage().getParameters().get('chstnum');
string gname = ApexPages.currentPage().getParameters().get('chendnum');
string hname = ApexPages.currentPage().getParameters().get('commamount');
string iname = ApexPages.currentPage().getParameters().get('pcreated');
string jname = ApexPages.currentPage().getParameters().get('pcfailed');
string kname = ApexPages.currentPage().getParameters().get('totalcom');
Messaging.SingleEmailMessage email1=new Messaging.SingleEmailMessage();
String[] toadd=new string[]{'teja.sfdc99@gmail.com'};
email1.setToAddresses(toadd);
pageReference p=page.Stre;
Blob b=p.getContentAsPdf();
Messaging.EmailFileAttachment ef=new Messaging.EmailFileAttachment();
ef.SetFileName('Check Run PDF');
ef.SetBody(b);
Messaging.EmailFileAttachment[] attachments=new Messaging.EmailFileAttachment[]{ef};
email1.setFileAttachments(attachments);
email1.setSubject('PDF Attachment');
email1.SetPlainTextBody('This is sample test PDF');
Messaging.Email[] emails=new Messaging.Email[]{email1};
Messaging.SendEmail(emails);
}
sample page with parametes is https://c.cs1.visual.force.com/apex/Stre?pId=Phoenix%20Health%20Plans%20(Formerly%20Abrazo)&cId=14/03/2015&chId=369175.0&chstnum=22912&chendnum=22949&commamount=369175.0&pcreated=3240&pcfailed=399&totalcom=4324
how can i pass this in my code please tell me i have taken the values as strings in the code but how can i pass it in pageReference p=page.Stre?.......
please help me with this
try this:
public void sendpdf()
{
string cname = ApexPages.currentPage().getParameters().get('pId');
string dname = ApexPages.currentPage().getParameters().get('cId');
string ename = ApexPages.currentPage().getParameters().get('chId');
string fname = ApexPages.currentPage().getParameters().get('chstnum');
string gname = ApexPages.currentPage().getParameters().get('chendnum');
string hname = ApexPages.currentPage().getParameters().get('commamount');
string iname = ApexPages.currentPage().getParameters().get('pcreated');
string jname = ApexPages.currentPage().getParameters().get('pcfailed');
string kname = ApexPages.currentPage().getParameters().get('totalcom');
Messaging.SingleEmailMessage email1=new Messaging.SingleEmailMessage();
String[] toadd=new string[]{'teja.sfdc99@gmail.com'};
email1.setToAddresses(toadd);
pageReference p=page.Stre;
p.getParameters().put('pId','cname');
p.getParameters().put('cId','dname');
p.getParameters().put('chId','ename');
p.getParameters().put('chstnum','fname');
p.getParameters().put('chendnum','gname');
p.getParameters().put('commamount','hname');
p.getParameters().put('pcreated','iname');
p.getParameters().put('pcfailed','jname');
p.getParameters().put('totalcom','kname');
Blob b=p.getContentAsPdf();
Messaging.EmailFileAttachment ef=new Messaging.EmailFileAttachment();
ef.SetFileName('Check Run PDF');
ef.SetBody(b);
Messaging.EmailFileAttachment[] attachments=new Messaging.EmailFileAttachment[]{ef};
email1.setFileAttachments(attachments);
email1.setSubject('PDF Attachment');
email1.SetPlainTextBody('This is sample test PDF');
Messaging.Email[] emails=new Messaging.Email[]{email1};
Messaging.SendEmail(emails);
}
https://developer.salesforce.com/forums/?id=906F000000091kCIAQ
Try to degrade the Apex Class version to 25 and see, if it solves your problem.
If not, take backup of the class, delete the old class and try to create a new class in version 25 directly and paste the code, see if it solves your problem.
Steps - Navigate to Apex Class -> click on "Version Settings" tab and choose 'version' 25.
T hanks,
Sumit KumarSingh
VF Page:-
<apex:page controller="salesfor">
<apex:form id="sf">
<apex:pageBlock >
<apex:pageblockSection title="Send Mail through SalesForce">
<apex:outputLabel value="Send to"/>
<apex:inputText value="{!sendto}"/>
<apex:outputLabel value="Subject"/>
<apex:inputText value="{!subject}"/>
<apex:outputLabel value="Body"/>
<apex:inputTextarea value="{!body}"/>
<apex:inputFile value="{!attbody}" fileName="{!attfile}" />
<apex:commandButton value="Attach & Send" action="{!upload}" reRender="sf"/>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex:-
public class salesfor
{
public string subject{get;set;}
public string body{get;set;}
public blob attbody{get;set;}
public string attfile{get;set;}
public string sendto{get;set;}
public pagereference upload ()
{
Messaging.SingleEmailMessage em = new Messaging.SingleEmailMessage();
String[] s = new String[]{subject};
em.setSubject('Sample');
em.setToAddresses(s);
em.setPlainTextBody('Sending Mail thru Salesforce');
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(attfile);
efa.setBody(attbody);
em.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
Messaging.sendEmailResult[] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {em});
return null;
}
}
Could you please anyone help me out. I am getting error like " apex:inputFile can not be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute "