• anillll
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 17
    Replies
I have written this code but its not taking

String phoneNumber = eachMob.Contact_Number_Mobile__c;
        Pattern isnumbers = Pattern.Compile('^[0-9]+$');
           Matcher MobileMatch = isnumbers.matcher(phoneNumber);

             if(MobileMatch.Matches())
  • trigger TaskCreatepromotionmember on Promotion_Member__c (before update) {
    Set<Id> createdByIds = new Set<Id>();
        Set<Id> Managerid=new Set<Id>();
      List<User> lstU2 = [select id,email,TL__c,ManagersId__c from User];
        try
        {
      List<Promotion_Member__c> t2=[select id,Verification_Status__c,Verified__c from Promotion_Member__c WHERE Verification_Status__c='Complaint' LIMIT 1];
        for(User u1:lstU2)
        {
        for(Promotion_Member__c pr:Trigger.New)
        {
            createdByIds.add(pr.createdById);
           Managerid.add(u1.ManagersId__c);
       }
      
       }
        Map<Id, User> userMap = new Map<Id,User>([select Name, Email,ManagersId__c from User where Id in :createdByIds]);
      
        for(Promotion_Member__c eq : Trigger.New)
        {
        Promotion_Member__c beforeUpdate = System.Trigger.oldMap.get(eq.Id);
       
        if(eq.Verification_Status__c=='Complaint' && eq.Verified__c==true && beforeUpdate.Verification_Status__c!= eq.Verification_Status__c)
        {
           
          
              // Promotion_Member__c eq=[select id,Complaint_Remarks__c,Complaints__c,Suggestion__c,Suggestion_Remarks__c,Call_Center_Remarks__c,createdbyId from Promotion_Member__c where id=:tsk.id];
               //system.debug('Enquiry'+eq);
              
               Task Tk = new Task();
               Tk.ownerid = userMap.get(eq.createdById).ManagersId__c;
               Tk.Call_Center_Comments__c=eq.Call_Center_Remarks__c;
               Tk.WhatId=eq.id;
               Tk.Suggestion__c=eq.Suggestion__c;
               Tk.Complaint__c=eq.Complaints__c;
               Tk.ActivityDate=system.today();
               Tk.Priority='Normal';
               Tk.Subject='PromotionMember Complaint';
               insert Tk;
              
               Task Tk1 = new Task();
               Tk1.ownerid =eq.createdbyId;
               Tk1.WhatId=eq.id;
               Tk1.Suggestion__c=eq.Suggestion__c;
               Tk1.Complaint__c=eq.Complaints__c;
               Tk1.ActivityDate=system.today();
               Tk1.Call_Center_Comments__c=eq.Call_Center_Remarks__c;
               Tk1.Priority='Normal';
               Tk1.Subject='PromotionMember Complaint';
               insert Tk1;
              
               }
              
              
              
              
               }
              }Catch(Exception e)
              {}                               
    }
    
    
    
    
    
    
    
    
    @isTest(SeeAllData=True)
    Public Class TestTaskCreatepromotionmemberClass
    {
        Static TestMethod Void Emailpromotion()
        {
            Test.StartTest();
            User lstU2 =[select id,email,TL__c,ManagersId__c from User where profile.Name='BD' LIMIT 1];
            Tour_Program__c tr=new Tour_Program__c();
            tr.From_Date__c=date.newinstance(2014, 3, 1);
            tr.To_Date__c=date.newinstance(2014, 3, 15);
            insert tr;
           
           List<Tour_Plan1__c > TourPlan=new List<Tour_Plan1__c >();
           Tour_Plan1__c tp=new Tour_Plan1__c();
           tp.Name='Tour Palan1234';
           tp.Tour_Program__c=tr.id;
          
           insert tp;
          
        
           Site_Visit__c sv=new Site_Visit__c();
           sv.Tour_Plan1__c=tp.id;
           sv.Architects_Meet_Actuals__c=1;
           sv.Boarers_Meet_Actuals__c=2;
           sv.Builders_Meet_Actuals__c=3;
           sv.Verification_Type__c='Complaint';
           sv.Verified__c=true;
           insert sv;
          
           Promotion__c prm=new Promotion__c();           
                prm.Date__c=System.today();
                prm.Type__c='Dealers Meet';
                prm.Site_Visit__c=sv.id;
                insert prm;
               
          Promotion_Member__c pm=new Promotion_Member__c();
                pm.Verified__c=true;
                pm.Promotions2__c=prm.id;
                pm.Verification_Status__c = 'Complaint';
                pm.Call_Center_Remarks__c='Remarks';
                pm.Call_Status__c='Completed';
              
                insert pm;
                update pm;
               
               
                       
            //Promotion_Member__c pm1= [SELECT id,Verification_Status__c  FROM  Promotion_Member__c WHERE id=:pm.id];
           
            //update pm1;
           
           
            Task Tk1=new task();
               Tk1.ActivityDate=system.today();
               Tk1.Priority='Normal';
               Tk1.Subject='Site Visit Complaint';
               Tk1.whatId=pm.id;
               Tk1.Call_Center_Comments__c='Test';
               Tk1.OwnerId=lstU2.ManagersId__c;
               insert Tk1;
              
            Task Tk2=new task();
               Tk2.ActivityDate=system.today()+2;
               Tk2.Priority='Normal';
               Tk2.Subject='Site Visit Complaint';
               Tk2.whatId=pm.id;
               Tk2.OwnerId=userinfo.getuserid();         
               Tk2.Call_Center_Comments__c='Type';
               insert Tk2;
           
       
        
         Test.StopTest();     
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
I am Using Account and it has 2 Record Types namely Distributor and Dealer.And when user creates Dealer he will choose Distributor from Standard Parent Account Lookup...

And for Distributors records are shared manually , the users who are shared distributors has to view dealers under them automatically./

for ex:i have Distributor called ABC Enterprise and under this distributor it has 60 dealers so when i share ABC distributor to 4 users dealers has to be shared automatically

I have two custom fields Chennai_DC_No__c,Bangalore_DC_No__c and Location__c (picklist) contains Bangalore,Chennai

 

One field is incrementing and another one is not incrementing , every time it display 1.

 

 

 

trigger ChennaiNos on Demo__c (before insert) {
List<Demo__c> OpList = new List<Demo__c>(); 
    OpList=[SELECT Chennai_DC_No__c FROM Demo__c]; 
    for(Demo__c c : Trigger.new){ 
    if(OpList.size() > 0){
                if(c.Location__c!= 'Bangalore'){ 
                  if(OpList[0].Chennai_DC_No__c!= null){                  
                    c.Chennai_DC_No__c =OpList[0].Chennai_DC_No__c +1;
                    } 
                    else{
                    c.Chennai_DC_No__c =0+1;
                    }
                    }
                    }
                    if(OpList.size() > 0){
                if(c.Location__c== 'Bangalore'){ 
                  if(OpList[0].Bangalore_DC_No__c!= null){                  
                    c.Bangalore_DC_No__c =OpList[0].Bangalore_DC_No__c +1;
                    } 
                    else{
                    c.Bangalore_DC_No__c =0+1;
                    }
                    }
                    }
                }

}

 

when we create a new record a field should be updated with the previous record value

I have a custom field in Opportunity is Auto_Number__c

 

i have a trigger like this

trigger updateactive on Opportunity(before insert){



for(Opportunity c : Trigger.new){

if(c.StageName == 'Closed Won')
c.Auto_Number__c=c.Auto_Number__c+1;

}

}

 I want to increment the old record Auto_Number__c and update like2,3,4 etc  like that when opportunity is closed won

 

trigger promoteOrdertoAsset on Item_Order__c (after insert, after update) {
 2	     
 3	     public List<Asset> listOfAssets = new List<Asset>();
 4	     public List<Asset> listOfUpdateAssets= new List<Asset>();
 5	     Schema.DescribeSObjectResult objDescribe =  Asset.SObjectType.getDescribe();
 6	     List<Status__c> status = [select id, Name from Status__C];
 7	      Map<Id,String> statusMap = new Map<Id, String>();
 8	     for (Status__c stat : status)
 9	     {
 10	         statusMap.put(stat.Id, stat.Name);
 11	     }
 12	     
 13	     List<OrderToAssetMap__c> conversionMap = OrderToAssetMap__c.getall().values();
 14	     Map<String,String> ignoreList = new Map<String, String>();
 15	     Map<String,String> mapList = new Map<String, String>();
 16	     for (OrderToAssetMap__c mapField : conversionMap )
 17	     {
 18	         if(mapField.Ignore__c= true)
 19	         {
 20	             ignoreList.put(mapField.Asset_Field__c,mapField.Asset_Field__c);
 21	         }
 22	     }
 23	    
 24	     for (OrderToAssetMap__c mapField : conversionMap )
 25	     {
 26	         System.debug(' mapField.Ignore__c is: ' + mapField.Ignore__c);
 27	         System.debug(' mapField.Asset_Field__c is: ' + mapField.Asset_Field__c);
 28	         System.debug('mapField.Order_Field__c is: ' +mapField.Order_Field__c);
 29	         if(mapField.Asset_Field__c!=null)
 30	         {
 31	             mapList.put(mapField.Asset_Field__c,mapField.Order_Field__c);
 32	         }
 33	     }
 34	     System.debug('mapList is: ' + mapList );
 35	     List<String> itemIds = new List<String>();
 36	     List<String> parentItemIds = new List<String>();
 37	     for(Item_Order__c ord : Trigger.new )
 38	     {
 39	         itemIds.add(ord.Item_ID__c);
 40	     }
 41	     for(Item_Order__c ord : Trigger.new )
 42	     {
 43	         if(ord.Parent_Item__c != null)
 44	         {
 45	             parentItemIds.add(ord.Parent_Item_Id__c);
 46	         }
 47	     }
 48	     System.debug('parentItemIds: ' + parentItemIds);
 49	     List<Asset> updateAssetList = [select Id, Item_Id__c from Asset where Item_id__c in : itemIds];
 50	     List<Asset> parentAssetList = [select Id, Item_Id__c from Asset where Item_id__c in : parentItemIds];
 51	     System.debug('parentAssetList : ' + parentAssetList );
 52	     Map<String, Asset> updateAssetMap = new Map<String, Asset>();
 53	     Map<String, Asset> parentAssetMap = new Map<String, Asset>();
 54	     for(Asset asset : updateAssetList )
 55	     {
 56	        updateAssetMap.put(asset.Item_Id__c, asset);
 57	     }
 58	     for(Asset asset : parentAssetList )
 59	     {
 60	        parentAssetMap.put(asset.Item_id__c, asset);
 61	     }
 62	     for(Item_Order__c ord : Trigger.new )
 63	     {
 64	         System.debug('Order Id: ' + ord.Account__C);
 65	         if(statusMap.get(ord.Status__c) != null && statusMap.get(ord.Status__c) == 'Published' && updateAssetMap.get(ord.Item_Id__C) == null)
 66	         {
 67	             System.debug('Creating Asset for Order: ' + ord);
 68	             Asset asset = new Asset();
 69	             asset.AccountId = ord.Account__c;
 70	             if(ord.Parent_Item__c != null)
 71	             {
 72	                 asset.Asset__c = parentAssetMap.get(ord.Parent_Item_Id__c).Id;
 73	             }
 74	             asset.InstallDate = System.today();
 75	              for (String field : objDescribe.fields.getMap().keySet())
 76	                 {
 77	                     if(ignoreList.get(field)== null && mapList.get(field)== null)
 78	                     {
 79	                         if(ord.get(field) != null)
 80	                         {
 81	                             asset.put(field , ord.get(field));
 82	                             System.debug('Asset is: '+ asset);
 83	                         }
 84	                     }
 85	                     if(mapList.get(field)!= null)
 86	                     {
 87	                         String orderField = mapList.get(field);
 88	                         asset.put(field , ord.get(orderField ));
 89	                         System.debug('orderField is: '+ orderField );
 90	                         System.debug(' orderField Asset is: '+ asset);
 91	                     }
 92	                 }
 93	             listOfAssets.add(asset);
 94	         }
 95	         else if (updateAssetMap.get(ord.Item_Id__C) != null && (ord.Action__c =='Change' ||ord.Action__c =='Renew') && ord.Action_Type__c != 'Cancel')
 96	         {
 97	             Asset asset = new Asset(Id=updateAssetMap.get(ord.Item_Id__C).Id);
 98	              for (String field : objDescribe.fields.getMap().keySet())
 99	                 {
 100	                     if(ignoreList.get(field)== null)
 101	                     {
 102	                         asset.put(field , ord.get(field));
 103	                         System.debug('Asset is: '+ asset);
 104	                     }
 105	                 }
 106	                 listOfUpdateAssets.add(asset);
 107	         }
 108	         else if (updateAssetMap.get(ord.Item_Id__C) != null && ord.Action__c =='Cancel'  && ord.Action_Type__c != 'Cancel')
 109	         {
 110	             Asset asset = new Asset(Id=updateAssetMap.get(ord.Item_Id__C).Id);
 111	              asset.Status = 'Cancel';
 112	                 listOfUpdateAssets.add(asset);
 113	         }
 114	        
 115	         
 116	     }
 117	    
 118	     System.debug('listOfAssets: '+ listOfAssets);
 119	     if(listOfAssets!=null)
 120	     {
 121	      insert listOfAssets;
 122	      }
 123	      if(listOfUpdateAssets != null)
 124	      {
 125	          update listOfUpdateAssets;
 126	      }
 127	  }

 Line no:68-112 are not covering

 

can u pls help in these

 

public with sharing class AttachController {

//private ApexPages.StandardController controller { get; set; }
public List<Deal_License__c> dp{get;set;}
public List<Contact> con{get;set;}

   public Deal__c D{get;set;}
    public AttachController(ApexPages.StandardController controller) {
    try
    {
     D = [Select Name,Id,VersionNo__c,Account__c,Account__r.Name,Account_Executive__r.Name,License_Value__c,Account__r.BillingStreet,Account__r.BillingCity,Account__r.Billingstate,Account__r.BillingPostalcode,Account__r.BillingCountry
                 from Deal__c where id=:controller.getRecord().id];
    system.debug('TestDeal'+D);
    Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:D.Account__c];
    system.debug('Account%%%%%%%%%%%%%%'+acc);
    dp=[select id,Name,Deal__c,Months__c,List_Price__c,Unit_Price__c,Quantity__c,Total_Value__c,Ingram_Transfer_Price__c,Ingram_Special_Price__c,Ingram_Purchase_Value__c,Start_Date__c,End_Date__c from Deal_License__c where Deal__c=:D.Id];
    System.debug('DEALPRDODUCT&&&&&&&&&&'+dp);
    con=[select Id,Name,Email,Phone,MobilePhone from Contact  where id=:D.Account_Executive__c];
   
    }
    catch(Exception e)
    {
    system.debug('Exception'+e);
    }
    }
    
    public void attach() {
        try{
           Deal__c D=new Deal__c();
            Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            system.debug('Account%%%%%%%%%%%%%%'+c);
            myAttach.name =''+''+ c +'';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;
            D.VersionNo__c=myAttach.name;
            update D;
          
            
              
            
                       
            System.debug('After attach');
            System.debug(myAttach);

            
            /*
            ApexPages.addMessage(new ApexPages.Message

(ApexPages.Severity.CONFIRM,'Quotation has been attached.'));
            */
        }
        catch(Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There was an error while attaching'));
            System.debug('Exception');
        }
    }
    
   public PageReference QA() {
   
     PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + ApexPages.currentPage().getParameters().get('id'));

      Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name = ''+''+ c +'';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
           try{
                myAttach.body = psPdf.getContentAsPdf();
               }
        catch(Exception e){}
//insert myAttach;
              secondPage.setRedirect(true);
              return secondPage;
              }
            
    
    public PageReference back() {
        attach();
        PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
        pr.setRedirect(true);
        System.debug('Inside back');
        return pr;
    }
       public PageReference cancel() {
       PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
       pr.setRedirect(true);
       System.debug('Inside back');
       return pr;
       }
       
    
      
     /*public String attachmentName{get; set;}
      public pagereference AttachQuote(){
        Pagereference pdf = page.Quotation;
        blob  b=pdf.getcontent();
      
         attachment att = new attachment();
         att.parentId = ApexPages.currentPage().getParameters().get('id') ;
         att.body = b;
         att.name = 'Quotation.pdf';     
         insert att;
         return null;
         
         
      
      }*/
       /*test methods here*/
     public  static testMethod void testAttachController()
      {    
       Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
  
 User U = new User(Alias = 'TUser1', Email='testItemaster1@im.com',EmailEncodingKey='UTF-8',
   LastName='TestingAcc1', LanguageLocaleKey='en_US',LocaleSidKey='en_US', ProfileId =p.Id,
   TimeZoneSidKey='America/Los_Angeles', UserName='testacc1@test.com');   
 insert U;
        
        Account acc=new Account

(Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india');
        insert acc;
         system.debug('########555'+ acc);
        Deal__c opp=new Deal__c(Name='test12',Account__c=acc.id);
        insert opp;
        system.debug('########7765'+ opp);
     
                
        Attachment myAttach1 = new Attachment();
        myAttach1.ParentId =opp.id;
        myAttach1.name = 'Quotation.pdf';
        myAttach1.body = blob.valueof('test');
          
        insert myAttach1;
        
        
        system.debug('Attahment1'+ myAttach1);
     
        AttachController atc = new AttachController(new ApexPages.StandardController(opp));
        system.debug('%%%%%'+atc);
        PageReference pageRef = Page.Quotation;
        pageRef.getParameters().put('id', String.valueOf(opp.Id));
        Test.setCurrentPage(pageRef);
       Blob b;

       ApexPages.currentPage().getParameters().put('id', opp.id);
       AttachController atc1 = new AttachController(new ApexPages.StandardController(myAttach1));
        //ApexPages.StandardController stc = new ApexPages.StandardController(opp);  
        //AttachController qe = new AttachController(stc);
         
         // qe.QA();
        atc.attach();
        //atc.QA();
        atc.back();
        atc.cancel();
        atc.QA();
       
        return;
        
       /* public PageReference QA() {
     PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + 

ApexPages.currentPage().getParameters().get('id'));
        
       insert myAttach1;
       secondPage.setRedirect(true);   
            return secondPage;
            }*/
     
      //Attachment atchoo = [Select Id,  From Attachment where Name like 'Quotation.pdf' 


       /* if (Test.isRunningTest())
{
   b=Blob.valueOf('Test Blob String');
}
else
{
  b= pageRef.getContent();
}*/

         }
         
      }

 I want to get the myattach.name in VersionNo__c field of Deal__c object shoulb get updated

 

Ref Line no:42

public void attach() {
        try{
            Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name =D.Account__r.Name +''+ 'License Version' + c +'.pdf';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;

 

In this i want to get the Google Docs, Notes, & Attachments ,,,Title Name when i attach Quotation by clicking the button

D.Account__r.Name +''+ 'License Version' + c +'.pdf';==aaa1.pdf

 

and when i attach manually finaldraft.doc

and when again i attach D.Account__r.Name +''+ 'License Version' + c +'.pdf';==aaa3.pdf but it should be aaa2.pdf

 

 

its urgent can u help me

i have two Objects Product_Master__c and Order_Product__c having look up relation,how can i get the updation of  Product_Master__c  look up fields in Order_Product__c   when i select Product master record in Order Product all the look up fields in Order Product should be updated

I Have two Objects Product_Master__c and Order_Product__c,in Order_Product__c i have given look up to Product_Master__c ,,,,,,,i want to get look up fields of  Product_Master__c in Order_Product__c...........i am getting the value but its in id form how can i get it in text type

trigger AddQuickLead on Lead (after insert) {
    
    for (Lead l : Trigger.new) {
       
        
        Quick_Lead__c reg = new Quick_Lead__c(
            Name=l.Name,
            Email__c = l.Email,
            Street_Address__c = l.Street,
            city__c = l.City,
            state__c = l.State,
            Country__c = l.Country
          );
          
          if(l.FirstName==null)
        {
        reg.Name= l.LastName;
        }
        else
        {
        reg.Name= l.FirstName+''+''+l.LastName;
        }
        
        insert reg;
    }

 how to get coverage for line:

reg.Name= l.FirstName+''+''+l.LastName;
  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

 

 

 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	  }

 From line 63-125 it is not covering

pls check once

public with sharing class AttachController {
 2	  
 3	  //private ApexPages.StandardController controller { get; set; }
 4	  public List<Deal_License__c> dp{get;set;}
 5	  
 6	     public Deal__c D{get;set;}
 7	      public AttachController(ApexPages.StandardController controller) {
 8	      try
 9	      {
 10	       D = [Select Name,Id,Account__c,Account__r.Name,Rate__c,License_Value__c,Account__r.BillingStreet,Account__r.BillingCity,Account__r.Billingstate,Account__r.BillingPostalcode,Account__r.BillingCountry
 11	                   from Deal__c where id=:controller.getRecord().id];
 12	      system.debug('TestDeal'+D);
 13	      Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:D.Account__c];
 14	      system.debug('Account%%%%%%%%%%%%%%'+acc);
 15	      dp=[select id,Name,Deal__c,Months__c,List_Price__c,Unit_Price__c,Quantity__c,Total_Value__c from Deal_License__c where Deal__c=:D.Id];
 16	      System.debug('DEALPRDODUCT&&&&&&&&&&'+dp);
 17	      }
 18	      catch(Exception e)
 19	      {
 20	      system.debug('Exception'+e);
 21	      }
 22	      }
 23	      
 24	      public void attach() {
 25	          try{
 26	              Attachment myAttach = new Attachment();
 27	              myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
 28	              System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
 29	              List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
 30	              Integer c=at.size()+1;
 31	              myAttach.name =D.Account__r.Name +''+ 'License Version' + c +'.pdf';
 32	              PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
 33	              myAttach.body = psPdf.getContentAsPdf();
 34	  
 35	              insert myAttach;
 36	              
 37	                
 38	              
 39	                         
 40	              System.debug('After attach');
 41	              System.debug(myAttach);
 42	  
 43	              
 44	              /*
 45	              ApexPages.addMessage(new ApexPages.Message
 46	  
 47	  (ApexPages.Severity.CONFIRM,'Quotation has been attached.'));
 48	              */
 49	          }
 50	          catch(Exception e) {
 51	              ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There was an error while attaching'));
 52	              System.debug('Exception');
 53	          }
 54	      }
 55	      
 56	     public PageReference QA() {
 57	     
 58	       PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + ApexPages.currentPage().getParameters().get('id'));
 59	  
 60	        Attachment myAttach = new Attachment();
 61	              myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
 62	              System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
 63	              List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
 64	              Integer c=at.size()+1;
 65	              myAttach.name = D.Account__r.Name +''+ 'License Version' + c +'.pdf';
 66	              PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
 67	              myAttach.body = psPdf.getContentAsPdf();
 68	  
 69	              //insert myAttach;
 70	                
 71	              secondPage.setRedirect(true);   
 72	              return secondPage; 
 73	              
 74	      }
 75	      public PageReference back() {
 76	          attach();
 77	          PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
 78	          pr.setRedirect(true);
 79	          System.debug('Inside back');
 80	          return pr;
 81	      }
 82	         public PageReference cancel() {
 83	         PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
 84	         pr.setRedirect(true);
 85	         System.debug('Inside back');
 86	         return pr;
 87	         }
 88	         
 89	      
 90	        
 91	       /*public String attachmentName{get; set;}
 92	        public pagereference AttachQuote(){
 93	          Pagereference pdf = page.Quotation;
 94	          blob  b=pdf.getcontent();
 95	        
 96	           attachment att = new attachment();
 97	           att.parentId = ApexPages.currentPage().getParameters().get('id') ;
 98	           att.body = b;
 99	           att.name = 'Quotation.pdf';     
 100	           insert att;
 101	           return null;
 102	           
 103	           
 104	        
 105	        }*/
 106	         /*test methods here*/
 107	       public  static testMethod void testAttachController()
 108	        {    
 109	         Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
 110	    
 111	   User U = new User(Alias = 'TUser1', Email='testItemaster1@im.com',EmailEncodingKey='UTF-8',
 112	     LastName='TestingAcc1', LanguageLocaleKey='en_US',LocaleSidKey='en_US', ProfileId =p.Id,
 113	     TimeZoneSidKey='America/Los_Angeles', UserName='testacc1@test.com');   
 114	   insert U;
 115	          
 116	          Account acc=new Account
 117	  
 118	  (Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india');
 119	          insert acc;
 120	           system.debug('########555'+ acc);
 121	          Deal__c opp=new Deal__c(Name='test12',Account__c=acc.id);
 122	          insert opp;
 123	          system.debug('########7765'+ opp);
 124	       
 125	                  
 126	          Attachment myAttach1 = new Attachment();
 127	          myAttach1.ParentId =opp.id;
 128	          myAttach1.name = 'Quotation.pdf';
 129	          myAttach1.body = blob.valueof('test');
 130	            
 131	          insert myAttach1;
 132	          
 133	          
 134	          system.debug('Attahment1'+ myAttach1);
 135	       
 136	          AttachController atc = new AttachController(new ApexPages.StandardController(opp));
 137	          system.debug('%%%%%'+atc);
 138	          PageReference pageRef = Page.Quotation;
 139	          pageRef.getParameters().put('id', String.valueOf(opp.Id));
 140	          Test.setCurrentPage(pageRef);
 141	         Blob b;
 142	  
 143	  
 144	         AttachController atc1 = new AttachController(new ApexPages.StandardController(myAttach1));
 145	          
 146	          atc1.attach();
 147	          atc.back();
 148	          atc.cancel();
 149	          //atc.QA();
 150	         
 151	          
 152	          return;
 153	         /* public PageReference QA() {
 154	       PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + 
 155	  
 156	  ApexPages.currentPage().getParameters().get('id'));
 157	          
 158	         insert myAttach1;
 159	         secondPage.setRedirect(true);   
 160	              return secondPage;
 161	              }*/
 162	       
 163	        //Attachment atchoo = [Select Id,  From Attachment where Name like 'Quotation.pdf' 
 164	  
 165	  
 166	         /* if (Test.isRunningTest())
 167	  {
 168	     b=Blob.valueOf('Test Blob String');
 169	  }
 170	  else
 171	  {
 172	    b= pageRef.getContent();
 173	  }*/
 174	  
 175	           }
 176	           
 177	        }

 when i am trying to keep atc.QA();

Error message:Methods defined as TestMethod do not support getContent call, test skipped

 

 

can u pls anybody help in solving this

public class MyAccountListCntrlr {


     // PROPERTIES
      public String subject { get; set; }
      public String body { get; set; }
      public string ccaddress{set;get;}
      public string bccaddress{set;get;}
  
     public List<ContactWrapperCls> acctList {get;set;}
     public List<String> selAccountNames{get;set;}
     public Boolean hasSelAcct {get;set;}
     public final Deal__c opp;
     public task t = new task();
     // CONSTRUCTOR
     public MyAccountListCntrlr(ApexPages.StandardController controller){
          acctList = new List<ContactWrapperCls>();
          selAccountNames= new List<String>();
          opp = [SELECT Name,id,Account__c FROM Deal__c
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
                   system.debug('opportunity@@@@@@@@@@'+opp);                  

        for(Contact a : [SELECT Name,id,Email,Account.Name,Account.Id FROM Contact where Account.id=:opp.Account__c ]){
               acctList.add(new ContactWrapperCls(a));
            Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:opp.Account__c];
          } 

     }

     // METHODS
     public void displaySelectedAccountNumbers(){
          selAccountNames.clear();
          hasSelAcct = false;
          for(ContactWrapperCls cWrapper : acctList){
               if(cWrapper.isSelected){
                    hasSelAcct = true;
                    selAccountNames.add(cWrapper.cContact.Email);
               }
          }
     }
   
      public PageReference send() {
     
     // Define the email 
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        
     // Reference the attachment page and pass in the OpportunityID
        PageReference pdf =  Page.Quotation;
        pdf.getParameters().put('id',(String)opp.id); 
        pdf.setRedirect(true);

     // Take the PDF content
            Blob b = pdf.getContent();
            Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name =opp.Name +''+ 'License Version' + c +'.pdf';
            myAttach.body = b;
            insert myAttach;
           

     // Create the email attachment
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setFileName(myAttach.name);
        efa.setBody(b);

        String[] ccAddresses = new String[] {ccaddress};
        String[] bccAddresses = new String[] {'emailtosalesforce@28wj1f7u1jx4d0rk7syg098pe8grkt8ir75tm5j0vhveterlrr.z-87epmai.z.le.sandbox.salesforce.com'};
        String addresses;
     /*   if (con[0].Email != null) {
       
            address = con[0].Email;
            // Loop through the whole list of contacts and their emails 
    
            for (Integer i = 1; i <con.size(); i++) {
                if (con[i].Email != null) {
                    address += ':' + con[i].Email;
                }
            }
        }*/
      //  addresses = con.Email;
        String[] toAddresses = selAccountNames;
        
       
        
    
     // Sets the paramaters of the email 
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
            
    string UserId = UserInfo.getUserId();
    User user = [select email, IsActive from User where id = :UserId];
        

        
     //email.setCcAddresses(toAddresses);
     //email.setBccAddresses(bccaddress);
        email.setReplyTo(user.email);
        email.setBccSender(true);
        email.setHtmlBody(body);
        email.setSenderDisplayName('Salesforce');
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); 
        
        // Sends the email 
        Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

        t.subject ='Email:'+myAttach.name+ subject;
        t.status = 'Completed';
        t.description = body;
        t.type =  'Email';
        t.ActivityDate = System.today();
        t.Whatid=opp.id;

        insert t;
            
        //PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
        PageReference pr = new PageReference('/'+ ApexPages.currentPage().getParameters().get('id'));
      
        pr.setRedirect(true);
      
        System.debug('Inside back');
        return pr;
        return null;
       }

public class ContactWrapperCls {
     public Boolean isSelected {get;set;}
     public Contact cContact {get;set;}

     public ContactWrapperCls(Contact cContact){
          this.cContact = cContact;
     }
}
private static testMethod void myUnitTest() {
  Account acc=new Account(Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india');
        insert acc;
         system.debug('########555'+ acc);
        Deal__c opp=new Deal__c(Name='test12',Account__c=acc.id);
        insert opp;
        system.debug('########7765'+ opp);
     
    Contact con =  new Contact();
    con.FirstName = 'Anil';
    con.LastName = 'Dutt';
    con.Email = 'anil@swiftsetup.com';
    insert con;


    Deal__c oppNew =  new Deal__c();
    oppNew.Name = 'Test Opp';
    oppNew.Stage__c = 'Business Case';
   
    insert oppNew;


   //ApexPages.StandardController sc = new ApexPages.StandardController(con);
   //SendConfirmation sc1=new SendConfirmation (sc);
   //sc1.SendEmail();
}
}

 

 
public with sharing class AttachController {

//private ApexPages.StandardController controller { get; set; }
public List<Deal_License__c> dp{get;set;}

   public Deal__c D{get;set;}
    public AttachController(ApexPages.StandardController controller) {
     D = [Select Name,Id,Account__c,Account__r.Name,Rate__c,Total_Value__c,Account__r.BillingStreet,
                 Account__r.BillingCity,Account__r.Billingstate,Account__r.BillingPostalcode,Account__r.BillingCountry
                 from Deal__c where id=:ApexPages.currentPage().getParameters().get('id')];
    system.debug('TestDeal'+D);
    Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:D.Account__c];
    system.debug('Account%%%%%%%%%%%%%%'+acc);
    dp=[select id,Name,Deal__c,Months__c,List_Price__c,Unit_Price__c,Quantity__c,Total_Value__c from Deal_License__c where Deal__c=:D.Id];
    System.debug('DEALPRDODUCT&&&&&&&&&&'+dp);
    }
    
    public void attach() {
        try{
            Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name =D.Account__r.Name +''+ 'License Version' + c +'.pdf';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;
              
            
                       
            System.debug('After attach');
            System.debug(myAttach);

            
            /*
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Quotation has been attached.'));
            */
        }
        catch(Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There was an error while attaching'));
            System.debug('Exception');
        }
    }
    
    public PageReference QA() {
     PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + ApexPages.currentPage().getParameters().get('id'));
      Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name = D.Account__r.Name +''+ 'License Version' + c +'.pdf';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;
              
            secondPage.setRedirect(true);   
            return secondPage; 
    }
    public PageReference back() {
        attach();
        PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
        pr.setRedirect(true);
        System.debug('Inside back');
        return pr;
    }
       public PageReference cancel() {
       PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
       pr.setRedirect(true);
       System.debug('Inside back');
       return pr;
       }
       
    
      
     public String attachmentName{get; set;}
      public pagereference AttachQuote(){
        Pagereference pdf = page.Quotation;
        blob  b = pdf.getContent();
    
         attachment att = new attachment();
         att.parentId = ApexPages.currentPage().getParameters().get('id') ;
         att.body = b;
         att.name = 'Quotation.pdf';     
         insert att;
         return null;
         
      
      }

 

public with sharing class AttachController {

//private ApexPages.StandardController controller { get; set; }
public List<Deal_License__c> dp{get;set;}

   public Deal__c D{get;set;}
    public AttachController(ApexPages.StandardController controller) {
     D = [Select Name,Id,Account__c,Account__r.Name,Rate__c,Total_Value__c,Account__r.BillingStreet,
                 Account__r.BillingCity,Account__r.Billingstate,Account__r.BillingPostalcode,Account__r.BillingCountry
                 from Deal__c where id=:ApexPages.currentPage().getParameters().get('id')];
    system.debug('TestDeal'+D);
    Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:D.Account__c];
    system.debug('Account%%%%%%%%%%%%%%'+acc);
    dp=[select id,Name,Deal__c,Months__c,List_Price__c,Unit_Price__c,Quantity__c,Total_Value__c from Deal_License__c where Deal__c=:D.Id];
    System.debug('DEALPRDODUCT&&&&&&&&&&'+dp);
    }
    
    public void attach() {
        try{
            Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name =D.Account__r.Name +''+ 'License Version' + c +'.pdf';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;
              
            
                       
            System.debug('After attach');
            System.debug(myAttach);

            
            /*
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Quotation has been attached.'));
            */
        }
        catch(Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There was an error while attaching'));
            System.debug('Exception');
        }
    }
    
    public PageReference QA() {
     PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + ApexPages.currentPage().getParameters().get('id'));
      Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name = D.Account__r.Name +''+ 'License Version' + c +'.pdf';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;
              
            secondPage.setRedirect(true);   
            return secondPage; 
    }
    public PageReference back() {
        attach();
        PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
        pr.setRedirect(true);
        System.debug('Inside back');
        return pr;
    }
       public PageReference cancel() {
       PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
       pr.setRedirect(true);
       System.debug('Inside back');
       return pr;
       }
        /*test methods here*/
     public static testMethod void testAttachController()
      {    
        //Opportunity opp=[select id from Opportunity where Name=:'Prasad Punage-'];
        Account acc=new Account(Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india' );
        insert acc;
        Deal__c opp=new Deal__c(Name='test12',Account__c='acc.id');
        insert opp;
       
        Deal_License__c dl=new Deal_License__c(Name='asd',Deal__c='opp.id');
        insert dl;        
        Attachment myAttach1 = new Attachment();
        myAttach1.ParentId =opp.id;
        myAttach1.name = 'Quotation.pdf';
        myAttach1.body = blob.valueof('test');
          
        insert myAttach1;
        system.debug('Attahment1'+ myAttach1);
        AttachController atc = new AttachController(new ApexPages.StandardController(myAttach1));
         
        atc.attach();
        atc.back();
        atc.cancel();
      }
      
      public String attachmentName{get; set;}
      public pagereference AttachQuote(){
        Pagereference pdf = page.Quotation;
        blob  b = pdf.getContent();
    
         attachment att = new attachment();
         att.parentId = ApexPages.currentPage().getParameters().get('id') ;
         att.body = b;
         att.name = 'Quotation.pdf';     
         insert att;
         
         return null;
      
      }
}

 Thanks in advance

