• 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 ; 
        
            }
        }
    }

 
  1. @isTest
  2. public class OpportunityOwnerUpdate_test {
  3.     
  4.     static testMethod void data1(){
  5.         List<Opportunity> Opportunitys = new List<Opportunity>();
  6.         Opportunity a = New Opportunity();
  7.         a.Name = 'myOpportunity';
  8.         a.StageName='Stage 1 - Expressed Interest';
  9.         a.CloseDate=date.today();
  10.         Opportunitys.add(a);
  11.         insert Opportunitys;
  12.          
  13.     
  14.         ApexPages.StandardSetController  sac = new ApexPages.StandardSetController (Opportunitys);
  15.         sac.setSelected([SELECT Id, OwnerId FROM Opportunity LIMIT 2]);
  16.         OpportunityOwnerUpdate aop = new OpportunityOwnerUpdate(sac);
  17.         aop.isSelected = true;
  18.         
  19.       
  20.      aop.updateOpportunity();
  21.              
  22.     }
  23.     
  24.    static testMethod void data2(){
  25.         List<Opportunity> Opportunitys = new List<Opportunity>();
  26.         Opportunity a = New Opportunity();
  27.         a.Name = 'myOpportunity';
  28.         a.StageName='Stage 1 - Expressed Interest';
  29.         a.CloseDate=date.today();
  30.         Opportunitys.add(a);
  31.         insert Opportunitys;
  32.          
  33.     
  34.         ApexPages.StandardSetController  sac = new ApexPages.StandardSetController (Opportunitys);
  35.         OpportunityOwnerUpdate aop = new OpportunityOwnerUpdate(sac);
  36.         aop.isSelected = false;
  37.     }
  38. }
This is class
-------------------------------------------------------------------------
public class leaddup {

    public List<lead>ac{get;set;}
    public leaddup(){
    ac =[SELECT name,email FROM lead ];
    }
    public void getbyname(){
       ac=[SELECT name,count(Id) FROM lead GROUP BY name HAVING count(Id)>1];
    }
     public void getbyemail(){
       ac=[SELECT email,count(Id) FROM lead GROUP BY email HAVING count(Id)>1];
    }
}
--------------------------------------------------
This is vf
---------------------------------------------------------------------
<apex:page controller="leaddup">
    <apex:form >
        <apex:pageblock title="Duplicate lead">
            <apex:pageBlockButtons >
                <apex:commandButton value="based on name" action="{!getbyname}"/>
                <apex:commandButton value="based on email" action="{!getbyemail}"/>
            </apex:pageBlockButtons>
                    <apex:PageBlockTable value="{!ac}" var="a">
                        <apex:Column value="{!a.Name}"/>
                        <apex:Column value="{!a.email}"/> 
                    </apex:PageBlockTable>
               
        </apex:pageblock>
    </apex:form>
</apex:page>
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');
    }

}
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>
when i change  the case owner and when new case owner not do any activity on the case within 4 hour than send a alert email to the admin and new case owner
Hello everyone, plz tell me how to write the test class for this trigger listed below.

trigger trigMapFields on Lead (before update) {
   Map<Id,String> leadStatus = new Map<Id,String>();
   for(Lead lead : Trigger.new) {
        if (lead.IsConverted) {
            leadStatus.put(lead.ConvertedContactId,lead.channel__c);
        }
    }
    List<Contact> conContacts = [select Id from Contact WHERE Contact.Id IN :leadStatus.keySet()];
    for ( Contact c : conContacts) {
        c.channel__c= leadStatus.get(c.Id);
    }
    update conContacts;
}
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>