• Ashish_Borate
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies

Hi,

 

I just want to send a single mail with an attachment, I have written something like this

Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
        String toAddresses = 'ashishborate@xyz.com';
        List<String> addr = new List<String>();
        addr.add(toAddresses);
        String subject ='Account CSV';
        email.setToAddresses(addr);
        email.setSubject(subject);
        email.setPlainTextBody('Account CSV');
        email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
        email.emailPriority='low';
        System.debug('Sending Email @@ '+email);
        Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        System.debug('SendEmailResult @@ '+r);

 Where, debug gives me, but I am not getting any mail. Kindly help.

SendEmailResult @@(Messaging.SendEmailResult[getErrors=();isSuccess=true;]

 Thanks,

Ashish.

Hi,

 

I wanted to send 3 links to user namely Completed, In Progress and Skipped through an email.  On click of which I want to capture them and run an Email service on that basis.

 

How to capture link response in an inbound mail? Please help me out.

 

Thanks In advance.

public PageReference finish() {
     
          String lastres;
          ID lastid;
          rs=[select Name,Id from Resource__c];
          List<String> reslist=new List<String>();
        for(Integer i=0;i<rs.size();i++)
          {
                reslist.add(rs[i].Name);
          }
          reslist.sort();
          lastres=reslist[reslist.size()-1];
          List<Resource__c> resource=new List<Resource__c>();
          resource= Database.query('select Employee__r.Name__c,Start_Date_on_SF__c,prevDate__​c,Training_Plan__r.Unselected__c,Training_Batch__r​.Training_Plan__r.Unselected__c,Id,Name,Training_B​atch__r.Name,Training_Batch__r.Training_Plan__r.Na​me,Training_Plan__r.Name,Training_Batch__c,Trainin​g_Plan__c from Resource__c where Name=:lastres');
         System.debug('Resource Name is'+resource[0].Employee__r.Name__c+'.........');
          lastid=resource[0].Id;
          resourceName=resource[0].Name;
          Date SF_StartDate=Date.valueof(resource[0].Start_Date_o​n_SF__c);
          lastTrainingPlan=resource[0].Training_Batch__r.Tra​ining_Plan__r.Name;
          lastTrainingBatch=resource[0].Training_Batch__r.Na​me;
 
      if(lastTrainingBatch==null)
      {
       pl=resource[0].Training_Plan__r.Name;
       unselectSub= resource[0].Training_Plan__r.Unselected__c;
      }
      else
      {
      pl=lastTrainingPlan;
      unselectSub= resource[0].Training_Batch__r.Training_Plan__r.Uns​elected__c;
      }
   

      //    unselectSub= resource[0].Training_Batch__r.Training_Plan__r.Uns​elected__c;
          finalone=new List<String>();
          if(unselectSub!=Null)
          finalone=unselectSub.split('/',100);
         
          List<Training_Plan_Module__c> mdle=new List<Training_Plan_Module__c>();
          mdle=Database.query('select Module__r.Name,Module__r.Name__c from Training_Plan_Module__c where Training_Plan__r.Name=:pl order by  Module__r.Name');

         for(Integer i=0;i<mdle.size();i++)
         {
        
             List<Submodule__c> submodule=new List<Submodule__c>();
             List<String> temp1=new List<String>();
            
             kt=mdle[i].Module__r.Name;
          
                submodule=Database.query('select Name,Hours__c,ID from Submodule__c where Module__r.Name=:kt');
                for(Integer j=0;j<submodule.size();j++)
                {
                    chk=0;
                    if(unselectSub!=Null)
                    {
                      for(Integer k=0;k<finalone.size();k++)
                     {
                          
                     if(finalone[k]==submodule[j].Name)
                     {
                             chk=1;
                      
                     }
                     }
                     }
                    
                         if(chk==0)
                         {
                                 Resource_Tracker__c Re=new Resource_Tracker__c();
                                 Re.Resource__c=lastid;          
                                 Re.Submodule__c=submodule[j].id;
                                 insert re;
                         }
                }
             }
        
         startDate=NULL;
         List<Resource_Tracker__c> addmilestone =new List<Resource_Tracker__c>();
        addmilestone=Database.query('select Submodule__r.Name__c, Expected_Finish_Date__c,Submodule__r.Hours__c, Submodule__r.Module__r.Name__c FROM Resource_Tracker__c where Resource__r.Name=:lastres order by Submodule__r.Module__c'); 
         startDate=SF_StartDate;
         AllTotal=0;
        
         for(Integer i=0;i<addmilestone.size();i++)
         {
         hrs=8;
         AllTotal=AllTotal+Double.ValueOf(addmilestone[i].S​ubmodule__r.Hours__c);
    
         if(givemeday(startDate)==6||givemeday(startDate)==​7||isholiday(startDate)==true)
        {
            startDate=startDate+1;
            i--;
            continue;
        }
        else
        {
        Double capturedHrs=isSpecialCase(startDate);
           if(capturedHrs != null)
            {
                hrs=capturedHrs;  
            }

       
            if(AllTotal>hrs)
            {
                AllTotal=Alltotal-hrs;
                startDate=startDate+1;
            }
        
        }
          while(true)
        {
         if(givemeday(startDate)==6||givemeday(startDate)==​7||isholiday(startDate)==true)
        {
        startDate+=1;
        }
        else
        break;
        }
          addmilestone[i].Expected_Finish_Date__c=startDate;
           upsert addmilestone;
         
   
    }
  String str=ApexPages.currentPage().getParameters().get('n​amefield');
    System.debug('Str Value is.... '+str);
  List<Date> dat = populatedata1(str);
     resource[0].prevDate__c = dat[0];
     System.debug('Date Value is.... '+dat[0]);

           upsert resource; 
        Pagereference ref=new PageReference('/apex/crudResource');
        ref.setRedirect(true);
        return ref;
    }

       

////////////////////////////Test Method//////////////////

static testMethod void verifyFinish()
    {
        Employee__c emp = new Employee__c();
        Training_Plan__c plan = new Training_Plan__c();
        Training_Batch__c batch = new Training_Batch__c();       
        Training_Plan_Module__c planmodule = new Training_Plan_Module__c();
        Module__c mod = new Module__c();
        Submodule__c sub = new Submodule__c();

       

        mod.Name__c='module1';
        insert mod;

        sub.Hours__c=double.valueOf('3.0');
        sub.Name__c = 'submodule1';
        sub.link__c = 'http://www.salesfoce.com';
        sub.Module__c=mod.id;
        insert sub;
               
        emp.Name__c = 'employee';
        emp.Email_ID__c = 'emp1@abc.com';
       
        insert emp;
       
        plan.Name__c = 'plan1';
        plan.Selected_hours__c = double.valueOf('3.0');
        plan.Unselected__c='SM-00001/SM-00002/SM-00003/SM-​00005/';
        insert plan;
       
             List<Training_Plan_Module__c> module=new List<Training_Plan_Module__c>();
        module=Database.query('select Module__r.Name,Module__r.Name__c,Training_Plan__c from Training_Plan_Module__c where Training_Plan__r.Name__c=:');*/
        planmodule.Module__c=mod.id;
        planmodule.Training_Plan__c=plan.id;
        insert planmodule;
       
        batch.Name__c = 'batch1';
        batch.Start_Date__c = System.today();
        batch.Training_Plan__c=plan.id;
        insert batch;
       
        ResourceNextController rcc=new ResourceNextController();

        Resource__c Res = new Resource__c();
        Res.Resource_Status__c='status';
        Res.Employee__c = emp.id;
        Res.Assessment__c='assessment';
        Res.Training_Plan__c=plan.id;
        Res.Training_Batch__c=batch.id;
        Res.Billed__c = 3;
        Res.Billing_Project__c = 'SFDC';
        Res.Work_Project__c = 'CMS';
        Res.EarMarked__c = 'yes';
        Res.Start_Date_on_SF__c = system.today();
        Res.prevDate__c = system.today();
        insert Res;

                Special_Case__c SC=new Special_Case__c();
                SC.New_Start_Date__c = system.today();
                SC.New_End_Date__c = system.today()+30;
                SC.New_Hours__c = double.valueOf('3');
                SC.EmpId__c=rcc.Res.id;
                insert SC;

            //    rcc.savenew();
        String nextPage;
        PageReference pageref = Page.ResourceNext;


        pageref.getParameters().put('namefield',Res.Name);
        Test.setCurrentPage(pageref);
        
        Prior_two_days_Mail1 ptd = new Prior_two_days_Mail1();
        ptd.populateData1(Res.Name);
       
        ResourceNextController controlle = new ResourceNextController();
        controlle.changePlanResource=rcc.res.employee__r.N​ame+'['+Res.Name+']';
        controlle.lastTrainingPlan=plan.Name;
   
        controlle.finish();
    

    }

 

 Here in test method value of 'namefield' is not getting set, hence not calling the populatedata1(). I did some R&D, Why this is happening but couldnt end up on one proper solution. It would be so grateful for me if you could help. Please help me out.

Hi,

 

I just want to send a single mail with an attachment, I have written something like this

Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
        String toAddresses = 'ashishborate@xyz.com';
        List<String> addr = new List<String>();
        addr.add(toAddresses);
        String subject ='Account CSV';
        email.setToAddresses(addr);
        email.setSubject(subject);
        email.setPlainTextBody('Account CSV');
        email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
        email.emailPriority='low';
        System.debug('Sending Email @@ '+email);
        Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
        System.debug('SendEmailResult @@ '+r);

 Where, debug gives me, but I am not getting any mail. Kindly help.

SendEmailResult @@(Messaging.SendEmailResult[getErrors=();isSuccess=true;]

 Thanks,

Ashish.