Apex class

public with sharing class AttachController {

//private ApexPages.StandardController controller { get; set; }
public List<Deal_License__c> dp{get;set;}

   public Deal__c D{get;set;}
    public AttachController(ApexPages.StandardController controller) {
     D = [Select Name,Id,Account__c,Account__r.Name,Rate__c,Total_Value__c,Account__r.BillingStreet,
                 Account__r.BillingCity,Account__r.Billingstate,Account__r.BillingPostalcode,Account__r.BillingCountry
                 from Deal__c where id=:ApexPages.currentPage().getParameters().get('id')];
    system.debug('TestDeal'+D);
    Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:D.Account__c];
    system.debug('Account%%%%%%%%%%%%%%'+acc);
    dp=[select id,Name,Deal__c,Months__c,List_Price__c,Unit_Price__c,Quantity__c,Total_Value__c from Deal_License__c where Deal__c=:D.Id];
    System.debug('DEALPRDODUCT&&&&&&&&&&'+dp);
    }
    
    public void attach() {
        try{
            Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name =D.Account__r.Name +''+ 'License Version' + c +'.pdf';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;
              
            
                       
            System.debug('After attach');
            System.debug(myAttach);

            
            /*
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Quotation has been attached.'));
            */
        }
        catch(Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There was an error while attaching'));
            System.debug('Exception');
        }
    }
    
    public PageReference QA() {
     PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + ApexPages.currentPage().getParameters().get('id'));
      Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name = D.Account__r.Name +''+ 'License Version' + c +'.pdf';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;
              
            secondPage.setRedirect(true);   
            return secondPage; 
    }
    public PageReference back() {
        attach();
        PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
        pr.setRedirect(true);
        System.debug('Inside back');
        return pr;
    }
       public PageReference cancel() {
       PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
       pr.setRedirect(true);
       System.debug('Inside back');
       return pr;
       }
        /*test methods here*/
     public static testMethod void testAttachController()
      {    
        //Opportunity opp=[select id from Opportunity where Name=:'Prasad Punage-'];
        Account acc=new Account(Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india' );
        insert acc;
        Deal__c opp=new Deal__c(Name='test12',Account__c='acc.id');
        insert opp;
       
        Deal_License__c dl=new Deal_License__c(Name='asd',Deal__c='opp.id');
        insert dl;        
        Attachment myAttach1 = new Attachment();
        myAttach1.ParentId =opp.id;
        myAttach1.name = 'Quotation.pdf';
        myAttach1.body = blob.valueof('test');
          
        insert myAttach1;
        system.debug('Attahment1'+ myAttach1);
        AttachController atc = new AttachController(new ApexPages.StandardController(myAttach1));
         
        atc.attach();
        atc.back();
        atc.cancel();
      }
      
      public String attachmentName{get; set;}
      public pagereference AttachQuote(){
        Pagereference pdf = page.Quotation;
        blob  b = pdf.getContent();
    
         attachment att = new attachment();
         att.parentId = ApexPages.currentPage().getParameters().get('id') ;
         att.body = b;
         att.name = 'Quotation.pdf';     
         insert att;
         
         return null;
      
      }
}

 Please help me in test class....

 

