• sachitanand kumar
  • NEWBIE
  • 40 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 7
    Replies
here is my apex class
public class wrapperexample2 {
    public wrapperexample2(ApexPages.StandardSetController controller) {        
    }
public List<Schema.contact> SList{get;set;}  //this line was not cover in test class
List<wrapper> WList=New List<wrapper>();
public List<wrapper> getLstwrapperstring()    //this line was not cover in test class
    {
        slist=[SELECT Account_name__c,Name,Phone,Title,Email FROM Contact WHERE AccountId =:ApexPages.CurrentPage().GetParameters().Get('id')];  //this line was not cover in test class
        for(Integer i=0 ;i<SList.size();i++){          //this line was not cover in test class
           WList.add(New wrapper(SList[i].name,SList[i].Account_name__c,SList[i].phone,SList[i].Title,SList[i].Email)); //this line was not cover in test class
        }
        return WList;   //this line was not cover in test class
    }
 public class wrapper
 {
     public string cid{get;set;}
     public string cName{get;set;}
     public string cPhone{get;set;}
     public string cTitle{get;set;}
      public string cEmail{get;set;}
   public wrapper(string cName,string cid,string cPhone,string cTitle,string cEmail)
     {
         this.cid=cid;
         this.cName=cName;
         this.cPhone=cPhone;
         this.cTitle=cTitle;
         this.cEmail=cEmail;
     }  
 }
}

and here is my current test class
@isTest
public class contact_pdf_test {
    
    static testMethod void data1(){
      List<contact> acc = new List<contact>();
        contact a = New contact();
        a.firstName = 'mycontact';
        a.lastName = 'mycontact';
        a.phone='124365';
        a.Title='Customer';
        a.Email ='test@gmail.com';
        acc.add(a);
        insert acc; 
              
 ApexPages.StandardSetController  sac = new ApexPages.StandardSetController (acc);  
 wrapperexample2 aop = new wrapperexample2(sac);   
     test.startTest();
        PageReference myVfPage = Page.contact_pdf;
         Test.setCurrentPage(myVfPage);
        String mycontact;
        String cid;
        String cPhone;
        String cTitle;
        String cEmail;
        wrapperexample2.wrapper sacc = new wrapperexample2.wrapper(mycontact,cid,cPhone,cTitle,cEmail);                    
     test.stopTest();
    }
 }

 
here is my trigger.
trigger autoupdate on Account (before update,before insert) {
Integer lista;
for(AggregateResult listcount :[SELECT max(customer_no__c) FROM Account]){
Decimal sumAmount = (Decimal) listcount.get('expr0');
lista =sumAmount.intValue();
 }
for(account count : trigger.new){
if(count.Type =='Customer' && count.customer_no__c == null) {   
    count.customer_no__c = lista +1 ; 
        
            }
        }
    }

 
trigger opportunitytocontactstageupdate on Opportunity (after insert, after update) {
     if(Trigger.isafter){


        List<contact> thisContact1=new List<contact>();
        set<id> thisContact=new set<id>();
        map<id,id> oppContactMap  = new map<id,id>(); 
        map<id,contact> ContactMap  = new map<id,contact>();

 List<OpportunityContactRole> oppContact = [SELECT id,OpportunityID,ContactId FROM OpportunityContactRole WHERE OpportunityID = :trigger.newmap.keyset() ];
                 
                 if(oppContact.size()>0){

                    for(OpportunityContactRole oppContacObj : oppContact){
                        oppContactMap.put(oppContacObj.OpportunityId,oppContacObj.ContactId);
                        thisContact.add(oppContacObj.Contactid);
                    }
                        for(Contact conObj :[Select Name,opportunityStageName__c from Contact Where id IN :thisContact] ){
                            ContactMap.put(conObj.id,conObj);
                        }
                            for(opportunity oppObj : trigger.new){
                                ContactMap.get(oppContactMap.get(oppObj.id)).opportunityStageName__c = oppObj.StageName;
                                thisContact1.add(contactMap.get(oppContactMap.get(oppObj.id)));
                            }
                                update thisContact1;
                 }
     }
}
Here is my apex class.
public class AccountOwnerUpdate{
    public Boolean isSelected{get;set;}
    public Account accounts{get;set;}
    public List<Account> selectedAccounts{get;set;}
   // public Boolean sendEmail{get;set;}
    public AccountOwnerUpdate(ApexPages.StandardSetController standardController)
    {   
        if(standardController.getSelected().size() == 0){
            isSelected = false;
            ApexPages.Message msg = new ApexPages.message(ApexPages.Severity.ERROR,'No Account Selected');
            ApexPages.addMessage(msg);
        }else{
            isSelected = true;
            selectedAccounts=  [SELECT id,name,ownerid from Account where id=:standardController.getSelected()];
           accounts = selectedAccounts[0]; 
           // accounts.ownerid = null; 
       }       
    }
    public PageReference updateAccount()
    {   
        for(Account a: selectedAccounts){
            a.ownerid = accounts.ownerid;
        }
        update selectedAccounts;
        return new Pagereference('/001/o');
    }

}

Here is my visual force page code. 

<apex:page standardController="Account" recordsetvar="Account" tabStyle="Account" extensions="AccountOwnerUpdate">
    <apex:pagemessages />
    <script>
        function myFunction() {      
            alert("Are you sure?");
        }
    </script>

    <apex:form rendered="{!isSelected}">
        <apex:sectionHeader subtitle="Change Owner" title="Account Edit" description="This screen allows you to transfer ownership of a Account to another user. When you transfer ownership of a Account, the new owner will own:
<br/>• all notes and attachments recorded for the current owner
<br/>• all open activities (tasks and events) owned by the current owner
<br/>
<br/>Note that completed activities and open activities owned by other users will not be transferred."/>
        <apex:pageblock mode="Edit" title="Account Edit">
            
    
           <apex:pageblockSection title="Select New Owner">
               <apex:inputField value="{!accounts.OwnerId}"/>
            </apex:pageblockSection>
           
            <apex:pageblockButtons >
                <apex:commandButton value="Save" action="{!updateAccount}" rendered="{!$User.Email == 'raj.sharma@theeclgroup.com'}"/>
                <apex:actionRegion >
                    <apex:commandButton value="Cancel" onclick="myFunction()" action="{!cancel}"/>  
               
                </apex:actionRegion>
            </apex:pageblockButtons>
        </apex:pageblock>
    </apex:form>
</apex:page>