function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Raju kanoperiRaju kanoperi 

Hi ,Hello

Hi , in visualforce page  subject , mobile, email fields are present. in email field what ever the mail id given that mail has to go that perticular mail after clicking the submit button  please provide code .
for example in vf page email field= abc@co.in given after clicking the submit button that mail has sent to abc@co.in


thanks
raju


 
Best Answer chosen by Raju kanoperi
SandhyaSandhya (Salesforce Developers) 
Hi,

Please refer below sample code.
 
<apex:page controller="Task35Controller">
 <apex:form >
 <apex:PageBlock >
 <apex:PageBlockSection >
 <apex:PageBlockSectionItem >
 <apex:outputLabel >Subject</apex:outputLabel>
  <apex:inputField value="{!st.Description}"/>
  </apex:PageBlockSectionItem>
  <apex:PageBlockSectionItem >
 <apex:outputLabel >Email</apex:outputLabel>
  <apex:inputText value="{!Email}"/>
  </apex:PageBlockSectionItem>

 </apex:PageBlockSection>
 <apex:PageBlockButtons >
  <apex:commandButton value="sendEmail" action="{!sendEmail}"/>
 </apex:PageBlockButtons>
 </apex:PageBlock>
 </apex:form>
</apex:page>
 
public class Task35Controller {
public lead st{set;get;}
public string subject{set;get;}
public string Email{set;get;}
public Task35Controller()
{

st= new lead();
     list <lead> l= [select Description, ID from Lead where id = :ApexPages.currentPage().getParameters().get('id')];
     
      subject =st.Description;
      system.debug(Email);

}
public PageReference sendEmail()
{
//EmailTemplate templateId = [Select id from EmailTemplate where name ='thanku'];//for text template
//EmailTemplate templateId = [Select id from EmailTemplate where name ='SandhyaTemplate'];// for html template
EmailTemplate templateId = [Select id from EmailTemplate where name ='ContactTemplateVF'];//for visualforcetemplate
System.debug(templateId);
System.debug(UserInfo.getUserId());
Messaging.singleEmailMessage mail= new Messaging.singleEmailMessage();
mail.setTargetObjectId(UserInfo.getUserId());
mail.setTemplateID(templateId.Id);
string[] toaddress= new String[]{Email};
mail.settoaddresses(toaddress);
mail.setSaveAsActivity(false); 
Messaging.sendEmail(new Messaging.singleEmailMessage[]{mail});
return null;
}
}

Hope this helps you!

Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution.
 
Thanks and Regards
Sandhya

 

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

Please refer below sample code.
 
<apex:page controller="Task35Controller">
 <apex:form >
 <apex:PageBlock >
 <apex:PageBlockSection >
 <apex:PageBlockSectionItem >
 <apex:outputLabel >Subject</apex:outputLabel>
  <apex:inputField value="{!st.Description}"/>
  </apex:PageBlockSectionItem>
  <apex:PageBlockSectionItem >
 <apex:outputLabel >Email</apex:outputLabel>
  <apex:inputText value="{!Email}"/>
  </apex:PageBlockSectionItem>

 </apex:PageBlockSection>
 <apex:PageBlockButtons >
  <apex:commandButton value="sendEmail" action="{!sendEmail}"/>
 </apex:PageBlockButtons>
 </apex:PageBlock>
 </apex:form>
</apex:page>
 
public class Task35Controller {
public lead st{set;get;}
public string subject{set;get;}
public string Email{set;get;}
public Task35Controller()
{

st= new lead();
     list <lead> l= [select Description, ID from Lead where id = :ApexPages.currentPage().getParameters().get('id')];
     
      subject =st.Description;
      system.debug(Email);

}
public PageReference sendEmail()
{
//EmailTemplate templateId = [Select id from EmailTemplate where name ='thanku'];//for text template
//EmailTemplate templateId = [Select id from EmailTemplate where name ='SandhyaTemplate'];// for html template
EmailTemplate templateId = [Select id from EmailTemplate where name ='ContactTemplateVF'];//for visualforcetemplate
System.debug(templateId);
System.debug(UserInfo.getUserId());
Messaging.singleEmailMessage mail= new Messaging.singleEmailMessage();
mail.setTargetObjectId(UserInfo.getUserId());
mail.setTemplateID(templateId.Id);
string[] toaddress= new String[]{Email};
mail.settoaddresses(toaddress);
mail.setSaveAsActivity(false); 
Messaging.sendEmail(new Messaging.singleEmailMessage[]{mail});
return null;
}
}

Hope this helps you!

Please mark it as Best Answer if my reply was helpful. It will make it available for other as the proper solution.
 
Thanks and Regards
Sandhya

 
This was selected as the best answer
Raju kanoperiRaju kanoperi
Thank you sandhya for giving a valuable information..


Regards
raju
Raju kanoperiRaju kanoperi
hi sandhya,
   after click on sendmail button am getting error i.e visualforce exception error like that..
SandhyaSandhya (Salesforce Developers) 
Hi,

As its a sample code please make sure you have all the fields and also template ID in your org.

Thanks and Regards
Sandhya
Raju kanoperiRaju kanoperi
Thank you so much sandhya it's working..


regards
raju
Raju kanoperiRaju kanoperi
Hi sandhya,
it is possible to do using visualforce customcomponents and attributes for same scenario .