Thanks in Advance............

I am Using Account and it has 2 Record Types namely Distributor and Dealer.And when user creates Dealer he will choose Distributor from Standard Parent Account Lookup...

And for Distributors records are shared manually , the users who are shared distributors has to view dealers under them automatically./

for ex:i have Distributor called ABC Enterprise and under this distributor it has 60 dealers so when i share ABC distributor to 4 users dealers has to be shared automatically

I have a custom field in Opportunity is Auto_Number__c

 

i have a trigger like this

trigger updateactive on Opportunity(before insert){



for(Opportunity c : Trigger.new){

if(c.StageName == 'Closed Won')
c.Auto_Number__c=c.Auto_Number__c+1;

}

}

 I want to increment the old record Auto_Number__c and update like2,3,4 etc  like that when opportunity is closed won

 

public with sharing class AttachController {

//private ApexPages.StandardController controller { get; set; }
public List<Deal_License__c> dp{get;set;}
public List<Contact> con{get;set;}

   public Deal__c D{get;set;}
    public AttachController(ApexPages.StandardController controller) {
    try
    {
     D = [Select Name,Id,VersionNo__c,Account__c,Account__r.Name,Account_Executive__r.Name,License_Value__c,Account__r.BillingStreet,Account__r.BillingCity,Account__r.Billingstate,Account__r.BillingPostalcode,Account__r.BillingCountry
                 from Deal__c where id=:controller.getRecord().id];
    system.debug('TestDeal'+D);
    Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:D.Account__c];
    system.debug('Account%%%%%%%%%%%%%%'+acc);
    dp=[select id,Name,Deal__c,Months__c,List_Price__c,Unit_Price__c,Quantity__c,Total_Value__c,Ingram_Transfer_Price__c,Ingram_Special_Price__c,Ingram_Purchase_Value__c,Start_Date__c,End_Date__c from Deal_License__c where Deal__c=:D.Id];
    System.debug('DEALPRDODUCT&&&&&&&&&&'+dp);
    con=[select Id,Name,Email,Phone,MobilePhone from Contact  where id=:D.Account_Executive__c];
   
    }
    catch(Exception e)
    {
    system.debug('Exception'+e);
    }
    }
    
    public void attach() {
        try{
           Deal__c D=new Deal__c();
            Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            system.debug('Account%%%%%%%%%%%%%%'+c);
            myAttach.name =''+''+ c +'';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;
            D.VersionNo__c=myAttach.name;
            update D;
          
            
              
            
                       
            System.debug('After attach');
            System.debug(myAttach);

            
            /*
            ApexPages.addMessage(new ApexPages.Message

(ApexPages.Severity.CONFIRM,'Quotation has been attached.'));
            */
        }
        catch(Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There was an error while attaching'));
            System.debug('Exception');
        }
    }
    
   public PageReference QA() {
   
     PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + ApexPages.currentPage().getParameters().get('id'));

      Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name = ''+''+ c +'';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
           try{
                myAttach.body = psPdf.getContentAsPdf();
               }
        catch(Exception e){}
