You need to sign in to do that
Don't have an account?
Vikram Singh 157
Hi ! Related to Future Method and callout
I am just practice the use of future method and callout but the below code is'nt working
global class MyFutureClass {
@future
public static void myMethod() {
EmailClass.SendEmailNotification();
}
}
global class EmailClass{
WebService static void SendEmailNotification() {
SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new string[] {'vikramsinghvs099@gmail.com'});
mail.setSenderDisplayName('SFDC.com ');
mail.setSubject('A new Hope'');
mail.setHtmlBody('GoT It ?');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );
}
}
global class MyFutureClass {
@future
public static void myMethod() {
EmailClass.SendEmailNotification();
}
}
global class EmailClass{
WebService static void SendEmailNotification() {
SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new string[] {'vikramsinghvs099@gmail.com'});
mail.setSenderDisplayName('SFDC.com ');
mail.setSubject('A new Hope'');
mail.setHtmlBody('GoT It ?');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );
}
}
Please save both class in dfferent apex class as below. Please let me know if it helps you.
// Please save as different apex class with Name 'MyFutureClass'
global class MyFutureClass {
@future
global static void myMethod() {
EmailClass.SendEmailNotification();
}
}
// Please save as different apex class with Name 'EmailClass'
global class EmailClass{
global static void SendEmailNotification() {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new string[] {'vikramsinghvs099@gmail.com'});
mail.setSenderDisplayName('SFDC.com ');
mail.setSubject('A new Hope');
mail.setHtmlBody('GoT It ?');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );
}
}
Regards,
Pawan Kumar
All Answers
If you want to send email using future method then you can simply replace "WebService" with Public. You no need to do callout here. Please let me know if it helps you.
Regards,
Pawan Kumar
Please save both class in dfferent apex class as below. Please let me know if it helps you.
// Please save as different apex class with Name 'MyFutureClass'
global class MyFutureClass {
@future
global static void myMethod() {
EmailClass.SendEmailNotification();
}
}
// Please save as different apex class with Name 'EmailClass'
global class EmailClass{
global static void SendEmailNotification() {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new string[] {'vikramsinghvs099@gmail.com'});
mail.setSenderDisplayName('SFDC.com ');
mail.setSubject('A new Hope');
mail.setHtmlBody('GoT It ?');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );
}
}
Regards,
Pawan Kumar
It will get saved successfully now do i need to call it separatly through anonumous window or get execute automatically .
Acually there is a confusion ..
MyFutureClass.myMethod();
You can call your method inside:
1. Trigger
2. Process Builder
You can complete below trailhead as well to get complete understanding
https://trailhead.salesforce.com/en/modules/asynchronous_apex/units/async_apex_future_methods
Regards,
Pawan Kumar