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
anillllanillll 

Test Coverage for the controller class

  public class MyAccountListCntrlr {
 2	  
 3	  
 4	       // PROPERTIES
 5	        public String subject { get; set; }
 6	        public String body { get; set; }
 7	        public string ccaddress{set;get;}
 8	        public string bccaddress{set;get;}
 9	    
 10	       public List<ContactWrapperCls> acctList {get;set;}
 11	       public List<String> selAccountNames{get;set;}
 12	       public Boolean hasSelAcct {get;set;}
 13	       public final Deal__c opp;
 14	       public task t = new task();
 15	       // CONSTRUCTOR
 16	       public MyAccountListCntrlr(ApexPages.StandardController controller){
 17	       try
 18	       {
 19	            acctList = new List<ContactWrapperCls>();
 20	            selAccountNames= new List<String>();
 21	            opp = [SELECT Name,id,Account__c FROM Deal__c
 22	                     WHERE Id = :controller.getRecord().id];
 23	                     system.debug('opportunity@@@@@@@@@@'+opp);                  
 24	  
 25	          for(Contact a : [SELECT Name,id,Email,Account.Name,Account.Id FROM Contact where Account.id=:opp.Account__c ]){
 26	                 acctList.add(new ContactWrapperCls(a));
 27	              Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:opp.Account__c];
 28	            } 
 29	  
 30	       }
 31	  
 32	  catch(Exception e)
 33	  {
 34	  system.debug(e);
 35	  }
 36	  }
 37	       // METHODS
 38	       public void displaySelectedAccountNumbers(){
 39	            selAccountNames.clear();
 40	            hasSelAcct = false;
 41	            for(ContactWrapperCls cWrapper : acctList){
 42	                 if(cWrapper.isSelected){
 43	                      hasSelAcct = true;
 44	                      selAccountNames.add(cWrapper.cContact.Email);
 45	                 }
 46	            }
 47	       }
 48	     
 49	        public PageReference send() {
 50	       
 51	        try
 52	        {
 53	       // Define the email 
 54	          Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
 55	          
 56	       // Reference the attachment page and pass in the OpportunityID
 57	          PageReference pdf =  Page.Quotation;
 58	          pdf.getParameters().put('id',(String)opp.id); 
 59	          pdf.setRedirect(true);
 60	  
 61	       // Take the PDF content
 62	          Blob b = pdf.getContent();
 63	           Attachment myAttach = new Attachment();
 64	              myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
 65	              System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
 66	              List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
 67	              Integer c=at.size()+1;
 68	              myAttach.name =opp.Name +''+ 'License Version' + c +'.pdf';
 69	                 myAttach.body = b;
 70	                insert myAttach;
 71	             
 72	  
 73	       // Create the email attachment
 74	          Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
 75	          efa.setFileName(myAttach.name);
 76	          efa.setBody(b);
 77	  
 78	          String[] ccAddresses = new String[] {ccaddress};
 79	          String[] bccAddresses = new String[] {'emailtosalesforce@28wj1f7u1jx4d0rk7syg098pe8grkt8ir75tm5j0vhveterlrr.z-87epmai.z.le.sandbox.salesforce.com'};
 80	          String addresses;
 81	       /*   if (con[0].Email != null) {
 82	         
 83	              address = con[0].Email;
 84	              // Loop through the whole list of contacts and their emails 
 85	      
 86	              for (Integer i = 1; i <con.size(); i++) {
 87	                  if (con[i].Email != null) {
 88	                      address += ':' + con[i].Email;
 89	                  }
 90	              }
 91	          }*/
 92	        //  addresses = con.Email;
 93	          String[] toAddresses = selAccountNames;
 94	          
 95	         
 96	          
 97	      
 98	       // Sets the paramaters of the email 
 99	          email.setSubject( subject );
 100	          email.setToAddresses( toAddresses );
 101	              
 102	      string UserId = UserInfo.getUserId();
 103	      User user = [select email, IsActive from User where id = :UserId];
 104	          
 105	  
 106	          
 107	       //email.setCcAddresses(toAddresses);
 108	       //email.setBccAddresses(bccaddress);
 109	          email.setReplyTo(user.email);
 110	          email.setBccSender(true);
 111	          email.setHtmlBody(body);
 112	          email.setSenderDisplayName('Salesforce');
 113	          email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); 
 114	          
 115	          // Sends the email 
 116	          Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
 117	  
 118	          t.subject ='Email:'+myAttach.name+ subject;
 119	          t.status = 'Completed';
 120	          t.description = body;
 121	          t.type =  'Email';
 122	          t.ActivityDate = System.today();
 123	          t.Whatid=opp.id;
 124	  
 125	          insert t;
 126	           }
 127	  catch(Exception e)
 128	  {
 129	  System.debug(e);
 130	  }   
 131	          //PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
 132	          PageReference pr = new PageReference('/'+ ApexPages.currentPage().getParameters().get('id'));
 133	        
 134	          pr.setRedirect(true);
 135	        
 136	          System.debug('Inside back');
 137	          return pr;
 138	          
 139	          //return null;
 140	         }
 141	  
 142	  public class ContactWrapperCls {
 143	       public Boolean isSelected {get;set;}
 144	       public Contact cContact {get;set;}
 145	  
 146	       public ContactWrapperCls(Contact cContact){
 147	            this.cContact = cContact;
 148	       }
 149	  }
 150	   public  static testMethod void testMyAccountListCntrlr() {
 151	       Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
 152	    
 153	   User U = new User(Alias = 'TUser1', Email='testItemaster1@im.com',EmailEncodingKey='UTF-8',
 154	     LastName='TestingAcc1', LanguageLocaleKey='en_US',LocaleSidKey='en_US', ProfileId =p.Id,
 155	     TimeZoneSidKey='America/Los_Angeles', UserName='testacc1@test.com');   
 156	   insert U;
 157	    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
 158	     Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
 159	    
 160	          Account acc=new Account(Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india');
 161	          insert acc;
 162	           system.debug('########555'+ acc);
 163	      
 164	      Contact con =  new Contact();
 165	      con.FirstName = 'Anil';
 166	      con.LastName = 'Dutt';
 167	      con.AccountID=acc.id;
 168	      con.Email = 'anil@swiftsetup.com';
 169	      insert con;
 170	  
 171	        Deal__c opp=new Deal__c(Name='test12',Account__c=acc.id);
 172	          insert opp;
 173	          ID id = opp.id;
 174	           task t=new task(subject ='hfhfg',status='completed',type='email',ActivityDate = System.today(),Whatid=opp.id);
 175	          insert t;
 176	    
 177	       
 178	     MyAccountListCntrlr myAcc= new MyAccountListCntrlr(new ApexPages.StandardController(opp));   
 179	       
 180	       
 181	   
 182	       
 183	          PageReference pageRef = Page.Quotation;
 184	          pageRef.getParameters().put('id', String.valueOf(opp.Id));
 185	          Test.setCurrentPage(pageRef);
 186	          Blob b;
 187	        
 188	          Attachment myAttach = new Attachment();
 189	          myAttach.ParentId =opp.id;
 190	          myAttach.name = 'Quotation.pdf';
 191	          myAttach.body = blob.valueof('test');
 192	           
 193	          insert myAttach; 
 194	           myacc.send();
 195	         
 196	          
 197	        
 198	     
 199	          //myAcc.displaySelectedAccountNumbers();
 200	          
 201	          
 202	  }
 203	  }

     

     