//insert myAttach;
              secondPage.setRedirect(true);
              return secondPage;
              }
            
    
    public PageReference back() {
        attach();
        PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
        pr.setRedirect(true);
        System.debug('Inside back');
        return pr;
    }
       public PageReference cancel() {
       PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
       pr.setRedirect(true);
       System.debug('Inside back');
       return pr;
       }
       
    
      
     /*public String attachmentName{get; set;}
      public pagereference AttachQuote(){
        Pagereference pdf = page.Quotation;
        blob  b=pdf.getcontent();
      
         attachment att = new attachment();
         att.parentId = ApexPages.currentPage().getParameters().get('id') ;
         att.body = b;
         att.name = 'Quotation.pdf';     
         insert att;
         return null;
         
         
      
      }*/
       /*test methods here*/
     public  static testMethod void testAttachController()
      {    
       Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
  
 User U = new User(Alias = 'TUser1', Email='testItemaster1@im.com',EmailEncodingKey='UTF-8',
   LastName='TestingAcc1', LanguageLocaleKey='en_US',LocaleSidKey='en_US', ProfileId =p.Id,
   TimeZoneSidKey='America/Los_Angeles', UserName='testacc1@test.com');   
 insert U;
        
        Account acc=new Account

(Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india');
        insert acc;
         system.debug('########555'+ acc);
        Deal__c opp=new Deal__c(Name='test12',Account__c=acc.id);
        insert opp;
        system.debug('########7765'+ opp);
     
                
        Attachment myAttach1 = new Attachment();
        myAttach1.ParentId =opp.id;
        myAttach1.name = 'Quotation.pdf';
        myAttach1.body = blob.valueof('test');
          
        insert myAttach1;
        
        
        system.debug('Attahment1'+ myAttach1);
     
        AttachController atc = new AttachController(new ApexPages.StandardController(opp));
        system.debug('%%%%%'+atc);
        PageReference pageRef = Page.Quotation;
        pageRef.getParameters().put('id', String.valueOf(opp.Id));
        Test.setCurrentPage(pageRef);
       Blob b;

       ApexPages.currentPage().getParameters().put('id', opp.id);
       AttachController atc1 = new AttachController(new ApexPages.StandardController(myAttach1));
        //ApexPages.StandardController stc = new ApexPages.StandardController(opp);  
        //AttachController qe = new AttachController(stc);
         
         // qe.QA();
        atc.attach();
        //atc.QA();
        atc.back();
        atc.cancel();
        atc.QA();
       
        return;
        
       /* public PageReference QA() {
     PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + 

ApexPages.currentPage().getParameters().get('id'));
        
       insert myAttach1;
       secondPage.setRedirect(true);   
            return secondPage;
            }*/
     
      //Attachment atchoo = [Select Id,  From Attachment where Name like 'Quotation.pdf' 


       /* if (Test.isRunningTest())
{
   b=Blob.valueOf('Test Blob String');
}
else
{
  b= pageRef.getContent();
}*/

         }
         
      }

 I want to get the myattach.name in VersionNo__c field of Deal__c object shoulb get updated

 

