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
Vikram Singh 157Vikram 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 } );  
   }  
 }  
Best Answer chosen by Vikram Singh 157
PawanKumarPawanKumar
Hi Vikram,

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

PawanKumarPawanKumar
Hi Vikram,
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
Vikram Singh 157Vikram Singh 157
Error: Compile Error: unexpected syntax: 'missing EOF at 'global'' at line 9 column 13
PawanKumarPawanKumar
Hi Vikram,

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
This was selected as the best answer
PawanKumarPawanKumar
Please let me know if above is still not working for you.
Vikram Singh 157Vikram Singh 157
Dear sir,
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 ..
Vikram Singh 157Vikram Singh 157
Thanks I will work thanks A lot .
PawanKumarPawanKumar
If you want to test, you can call below line in execute anonymus.
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