8    public void displaySelectedAccountNumbers(){  39    selAccountNames.clear();  40    hasSelAcct = false;  41    for(ContactWrapperCls cWrapper : acctList){  42    if(cWrapper.isSelected){  43    hasSelAcct = true;  44    selAccountNames.add(cWrapper.cContact.Email);

 

    

Attachment myAttach = new Attachment();  64    myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');  65    System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));  66    List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];  67    Integer c=at.size()+1;  68    myAttach.name =opp.Name +''+ 'License Version' + c +'.pdf';  69    myAttach.body = b;  70    insert myAttach;  71     72     73    // Create the email attachment  74    Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();  75    efa.setFileName(myAttach.name);  76    efa.setBody(b);  77     78    String[] ccAddresses = new String[] {ccaddress};  79    String[] bccAddresses = new String[] {'emailtosalesforce@28wj1f7u1jx4d0rk7syg098pe8grkt8ir75tm5j0vhveterlrr.z-87epmai.z.le.sandbox.salesforce.com'}; 80

   String addresses;

 

 

 

 

   

String[] toAddresses = selAccountNames;  94     95     96     97     98    // Sets the paramaters of the email  99    email.setSubject( subject );  100    email.setToAddresses( toAddresses );  101     102    string UserId = UserInfo.getUserId();  103    User user = [select email, IsActive from User where id = :UserId];  104     105     106     107    //email.setCcAddresses(toAddresses);  108    //email.setBccAddresses(bccaddress);  109    email.setReplyTo(user.email);  110    email.setBccSender(true);  111    email.setHtmlBody(body);  112    email.setSenderDisplayName('Salesforce');  113    email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});  114     115    // Sends the email  116    Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});  117     118    t.subject ='Email:'+myAttach.name+ subject;  119    t.status = 'Completed';  120    t.description = body;  121    t.type = 'Email';  122    t.ActivityDate = System.today();  123    t.Whatid=opp.id;  124    125

   insert t;

 

 

 

     These three methods are not covered ,,please help me in this

 

Thanks in advance