Ref Line no:42

public with sharing class AttachController {
 2	  
 3	  //private ApexPages.StandardController controller { get; set; }
 4	  public List<Deal_License__c> dp{get;set;}
 5	  
 6	     public Deal__c D{get;set;}
 7	      public AttachController(ApexPages.StandardController controller) {
 8	      try
 9	      {
 10	       D = [Select Name,Id,Account__c,Account__r.Name,Rate__c,License_Value__c,Account__r.BillingStreet,Account__r.BillingCity,Account__r.Billingstate,Account__r.BillingPostalcode,Account__r.BillingCountry
 11	                   from Deal__c where id=:controller.getRecord().id];
 12	      system.debug('TestDeal'+D);
 13	      Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:D.Account__c];
 14	      system.debug('Account%%%%%%%%%%%%%%'+acc);
 15	      dp=[select id,Name,Deal__c,Months__c,List_Price__c,Unit_Price__c,Quantity__c,Total_Value__c from Deal_License__c where Deal__c=:D.Id];
 16	      System.debug('DEALPRDODUCT&&&&&&&&&&'+dp);
 17	      }
 18	      catch(Exception e)
 19	      {
 20	      system.debug('Exception'+e);
 21	      }
 22	      }
 23	      
 24	      public void attach() {
 25	          try{
 26	              Attachment myAttach = new Attachment();
 27	              myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
 28	              System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
 29	              List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
 30	              Integer c=at.size()+1;
 31	              myAttach.name =D.Account__r.Name +''+ 'License Version' + c +'.pdf';
 32	              PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
 33	              myAttach.body = psPdf.getContentAsPdf();
 34	  
 35	              insert myAttach;
 36	              
 37	                
 38	              
 39	                         
 40	              System.debug('After attach');
 41	              System.debug(myAttach);
 42	  
 43	              
 44	              /*
 45	              ApexPages.addMessage(new ApexPages.Message
 46	  
 47	  (ApexPages.Severity.CONFIRM,'Quotation has been attached.'));
 48	              */
 49	          }
 50	          catch(Exception e) {
 51	              ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There was an error while attaching'));
 52	              System.debug('Exception');
 53	          }
 54	      }
 55	      
 56	     public PageReference QA() {
 57	     
 58	       PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + ApexPages.currentPage().getParameters().get('id'));
 59	  
 60	        Attachment myAttach = new Attachment();
 61	              myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
 62	              System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
 63	              List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
 64	              Integer c=at.size()+1;
 65	              myAttach.name = D.Account__r.Name +''+ 'License Version' + c +'.pdf';
 66	              PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
 67	              myAttach.body = psPdf.getContentAsPdf();
 68	  
 69	              //insert myAttach;
 70	                
 71	              secondPage.setRedirect(true);   
 72	              return secondPage; 
 73	              
 74	      }
 75	      public PageReference back() {
 76	          attach();
 77	          PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
 78	          pr.setRedirect(true);
 79	          System.debug('Inside back');
 80	          return pr;
 81	      }
 82	         public PageReference cancel() {
 83	         PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
 84	         pr.setRedirect(true);
 85	         System.debug('Inside back');
 86	         return pr;
 87	         }
 88	         
 89	      
 90	        
 91	       /*public String attachmentName{get; set;}
 92	        public pagereference AttachQuote(){
 93	          Pagereference pdf = page.Quotation;
 94	          blob  b=pdf.getcontent();
 95	        
 96	           attachment att = new attachment();
 97	           att.parentId = ApexPages.currentPage().getParameters().get('id') ;
 98	           att.body = b;
 99	           att.name = 'Quotation.pdf';     
 100	           insert att;
 101	           return null;
 102	           
 103	           
 104	        
 105	        }*/
 106	         /*test methods here*/
 107	       public  static testMethod void testAttachController()
 108	        {    
 109	         Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
 110	    
 111	   User U = new User(Alias = 'TUser1', Email='testItemaster1@im.com',EmailEncodingKey='UTF-8',
 112	     LastName='TestingAcc1', LanguageLocaleKey='en_US',LocaleSidKey='en_US', ProfileId =p.Id,
 113	     TimeZoneSidKey='America/Los_Angeles', UserName='testacc1@test.com');   
 114	   insert U;
 115	          
 116	          Account acc=new Account
 117	  
 118	  (Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india');
 119	          insert acc;
 120	           system.debug('########555'+ acc);
 121	          Deal__c opp=new Deal__c(Name='test12',Account__c=acc.id);
 122	          insert opp;
 123	          system.debug('########7765'+ opp);
 124	       
 125	                  
 126	          Attachment myAttach1 = new Attachment();
 127	          myAttach1.ParentId =opp.id;
 128	          myAttach1.name = 'Quotation.pdf';
 129	          myAttach1.body = blob.valueof('test');
 130	            
 131	          insert myAttach1;
 132	          
 133	          
 134	          system.debug('Attahment1'+ myAttach1);
 135	       
 136	          AttachController atc = new AttachController(new ApexPages.StandardController(opp));
 137	          system.debug('%%%%%'+atc);
 138	          PageReference pageRef = Page.Quotation;
 139	          pageRef.getParameters().put('id', String.valueOf(opp.Id));
 140	          Test.setCurrentPage(pageRef);
 141	         Blob b;
 142	  
 143	  
 144	         AttachController atc1 = new AttachController(new ApexPages.StandardController(myAttach1));
 145	          
 146	          atc1.attach();
 147	          atc.back();
 148	          atc.cancel();
 149	          //atc.QA();
 150	         
 151	          
 152	          return;
 153	         /* public PageReference QA() {
 154	       PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + 
 155	  
 156	  ApexPages.currentPage().getParameters().get('id'));
 157	          
 158	         insert myAttach1;
 159	         secondPage.setRedirect(true);   
 160	              return secondPage;
 161	              }*/
 162	       
 163	        //Attachment atchoo = [Select Id,  From Attachment where Name like 'Quotation.pdf' 
 164	  
 165	  
 166	         /* if (Test.isRunningTest())
 167	  {
 168	     b=Blob.valueOf('Test Blob String');
 169	  }
 170	  else
 171	  {
 172	    b= pageRef.getContent();
 173	  }*/
 174	  
 175	           }
 176	           
 177	        }

 when i am trying to keep atc.QA();

Error message:Methods defined as TestMethod do not support getContent call, test skipped

 

 

can u pls anybody help in solving this

public class MyAccountListCntrlr {


     // PROPERTIES
      public String subject { get; set; }
      public String body { get; set; }
      public string ccaddress{set;get;}
      public string bccaddress{set;get;}
  
     public List<ContactWrapperCls> acctList {get;set;}
     public List<String> selAccountNames{get;set;}
     public Boolean hasSelAcct {get;set;}
     public final Deal__c opp;
     public task t = new task();
     // CONSTRUCTOR
     public MyAccountListCntrlr(ApexPages.StandardController controller){
          acctList = new List<ContactWrapperCls>();
          selAccountNames= new List<String>();
          opp = [SELECT Name,id,Account__c FROM Deal__c
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
                   system.debug('opportunity@@@@@@@@@@'+opp);                  

        for(Contact a : [SELECT Name,id,Email,Account.Name,Account.Id FROM Contact where Account.id=:opp.Account__c ]){
               acctList.add(new ContactWrapperCls(a));
            Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:opp.Account__c];
          } 

     }

     // METHODS
     public void displaySelectedAccountNumbers(){
          selAccountNames.clear();
          hasSelAcct = false;
          for(ContactWrapperCls cWrapper : acctList){
               if(cWrapper.isSelected){
                    hasSelAcct = true;
                    selAccountNames.add(cWrapper.cContact.Email);
               }
          }
     }
   
      public PageReference send() {
     
     // Define the email 
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        
     // Reference the attachment page and pass in the OpportunityID
        PageReference pdf =  Page.Quotation;
        pdf.getParameters().put('id',(String)opp.id); 
        pdf.setRedirect(true);

     // Take the PDF content
            Blob b = pdf.getContent();
            Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name =opp.Name +''+ 'License Version' + c +'.pdf';
            myAttach.body = b;
            insert myAttach;
           

     // Create the email attachment
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setFileName(myAttach.name);
        efa.setBody(b);

        String[] ccAddresses = new String[] {ccaddress};
        String[] bccAddresses = new String[] {'emailtosalesforce@28wj1f7u1jx4d0rk7syg098pe8grkt8ir75tm5j0vhveterlrr.z-87epmai.z.le.sandbox.salesforce.com'};
        String addresses;
     /*   if (con[0].Email != null) {
       
            address = con[0].Email;
            // Loop through the whole list of contacts and their emails 
    
            for (Integer i = 1; i <con.size(); i++) {
                if (con[i].Email != null) {
                    address += ':' + con[i].Email;
                }
            }
        }*/
      //  addresses = con.Email;
        String[] toAddresses = selAccountNames;
        
       
        
    
     // Sets the paramaters of the email 
        email.setSubject( subject );
        email.setToAddresses( toAddresses );
            
    string UserId = UserInfo.getUserId();
    User user = [select email, IsActive from User where id = :UserId];
        

        
     //email.setCcAddresses(toAddresses);
     //email.setBccAddresses(bccaddress);
        email.setReplyTo(user.email);
        email.setBccSender(true);
        email.setHtmlBody(body);
        email.setSenderDisplayName('Salesforce');
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); 
        
        // Sends the email 
        Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

        t.subject ='Email:'+myAttach.name+ subject;
        t.status = 'Completed';
        t.description = body;
        t.type =  'Email';
        t.ActivityDate = System.today();
        t.Whatid=opp.id;

        insert t;
            
        //PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
        PageReference pr = new PageReference('/'+ ApexPages.currentPage().getParameters().get('id'));
      
        pr.setRedirect(true);
      
        System.debug('Inside back');
        return pr;
        return null;
       }

public class ContactWrapperCls {
     public Boolean isSelected {get;set;}
     public Contact cContact {get;set;}

     public ContactWrapperCls(Contact cContact){
          this.cContact = cContact;
     }
}
private static testMethod void myUnitTest() {
  Account acc=new Account(Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india');
        insert acc;
         system.debug('########555'+ acc);
        Deal__c opp=new Deal__c(Name='test12',Account__c=acc.id);
        insert opp;
        system.debug('########7765'+ opp);
     
    Contact con =  new Contact();
    con.FirstName = 'Anil';
    con.LastName = 'Dutt';
    con.Email = 'anil@swiftsetup.com';
    insert con;


    Deal__c oppNew =  new Deal__c();
    oppNew.Name = 'Test Opp';
    oppNew.Stage__c = 'Business Case';
   
    insert oppNew;


   //ApexPages.StandardController sc = new ApexPages.StandardController(con);
   //SendConfirmation sc1=new SendConfirmation (sc);
   //sc1.SendEmail();
}
}

 

 
public with sharing class AttachController {

//private ApexPages.StandardController controller { get; set; }
public List<Deal_License__c> dp{get;set;}

   public Deal__c D{get;set;}
    public AttachController(ApexPages.StandardController controller) {
     D = [Select Name,Id,Account__c,Account__r.Name,Rate__c,Total_Value__c,Account__r.BillingStreet,
                 Account__r.BillingCity,Account__r.Billingstate,Account__r.BillingPostalcode,Account__r.BillingCountry
                 from Deal__c where id=:ApexPages.currentPage().getParameters().get('id')];
    system.debug('TestDeal'+D);
    Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:D.Account__c];
    system.debug('Account%%%%%%%%%%%%%%'+acc);
    dp=[select id,Name,Deal__c,Months__c,List_Price__c,Unit_Price__c,Quantity__c,Total_Value__c from Deal_License__c where Deal__c=:D.Id];
    System.debug('DEALPRDODUCT&&&&&&&&&&'+dp);
    }
    
    public void attach() {
        try{
            Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name =D.Account__r.Name +''+ 'License Version' + c +'.pdf';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;
              
            
                       
            System.debug('After attach');
            System.debug(myAttach);

            
            /*
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Quotation has been attached.'));
            */
        }
        catch(Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There was an error while attaching'));
            System.debug('Exception');
        }
    }
    
    public PageReference QA() {
     PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + ApexPages.currentPage().getParameters().get('id'));
      Attachment myAttach = new Attachment();
            myAttach.ParentId = ApexPages.currentPage().getParameters().get('id');
            System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id'));
            List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId];
            Integer c=at.size()+1;
            myAttach.name = D.Account__r.Name +''+ 'License Version' + c +'.pdf';
            PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id'));
            myAttach.body = psPdf.getContentAsPdf();

            insert myAttach;
              
            secondPage.setRedirect(true);   
            return secondPage; 
    }
    public PageReference back() {
        attach();
        PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
        pr.setRedirect(true);
        System.debug('Inside back');
        return pr;
    }
       public PageReference cancel() {
       PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target');
       pr.setRedirect(true);
       System.debug('Inside back');
       return pr;
       }
        /*test methods here*/
     public static testMethod void testAttachController()
      {    
        //Opportunity opp=[select id from Opportunity where Name=:'Prasad Punage-'];
        Account acc=new Account(Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india' );
        insert acc;
        Deal__c opp=new Deal__c(Name='test12',Account__c='acc.id');
        insert opp;
       
        Deal_License__c dl=new Deal_License__c(Name='asd',Deal__c='opp.id');
        insert dl;        
        Attachment myAttach1 = new Attachment();
        myAttach1.ParentId =opp.id;
        myAttach1.name = 'Quotation.pdf';
        myAttach1.body = blob.valueof('test');
          
        insert myAttach1;
        system.debug('Attahment1'+ myAttach1);
        AttachController atc = new AttachController(new ApexPages.StandardController(myAttach1));
         
        atc.attach();
        atc.back();
        atc.cancel();
      }
      
      public String attachmentName{get; set;}
      public pagereference AttachQuote(){
        Pagereference pdf = page.Quotation;
        blob  b = pdf.getContent();
    
         attachment att = new attachment();
         att.parentId = ApexPages.currentPage().getParameters().get('id') ;
         att.body = b;
         att.name = 'Quotation.pdf';     
         insert att;
         
         return null;
      
      }
}

 Thanks in advance