• bharath kuamar
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 24
    Questions
  • 14
    Replies

Hi,

 

 I am trying to integrate foursquare application with salesforce , and whoever checkins into foursquare gets notified in salesforce via chatter feed, i have enabled all chatter feeds ,
but when i checkin to a location in foursquare i am not getting the chatter feed , which the following error displayed,

 

Status=Moved Temporarily, StatusCode=302

Please help me out with my case, Thanks in Advance

 

Hi,

 

 I am trying to integrate foursquare application with salesforce, I have downloaded the foursquare app from appexchange, put i am not getting the oath token generated, Can anyone help me with my case who has done the integration of foursquare with salesforce..

 

 

 

Thanks in Advance

Hi,

 

 I am trying to integrate foursquare application with salesforce, I have downloaded the foursquare app from appexchange, put i am not getting the oath token generated, Can anyone help me with my case who has done the integration of foursquare with salesforce..

 

 

 

Thanks in Advance

Hi, i have written the test clss for the below class but the coverage shows only 60%, please help me to increase the coverage

global class PDFGencontroller
{
String LongDate = ' ';
String hostUrl;
String PreferId=System.currentPagereference().getParameters().get('id'); 
public PDFGencontroller()
{
 hostUrl = 'https://'+ ApexPages.currentPage().getHeaders().get('Host') +'/servlet/servlet.FileDownload?file=';
  }

public list<contact> getcontactinfo()
{
   
    system.debug('<<<<<<<<<<<<<Inside getContactInfo>>>>>>>>>>>>>>'+PreferId);
    List<Contact> con = new List<Contact>();
    Preference__c  p=[select opportunity__c from preference__c where id=:PreferId];
    OpportunityContactRole oRole = [Select ContactId from OpportunityContactRole Where OpportunityId=:p.opportunity__c ];
    con =[select firstname,lastname,Birthdate,Email,Phone from contact where id=:oRole.ContactId];
  
    return con;
    
}

 public list<Preference__c> getPreferenceInfo()
 {
   
    List<Preference__c> con1 = new List<Preference__c>();
    con1=[select name,Payment_Modes__c,payment_frequency__c,duration__c  from preference__c where id=:PreferId];
    return con1;
   }
   
   public list<commitment__c> getCommitmentInfo()
   {
    
     List<commitment__c> con2 = new List<commitment__c>();
    con2=[select name,Commitment_Type__c,Start_Date__c,End_Date__c,status__c from commitment__c where preference__c=:PreferId];
    return con2;
    
   }
   
 public list<Payment_Schedule__c> getPaymentInfo()
 {
   
    
    List<Payment_Schedule__c> con3 = new List<Payment_Schedule__c>();
    Preference__c p=[select opportunity__c from preference__c where id=:PreferId];
    con3=[select name,Payment_Start_Date__c,Payment_End_Date__c,Payment_Frequency__c,Payment_Mode__c,Amount__c  from Payment_Schedule__c where Opportunity__c =:p.opportunity__c ];
     
    return con3;

   }
   
    public String getLongDate()
     {
        Datetime cDT = System.now();
        LongDate = cDT.format('MMMM d,yyyy');
        return LongDate;
      }
      
      //test methods for the class "PDFGencontroller"
 
  static testmethod void PDFGencontroller()
      {
       
        PDFGencontroller pdfn = new PDFGencontroller();
        String hostUrl='_https://'+ 'ER201109-0000570' +'/servlet/servlet.FileDownload?file=';
        Preference__c pref = new Preference__c();
        pref.opportunity__c='00690000006yeky';
        insert pref;
        
        //OpportunityContactRole oRole = new OpportunityContactRole();
        //oRole.ContactId ='0039000000CvOJa';
       // insert oRole;

        Contact con = new Contact();
        con.firstname='test';
        con.lastname='date';
        con.Birthdate=date.today();
        con.Email='abc@abc.com';
        con.Phone ='6262323';
        insert con;
        
        //pdfn.getcontactinfo();

        Preference__c con1= new Preference__c();
        con1.Payment_Modes__c='cash';
        con1.payment_frequency__c='Annually(Full Payment)';
        con1.duration__c='3';
        insert con1;
        pdfn.getPreferenceInfo();
        commitment__c comm = new commitment__c();
        comm.Commitment_Type__c='Sponsor a child';
        comm.status__c='assigned';
        insert comm;
        
        pdfn.getCommitmentInfo();
                 //  pdfn.getPaymentInfo();  
        Payment_Schedule__c payy =new Payment_Schedule__c();
                  // payy.getPaymentInfo();  
        payy.name='ghd';
         payy.Payment_Start_Date__c=date.today();
          payy.Payment_End_Date__c=date.today();
           payy.Payment_Frequency__c='Annaul';
            payy.Payment_Mode__c='Cash';
             payy.Amount__c=50;
             insert payy;

          
        pdfn.getLongDate();
         
         
         
       Preference__c con11= new Preference__c();
       con11.opportunity__c='00690000006yeky';
       //con11.name='a0990000008T5DB';
       insert con11;
       Payment_Schedule__c payment = new Payment_Schedule__c();
       payment.name='testpayment';
       payment.Payment_Start_Date__c=date.today();
       payment.Payment_End_Date__c=date.today();
        payment.Payment_Frequency__c='Annual(fullpayment)';
        payment.Payment_Mode__c='Cash';
        payment.Amount__c=50;
         insert payment;
        // pdfn.getPaymentInfo();
     
}
}

getPaymentInfo() method and getcontactinfo()method is not covered, please help me out

 

 Error: Compile Error: Constructor not defined: [PreferenceChildController].<Constructor>() at line 410 column 39  for when i attempt to write testclass for the below class

 

public class PreferenceChildController
{
public Preference__c prefer{get;set;}
String LongDate = ' ';
public Preference__c preferobj{get;set;}
List<Commitment__c> list_commitment = new List<Commitment__c>();
private final Preference__c obj;
Public String oppId = System.currentPageReference().getParameters().get('opportunityId');
public List<ChildDetails> detailsList {get; set;}
public PreferenceChildController(ApexPages.StandardController stdController)
    {
        this.preferobj= (Preference__c)stdController.getRecord();
        
    }
   
public class ChildDetails
    {
        public String Name {get; set;}
        public String id {get;set;}
        public String regDate {get;set;}
        public String sex {get; set;}
        public String dob {get;set;}
        public String fieldOfficier{get;set;}
        public String religion {get;set;}
        public String status {get;set;}
        public Boolean isAssign {get;set;}
        
    }
    
    
    public void generateQuery()
    {
        system.debug('<<<<<<<<<<<<<>>>>>>>>>>>>>>'+preferobj.id);
        system.debug('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'+oppId);
      
        detailsList = new List<childDetails>();
         Preference__c prefObj =[Select Id, Age_From__c, Age_To__c, Sex__c, Continent__c, Country__c, Language__c, Religion__c
                                              From Preference__c Where Id=:preferobj.Id];
        List<String> list_status = new List<String>();
        list_status.add('Pooled');
        list_status.add('UnAssigned');
        list_status.add('Cancelled');
         system.debug('<<<<<<<<<<<<<>>>>>>>>>>>>>>');
        String sOQL = 'Select Age__c, Name, Child_Registration_Date__c, Comments__c, Continent__c, Country__c,'
                                + ' Date_of_Birth__c, Field_Officer__r.Name, Language__c, Religion__c, Sex__c, Status__c '
                                + ' From Child__c  Where Status__c IN :list_status';
        String whereSQOL = '';
        if (prefObj.Age_From__c != null && prefObj.Age_To__c != null)
        {
            whereSQOL = whereSQOL + ' And Age__c >='+prefObj.Age_From__c +' And Age__c <= '+ prefObj.Age_To__c;
        }
        else if (prefObj.Age_From__c == null && prefObj.Age_To__c != null)
        {
            whereSQOL = whereSQOL + ' And Age__c >='+prefObj.Age_To__c + ' And Age__c <= ' + prefObj.Age_To__c;
        }
        else if (prefObj.Age_From__c != null && prefObj.Age_To__c == null)
        {
            whereSQOL = whereSQOL + ' And Age__c >= '+ prefObj.Age_From__c + 'And Age__c <= '+prefObj.Age_From__c;
        }
        if (prefObj.Continent__c != null)
        {
            whereSQOL = whereSQOL + ' And Continent__c =\''+prefObj.Continent__c+'\'';
        }
        if (prefObj.Country__c != null)
        {
            whereSQOL = whereSQOL + ' And Country__c =\''+prefObj.Country__c+'\'';
        }
        /*else if (prefObj.Language__c != null)
        {
            whereSQOL = whereSQOL + ' And Language__c =:prefObj.Country__c';
        }*/
        if (prefObj.Religion__c != null)
        {
            whereSQOL = whereSQOL + ' And Religion__c =\''+prefObj.Religion__c+'\'';
        }
        if (prefObj.Sex__c != null)
        {
            whereSQOL = whereSQOL + ' And Sex__c =\''+prefObj.Sex__c+'\'';
        }
        
        sOQL = sOQL +  whereSQOL;
        system.debug('<<<<<<<<<<<<<>>>>>>>>>>>>>>');
        System.debug(sOQL + ' == sOQL');
        for (SObject oSobject : Database.Query(sOQL))
        {
            Child__c obj = (Child__c)oSobject;
            ChildDetails oChildDetails = new ChildDetails();
            oChildDetails.Name = obj.Name;
            oChildDetails.id = obj.Id;
            oChildDetails.regDate = obj.Child_Registration_Date__c != null ? obj.Child_Registration_Date__c.format() : '';
            oChildDetails.sex = obj.Sex__c;
            oChildDetails.dob = obj.Date_of_Birth__c != null ? obj.Date_of_Birth__c .format() : '';
            oChildDetails.fieldOfficier = obj.Field_Officer__r.Name;
            oChildDetails.religion = obj.Religion__c;
            oChildDetails.isAssign = false;
            detailsList.add( oChildDetails );
        }
    }
    public void getOpportunityId(){
    
    prefer =[select id,name,Duration__c,Opportunity__c from Preference__c where Id=:preferobj.id];
    system.debug('<<<<<arun>>>>>'+prefer.id);
    
    }
    
    
    
     
    
    
    public void manualAssignAction()
    
    {
    if(detailsList.size() == 0)
    {
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching record for given criteria.');
    ApexPages.addMessage(myMsg);
    }else{
    Preference__c p=[select opportunity__c from preference__c where id=:preferobj.id];
    system.debug('<<<<<arun>>>>>'+oppId);
     getOpportunityId();
        for (ChildDetails obj : detailsList)
        {
            if (obj.isAssign)
            {
               Commitment__c com=new Commitment__c();
               com.Preference__c=preferobj.id;
               com.Commitment_Type__c = 'Sponsor Child';
               com.Start_Date__c = Date.today();
               com.Commitments__c=p.opportunity__c ;
               com.End_Date__c =  Date.today().addMonths(Integer.valueOf(prefer.Duration__c));
               com.Child__c =obj.id;
               com.Commitment_Details__c = 'Manual Assignment';
               com.Status__c = 'Assigned';
             //system.debug('<<<<<arun>>>>>'+prefer.name+'>>>>>>>>>>>>'+prefer.ID);
               list_commitment.add(com);
               
           }
        }
    
       if ( list_commitment != null &&  list_commitment.size() > 0 ) insert list_commitment;
          generatePaymentSchedules();
        }
    }
 public void autoAssignAction(){
 if(detailsList.size() == 0)
    {
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching record for given criteria.');
    ApexPages.addMessage(myMsg);
    }else{
 
                    List<Preference__c> pref = [Select ID,
                                                    Age_From__c,
                                                    Age_To__c,
                                                    Country__c,
                                                    Continent__c,
                                                    Duration__c,
                                                    Payment_Mode__c,
                                                    Religion__c,
                                                    Sex__c,
                                                    Payment_Frequency__c
                                                From
                                                    Preference__c
                                                Where id=:preferobj.id ];
                    //System.debug('Preference Details : '+ opp1.Preference__c);
                    Preference__c p=[select opportunity__c from preference__c where id=:preferobj.id];
                   OpportunityContactRole oRole = [Select ContactId from OpportunityContactRole Where OpportunityId=:p.opportunity__c ];
                    System.debug('Contact Role : '+ oRole);
                    Opportunity opp = [Select Id, Amount from Opportunity Where Preference__c =:preferobj.id];

                    assignChild(pref.get(0), oRole.ContactId);
                       }
                     }
 
          public void assignChild(Preference__c prefObj, String contactId)
            {
                List<String> list_status = new List<String>();
                list_status.add('Pooled');
                list_status.add('UnAssigned');
                list_status.add('Cancelled');
               Preference__c p=[select opportunity__c from preference__c where id=:preferobj.id];
                //RecordType oRecordType = [Select Id From RecordType Where SObjectType= 'Child__c'];
                system.debug('<<<<<>>>>>>>');
                String sOQL = 'Select Age__c, Name, Child_Registration_Date__c, Comments__c, Continent__c, Country__c, '
                                        + ' Date_of_Birth__c, Field_Officer__r.Name, Language__c, Religion__c, Sex__c, Status__c '
                                        + ' From Child__c  Where Status__c IN :list_status';
                String whereSQOL = '';
                if (prefObj.Age_From__c != null && prefObj.Age_To__c != null)
                {
                    whereSQOL = whereSQOL + ' And Age__c >='+prefObj.Age_From__c +' And Age__c <= '+ prefObj.Age_To__c;
                }
                else if (prefObj.Age_From__c == null && prefObj.Age_To__c != null)
                {
                    whereSQOL = whereSQOL + ' And Age__c >='+prefObj.Age_To__c + ' And Age__c <= ' + prefObj.Age_To__c;
                }
                else if (prefObj.Age_From__c != null && prefObj.Age_To__c == null)
                {
                    whereSQOL = whereSQOL + ' And Age__c >= '+ prefObj.Age_From__c + 'And Age__c <= '+prefObj.Age_From__c;
                }
                if (prefObj.Continent__c != null)
                {
                    whereSQOL = whereSQOL + ' And Continent__c =\''+prefObj.Continent__c+'\'';
                }
                if (prefObj.Country__c != null)
                {
                    whereSQOL = whereSQOL + ' And Country__c =\''+prefObj.Country__c+'\'';
                }
                /*else if (prefObj.Language__c != null)
                {
                    whereSQOL = whereSQOL + ' And Language__c =:prefObj.Country__c';
                }*/
                if (prefObj.Religion__c != null)
                {
                    whereSQOL = whereSQOL + ' And Religion__c =\''+prefObj.Religion__c+'\'';
                }
                if (prefObj.Sex__c != null)
                {
                    whereSQOL = whereSQOL + ' And Sex__c =\''+prefObj.Sex__c+'\'';
                }
                 sOQL = sOQL +  whereSQOL + ' limit 1';
                system.debug('<<<<<<<<<<<<<>>>>>>>>>>>>>>'+contactId);
                System.debug(sOQL + ' == sOQL');
                List<Commitment__c> list_commitment = new List<Commitment__c>();
                for (SObject oSobject : Database.Query(sOQL))
                {
                    Child__c oChild = (Child__c)oSobject;
                    Commitment__c com=new Commitment__c();
                    com.Contact__c = contactId;
                    com.Preference__c=prefObj.ID;
                    com.Commitment_Type__c = 'Sponsor Child';
                    com.Child__c = oChild.Id;
                    com.Commitments__c = p.opportunity__c;
                    com.Start_Date__c = Date.today();
                    com.End_Date__c =  Date.today().addMonths(Integer.valueOf(prefObj.Duration__c));
                    com.Commitment_Details__c = 'Auto Assignment';
                    com.Status__c = 'Assigned';
                    list_commitment.add(com);
                }
                if ( list_commitment != null &&  list_commitment.size() > 0 ) insert list_commitment;
                 generatePaymentSchedules();
            }
 
 
 
 

            
            public void generatePaymentSchedules()
              {
                              Integer calculateduration=0;
              Preference__c p=[select opportunity__c from preference__c where id=:preferobj.id];
              
              system.debug('<<<<<bhart>>>>>');
               Opportunity oppamt =[select OppAmount__c from opportunity where id=:p.opportunity__c ];
                 system.debug('<<<<<<<<<<<venki>>>>>>>>>>');
                 Opportunity opp1=[select Preference__c from opportunity where id=:p.opportunity__c ];
                 Preference__c payPref = [select Payment_Frequency__c,Duration__c from preference__c where id=:opp1.Preference__c];
                  Integer divisionRatio = 1;
                   Integer scheduleDueDate = 0;
                    Integer PayDurationInt = Integer.valueOf(payPref.Duration__c);

                  if (payPref.Payment_Frequency__c == 'Quarterly')
                  {
                      divisionRatio = 3;
                      scheduleDueDate = 3;
                    system.debug('<<<<<<<<<<<schedule date calculation>>>>>>>>>>');
                  }
                  if (payPref.Payment_Frequency__c == 'Half-Yearly')
                  {
                      divisionRatio = 6;
                      scheduleDueDate = 6;
                    
                  }
                  if(payPref.Payment_Frequency__c =='Annually(Full Payment)')
                  {
                  calculateduration =1;
                  
                  
                  }
                  else
                  {
                  calculateduration =(PayDurationInt/divisionRatio);
                  }
                  
                  
                  List<Payment_Schedule__c> list_schedule = new List<Payment_Schedule__c>();
                  System.debug(divisionRatio + ' == paymentMode ==');
                  Double scheduleAmt = oppamt.OppAmount__c/divisionRatio;
                  Integer temp =0;
                  system.debug('<<<<<<<<111111111111>>>>>>>>>>>');
                  for (Integer j = 0; j < calculateduration ; j++)
                  {
                        
                        Payment_Schedule__c obj = new Payment_Schedule__c();
                        obj.opportunity__c = p.opportunity__c ;
                        obj.Amount__c = scheduleAmt;
                        temp+= scheduleDueDate;
                        obj.Payment_Start_Date__c = Date.today().addMonths(temp);
                        list_schedule.add(obj);
                  }
                  
                  if (list_schedule.size() > 0){
                  system.debug('<<<<<<<<222222222222>>>>>>>>>>>');
                   insert list_schedule;
                   closedOpportunity();
                    
                  
                 }
            }
            
            
 
 
  public void closedOpportunity(){
           Preference__c p=[select opportunity__c from preference__c where id=:preferobj.id];
           Opportunity opp = [select id,StageName from opportunity where id=:p.opportunity__c ];
           opp.StageName ='Closed Won';
           update opp;
          EmailReportGen();
       
 }
public void EmailReportGen()
      {
        
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        String[] toAddresses = new String[] {'arunsoftviewrmd@gmail.com'};
        Blob b;
        Messaging.SendEmailResult [] r;
        email.setSubject('Child Assigned');
        email.setToAddresses(toAddresses);
        email.setHtmlBody( 'Hi,<br/><br/> Commitment Details has attached for your reference  <br/><br/>Thank you,<br/>');
        PageReference attachPdf =  Page.PDFGenratorpage;
        String pageUrl=attachPdf.getUrl();
        pageUrl = pageUrl + '?id=' +preferobj.id;
        PageReference pdf = new Pagereference(pageUrl);
        pdf.setRedirect(true);
        b = pdf.getContentAsPdf();
        efa.setFileName('.pdf');
        efa.setBody(b);
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
        r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    }
    
    // test class for the class "PreferenceChildController"
    
    static testmethod void PreferenceChildController()
    {
    
     
    PreferenceChildController pref1 = new PreferenceChildController();
    ApexPages.StandardController sc = new ApexPages.StandardController(pref1);
            
            
         
    }
    
    
   
 
 }


Please anyone help me

Please help me with the test class for the below class,

 

global class Projectassignment{
 
 Public String paymentfrequency{get;set;}
 public String paymentModes{get;set;}
 public String Duration{get;set;}
 public Boolean isProjAssign {get; set;}
 private final Preference__c obj;
 Public String oppId = System.currentPageReference().getParameters().get('opportunityId');
 public List<ProjectDetails> detailsList {get; set;}
 
 
 public Projectassignment(ApexPages.StandardController stdController)
    {
        this.obj = (Preference__c)stdController.getRecord();
        isProjAssign = true;
        
      }
      
      public class ProjectDetails
    {
        public String Name {get; set;}
        public String id {get;set;}
        public Date StartDate{get;set;}
        public Date EndDate{get;set;}
        public String fieldOfficier{get;set;}
        public Boolean isAssign {get;set;}
        
    }

public void getProjectCodes(){

    detailsList = new List<ProjectDetails>();
    String sOQL='Select id,Name,StartDate__c,EndDate__c from Project__c';
    for(SObject oSobject : Database.Query(sOQL))
  {
      Project__c obj = (Project__c)oSobject;
      ProjectDetails Oproobj = new ProjectDetails();
      Oproobj.Name = obj.Name;
      Oproobj.StartDate=obj.StartDate__c;
      Oproobj.EndDate=obj.EndDate__c; 
      Oproobj.isAssign = false;
      detailsList.add(Oproobj);
   }
   System.debug(sOQL + ' == sOQL');
   //system.debug('<<<<<<<<<>>>>>>>'+detailsList);
}

public pagereference preferenceassign(){
 OpportunityContactRole oRole = [Select ContactId from OpportunityContactRole Where OpportunityId=:oppId];
   PageReference pageRef=New PageReference('/'+oRole.ContactId);
     pageRef.setRedirect(true);
system.debug('<<<<<<<<<<arun1>>>>>>>>>>>>>');
   List<Preference__c> preflst = new List<Preference__C>();
       for (ProjectDetails obj : detailsList){
             if (obj.isAssign)
            {
            
             Preference__c pref = new Preference__c();
             //Integer DurationInt = Integer.valueof(this.Duration);
             //DurationInt =this.Duration;
             pref.Duration__c  = this.Duration;
             pref.Payment_Modes__c =this.paymentModes;
             pref.Payment_Frequency__c =this.paymentfrequency;
             pref.Opportunity__c = oppId;
             preflst.add(pref);
       }
       
       }
           if ( preflst != null &&  preflst.size() > 0 ){
           
            insert preflst;
            updateopportunity();
           }
   return pageref;        
           
}

  public void updateopportunity(){
  system.debug('<<<<<<<<<<arun2>>>>>>>>>>>>>');
      Preference__c prefer= new Preference__c();
      prefer=[select id,name from Preference__c where Opportunity__c=:oppId];
      Opportunity lst = new Opportunity();
      lst=[select id, name,Preference__c from opportunity where id=:oppId];
      lst.Preference__c = prefer.id;
  //obj.Id = prefer.name;
      if ( lst!= null){
            update lst;
            createcommitment();
           }

  
  }

public void createcommitment(){
String str;
system.debug('<<<<<<<<<<arun3>>>>>>>>>>>>>');
   List<commitment__c>lstcom = new List<commitment__c>();
   for (ProjectDetails obj : detailsList){
        if(obj.isAssign){
      Preference__c prefer= new Preference__c();
      prefer=[select id,name,Duration__c from Preference__c where Opportunity__c=:oppId];
      Commitment__c com=new Commitment__c();
      com.Preference__c=prefer.id;
      com.Commitment_Type__c = 'Sponsor Project';
      com.Start_Date__c = Date.today();
      system.debug('<<<<<<<<<<arun31>>>>>>>>>>>>>'+prefer.Duration__c);
      com.End_Date__c =  Date.today().addMonths(Integer.valueOf(prefer.Duration__c));
      com.Project__c=obj.id;
      com.Commitment_Details__c = 'Manual Assignment';
      com.Status__c = 'Assigned';
      //com.Project__r.name =obj.Name;
      str =prefer.id;
      lstcom.add(com);
      }
}
if ( lstcom != null &&  lstcom.size() > 0 )
         {

            insert lstcom ;
            generatePaymentSchedules(str);
           
            
           }

}

 
public void generatePaymentSchedules(String PreferenceID){
  system.debug('<<<<<<<<<<arun4>>>>>>>>>>>>>');
   Integer calculateduration=0;
  Opportunity oppamt =[select OppAmount__c from opportunity where id=:oppId];
  Preference__c payPref = [select Payment_Frequency__c,Payment_Mode__c,Duration__c from preference__c where id=:PreferenceID];
                  system.debug('<<<<<<<<<<arun>>>>>>>>>>>>>');
                  Integer divisionRatio = 1;
                  Integer PayDurationInt = Integer.valueOf(payPref.Duration__c);
                  Integer scheduleDueDate = 0;
                   if (payPref.Payment_Frequency__c == 'Quarterly')
                  {
                      divisionRatio = 3;
                      scheduleDueDate = 3;
                    system.debug('<<<<<<<<<<<schedule date calculation>>>>>>>>>>');
                  }
                  
                 if (payPref.Payment_Frequency__c == 'Half-Yearly')
                  {
                      divisionRatio = 6;
                      scheduleDueDate = 6;
                    
                  }
                  if(payPref.Payment_Frequency__c =='Annually(Full Payment)')
                  {
                  calculateduration =1;
                  
                  
                  }
                  else
                  {
                  calculateduration =(PayDurationInt/divisionRatio);
                  }
                  
                  
                  List<Payment_Schedule__c> list_schedule = new List<Payment_Schedule__c>();
                 System.debug(divisionRatio + ' == paymentMode == ' + payPref.Payment_Mode__c);
                  Double scheduleAmt = oppamt.OppAmount__c/divisionRatio;
                   Integer temp =0;
                    for (Integer j = 0; j < calculateduration ; j++)
                  {
                        Payment_Schedule__c obj = new Payment_Schedule__c();
                        obj.opportunity__c =oppId  ;
                        obj.Amount__c = scheduleAmt;
                        obj.Payment_Start_Date__c = Date.today().addMonths(scheduleDueDate);
                        temp+= scheduleDueDate;
                        list_schedule.add(obj);
                  } 
                  if (list_schedule.size() > 0)
                   insert list_schedule;
                   closedOpportunity();

            }

public void closedOpportunity(){
           Opportunity opp = [select id,StageName from opportunity where id=:oppId ];
           opp.StageName ='Closed Won';
           update opp;
         // EmailReportGen();
       
 }
/*public void EmailReportGen()
      {
        
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        String[] toAddresses = new String[] {'arunsoftviewrmd@gmail.com'};
        Blob b;
        Messaging.SendEmailResult [] r;
        email.setSubject('Child Assigned');
        email.setToAddresses(toAddresses);
        email.setHtmlBody( 'Hi,<br/><br/> Commitment Details has attached for your reference  <br/><br/>Thank you,<br/>');
        PageReference attachPdf =  Page.PDFGenratorpage;
        String pageUrl=attachPdf.getUrl();
        Opportunity opp=[select Preference__c from opportunity where id =:oppId];
        system.debug('>>>>>>>>>>>>>>>>>>>>>prefer.id<<<<<<<<<<<'+opp.Preference__c);
        pageUrl = pageUrl + '?id=' +opp.Preference__c;
        PageReference pdf = new Pagereference(pageUrl);
        pdf.setRedirect(true);
        b = pdf.getContentAsPdf();
        efa.setFileName('.pdf');
        efa.setBody(b);
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
        r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
    }*/



     public pagereference cancelAction()
    
    {
   
  
   PageReference pageRef=New PageReference('/'+oppId);
      pageRef.setRedirect(true);
        return pageRef;
     
    }}

Please help me out with the test class for the below class

public class DonorDetailsController
{
        public List<CommitmentDetails> commitmentDetailsList {get;set;}
        public List<PaymentDetails> paymentDetailsList {get;set;}
        public Preference__c preObj {get;set;}
        public String contactId {get;set;}
        public String preferenceId {get;set;}
        public DonorDetailsController()
        {
            User oUser = [Select Id, ContactId From User Where Id=:UserInfo.getUserId()];
            contactId = oUser.contactId;
            preObj = new Preference__c();                
            getAllCommitmentDetails();
            getAllPaymentDetails();
        }   
        public class CommitmentDetails
        { 
            public String childName {get;Set;}
            public String projectName {get;set;}
            public String commitmentType {get;set;}
            public String commitmentStartDate {get;set;}
            public String commitmentEndDate {get;set;}
            public String perferenceId {get;set;}
            public String childId {get;set;}
        }

        public class PaymentDetails
        {
            public Double amount {get;set;}
            public Double opportunityAmount {get;set;}
            public String paymentMode {get;set;}
            public String paymentFrequency {get;set;}
            public Date paymentStartDate {get;set;}
            public Date paymentEndDate {get;set;}
            public String paymentStatus{get;set;}
        }
        public void getAllCommitmentDetails()
        {
            commitmentDetailsList = new List<CommitmentDetails>(); 
            for (Commitment__c oCommitment : [Select Id, Child__c, Child__r.Name, Start_Date__c, Project__c, 
                                                                    Project__r.Name, Commitment_Type__c, End_Date__c,
                                                                    Preference__c, Status__c From Commitment__c Where Contact__c=:contactId])
                                                                     
           //System.debug(oCommitment);
            {
                CommitmentDetails oCommitmentDetails = new CommitmentDetails();
                oCommitmentDetails.childName = oCommitment.Child__r.Name;
                oCommitmentDetails.projectName = oCommitment.Project__r.Name;
                oCommitmentDetails.commitmentType = oCommitment.Commitment_Type__c;
                oCommitmentDetails.commitmentStartDate = oCommitment.Start_Date__c != null ? oCommitment.Start_Date__c.format() : '';
                oCommitmentDetails.commitmentEndDate = oCommitment.End_Date__c != null ? oCommitment.End_Date__c.format() : ''; 
                oCommitmentDetails.perferenceId = oCommitment.Preference__c;
                oCommitmentDetails.childId = oCommitment.Child__c;
                commitmentDetailsList.add(oCommitmentDetails);
                
            }  
           
            
        }
        public void getAllPaymentDetails()
       {
            paymentDetailsList = new List<PaymentDetails>();
            String opportunityId = [Select OpportunityId From OpportunityContactRole Where ContactId=:contactId limit 1].OpportunityId;
            for (Payment_Schedule__c obj : [Select Amount__c, Payment_End_Date__c, Opportunity__r.Amount, 
                                                                      Payment_Frequency__c, Payment_Mode__c, Payment_Start_Date__c
                                                             From Payment_Schedule__c Where Opportunity__c=:opportunityId])
            {
                PaymentDetails oPaymentDetails = new PaymentDetails();
                oPaymentDetails.amount = obj.Amount__c;
                oPaymentDetails.opportunityAmount = obj.Opportunity__r.Amount;
                oPaymentDetails.paymentMode = obj.Payment_Mode__c;
                oPaymentDetails.paymentFrequency = obj.Payment_Frequency__c;
                oPaymentDetails.paymentStartDate = obj.Payment_Start_Date__c;
                oPaymentDetails.paymentEndDate = obj.Payment_End_Date__c;   
                paymentDetailsList.add(oPaymentDetails);
            }
       }
       public void loadPreference() 
      {
          preObj = [Select Id, Age_From__c, Age_To__c, Sex__c, 
                                    Continent__c, Country__c, Language__c, Religion__c
                                    From Preference__c Where Id=:preferenceId];
          System.debug( preObj  + ' == ' );                                     

      }
Thanks in advance :)
     

Please help me with this test class below as follows,

 

public class DonorProfileController
{
    public String contactId {get;set;}
    public Contact donorObj {get;set;}
    
    public DonorProfileController() {
        User oUser = [Select Id, ContactId From User Where Id=:UserInfo.getUserId()];
            contactId = oUser.contactId;
            donorObj = [Select FirstName,LastName,BirthDate,Description,Email,Phone,Mobilephone,Fax From Contact Where Id=:contactId];

    }
   
    public String firstname{ get; set;}
    
    public String lastname{ get; set; }
    
    public Date birthdate{ get; set; }

    public String description { get; set; }

    public String email { get; set; }

    public String phone { get; set; }

    public String homephone { get; set; }

    public String fax { get; set; }

    public String mobilephone { get; set; }

     public PageReference saveAction()
    {
    System.debug('saveAction()');
        
//        MyProfile__c profile=[Select Name,First_Name__c,BirthDate__c,Description__c,Fax__c,Email__c,Phone__c from MyProfile__c Where Id=:contactId ];
        MyProfile__c profile=new MyProfile__c();
        profile.Name = this.lastname;
        profile.First_Name__c = this.firstname;
        profile.BirthDate__c = this.birthdate;
        profile.Description__c=this.description;
        profile.Email__c=this.email;
        profile.Phone__c=this.phone;
        profile.Fax__c=this.fax;
        profile.Mobile__c=this.mobilephone;
        insert profile;
        return null;
        
      /*  Contact donorObj = [Select FirstName,LastName,BirthDate,Description,Email,Phone,Mobilephone,Fax From Contact Where Id=:profile.Id];
        donorObj.LastName = profile.Name;
        donorObj.FirstName = profile.First_Name__c;
        donorObj.BirthDate = profile.Birthdate__c;
        donorObj.Description=profile.Description__c;
        donorObj.Email=profile.Email__c;
        donorObj.Phone=profile.Phone__c;
        donorObj.Fax=profile.Fax__c;
        donorObj.Mobilephone=profile.Mobile__C;
        update donorObj;
        */
        
        
       }
           
          /*      
            if (pageRef == null) {
                pageRef = Page.DonorProfile;
            }
            pageRef.setRedirect(true);
            return pageRef;
            */
            
            
            //test methods written for the class DonorProfileController
            
 
 
          
          
 
}

 

thanks in advance

public class DonorProfileController
{
    public String contactId {get;set;}
    public Contact donorObj {get;set;}
    
    public DonorProfileController() {
        User oUser = [Select Id, ContactId From User Where Id=:UserInfo.getUserId()];
            contactId = oUser.contactId;
            donorObj = [Select FirstName,LastName,BirthDate,Description,Email,Phone,Mobilephone,Fax From Contact Where Id=:contactId];

    }
   
    public String firstname{ get; set; }
    
    public String lastname{ get; set; }
    
    public Date birthdate{ get; set; }

    public String description { get; set; }

    public String email { get; set; }

    public String phone { get; set; }

    public String homephone { get; set; }

    public String fax { get; set; }

    public String mobilephone { get; set; }

     public PageReference saveAction()
    {
    System.debug('saveAction()');
        
//        MyProfile__c profile=[Select Name,First_Name__c,BirthDate__c,Description__c,Fax__c,Email__c,Phone__c from MyProfile__c Where Id=:contactId ];
        MyProfile__c profile=new MyProfile__c();
        profile.Name = this.lastname;
        profile.First_Name__c = this.firstname;
        profile.BirthDate__c = this.birthdate;
        profile.Description__c=this.description;
        profile.Email__c=this.email;
        profile.Phone__c=this.phone;
        profile.Fax__c=this.fax;
        profile.Mobile__c=this.mobilephone;
        insert profile;
        return null;
        
      /*  Contact donorObj = [Select FirstName,LastName,BirthDate,Description,Email,Phone,Mobilephone,Fax From Contact Where Id=:profile.Id];
        donorObj.LastName = profile.Name;
        donorObj.FirstName = profile.First_Name__c;
        donorObj.BirthDate = profile.Birthdate__c;
        donorObj.Description=profile.Description__c;
        donorObj.Email=profile.Email__c;
        donorObj.Phone=profile.Phone__c;
        donorObj.Fax=profile.Fax__c;
        donorObj.Mobilephone=profile.Mobile__C;
        update donorObj;
        */
        
        
       }
           
          /*      
            if (pageRef == null) {
                pageRef = Page.DonorProfile;
            }
            pageRef.setRedirect(true);
            return pageRef;
            */
            
            
            //test methods written for the class DonorProfileController
            
                static testmethod void DonorProfileController()

    {
    DonorProfileController dd2 = new DonorProfileController();
        dd2.LastName ='test';
        dd2.FirstName = 'date';
        dd2.BirthDate = system.today();
        dd2.Description='description';
        dd2.Email='abc@abc.com';
        dd2.Phone='65662626';
        dd2.Fax='545454';
        dd2.Mobilephone='656562';
        dd2.saveAction();
    }
 
          
          
  
}

Class.DonorProfileController.<init>: line 9, column 1 Class.DonorProfileController.DonorProfileController: line 77, column 1

please help me out with my case

 

public class DonorProfileController
{
    public String contactId {get;set;}
    public Contact donorObj {get;set;}
    
    public DonorProfileController() {
        User oUser = [Select Id, ContactId From User Where Id=:UserInfo.getUserId()];
            contactId = oUser.contactId;
            donorObj = [Select FirstName,LastName,BirthDate,Description,Email,Phone,Mobilephone,Fax From Contact Where Id=:contactId];

    }
   
    public String firstname{ get; set; }
    
    public String lastname{ get; set; }
    
    public Date birthdate{ get; set; }

    public String description { get; set; }

    public String email { get; set; }

    public String phone { get; set; }

    public String homephone { get; set; }

    public String fax { get; set; }

    public String mobilephone { get; set; }

     public PageReference saveAction()
    {
    System.debug('saveAction()');
        
//        MyProfile__c profile=[Select Name,First_Name__c,BirthDate__c,Description__c,Fax__c,Email__c,Phone__c from MyProfile__c Where Id=:contactId ];
        MyProfile__c profile=new MyProfile__c();
        profile.Name = this.lastname;
        profile.First_Name__c = this.firstname;
        profile.BirthDate__c = this.birthdate;
        profile.Description__c=this.description;
        profile.Email__c=this.email;
        profile.Phone__c=this.phone;
        profile.Fax__c=this.fax;
        profile.Mobile__c=this.mobilephone;
        insert profile;
        return null;
        
      /*  Contact donorObj = [Select FirstName,LastName,BirthDate,Description,Email,Phone,Mobilephone,Fax From Contact Where Id=:profile.Id];
        donorObj.LastName = profile.Name;
        donorObj.FirstName = profile.First_Name__c;
        donorObj.BirthDate = profile.Birthdate__c;
        donorObj.Description=profile.Description__c;
        donorObj.Email=profile.Email__c;
        donorObj.Phone=profile.Phone__c;
        donorObj.Fax=profile.Fax__c;
        donorObj.Mobilephone=profile.Mobile__C;
        update donorObj;
        */
        
        
       }

Hi

 

Help me out with the testclass for the class

public class DonorProfileController
{
    public String contactId {get;set;}
    public Contact donorObj {get;set;}
    
    public DonorProfileController() {
        User oUser = [Select Id, ContactId From User Where Id=:UserInfo.getUserId()];
            contactId = oUser.contactId;
            donorObj = [Select FirstName,LastName,BirthDate,Description,Email,Phone,Mobilephone,Fax From Contact Where Id=:contactId];

    }
   
    public String firstname{ get; set; }
    
    public String lastname{ get; set; }
    
    public Date birthdate{ get; set; }

    public String description { get; set; }

    public String email { get; set; }

    public String phone { get; set; }

    public String homephone { get; set; }

    public String fax { get; set; }

    public String mobilephone { get; set; }

     public PageReference saveAction()
    {
    System.debug('saveAction()');
        
//        MyProfile__c profile=[Select Name,First_Name__c,BirthDate__c,Description__c,Fax__c,Email__c,Phone__c from MyProfile__c Where Id=:contactId ];
        MyProfile__c profile=new MyProfile__c();
        profile.Name = this.lastname;
        profile.First_Name__c = this.firstname;
        profile.BirthDate__c = this.birthdate;
        profile.Description__c=this.description;
        profile.Email__c=this.email;
        profile.Phone__c=this.phone;
        profile.Fax__c=this.fax;
        profile.Mobile__c=this.mobilephone;
        insert profile;
        return null;
        
      /*  Contact donorObj = [Select FirstName,LastName,BirthDate,Description,Email,Phone,Mobilephone,Fax From Contact Where Id=:profile.Id];
        donorObj.LastName = profile.Name;
        donorObj.FirstName = profile.First_Name__c;
        donorObj.BirthDate = profile.Birthdate__c;
        donorObj.Description=profile.Description__c;
        donorObj.Email=profile.Email__c;
        donorObj.Phone=profile.Phone__c;
        donorObj.Fax=profile.Fax__c;
        donorObj.Mobilephone=profile.Mobile__C;
        update donorObj;
        */
        
        
       }

public class ManualAssignController
{
    public Preference__c prefer{get;set;}
    List<Commitment__c> list_commitment = new List<Commitment__c>();
    private final Preference__c obj;
    public List<ChildDetails> detailsList {get; set;}
    
 
   
    public ManualAssignController(ApexPages.StandardController stdController)
    {
        this.obj = (Preference__c)stdController.getRecord();
        
        
    }



  
    public class ChildDetails
    {
        public String Name {get; set;}
        public String id {get;set;}
        public String regDate {get;set;}
        public String sex {get; set;}
        public String dob {get;set;}
        public String fieldOfficier{get;set;}
        public String religion {get;set;}
        public String status {get;set;}
        public Boolean isAssign {get;set;}
        
    }
    
    public void generateQuery()
    {
       
      
        detailsList = new List<childDetails>(); 
        Preference__c prefObj = obj;//[Select Id, Age_From__c, Age_To__c, Sex__c, Continent__c, Country__c, Language__c, Religion__c
                                     //         From Preference__c Where Id=:obj.Id];
        List<String> list_status = new List<String>();
        list_status.add('Pooled');
        list_status.add('UnAssigned');
        list_status.add('Cancelled');
        
        String sOQL = 'Select Age__c, Name, Child_Registration_Date__c, Comments__c, Continent__c, Country__c, '
                                + ' Date_of_Birth__c, Field_Officer__r.Name, Language__c, Religion__c, Sex__c, Status__c '
                                + ' From Child__c  Where Status__c IN :list_status';
        String whereSQOL = '';
        if (prefObj.Age_From__c != null && prefObj.Age_To__c != null)
        {
            whereSQOL = whereSQOL + ' And Age__c >='+prefObj.Age_From__c +' And Age__c <= '+ prefObj.Age_To__c;
        }
        else if (prefObj.Age_From__c == null && prefObj.Age_To__c != null)
        {
            whereSQOL = whereSQOL + ' And Age__c >='+prefObj.Age_To__c + ' And Age__c <= ' + prefObj.Age_To__c;
        }
        else if (prefObj.Age_From__c != null && prefObj.Age_To__c == null)
        {
            whereSQOL = whereSQOL + ' And Age__c >= '+ prefObj.Age_From__c + 'And Age__c <= '+prefObj.Age_From__c;
        }
        if (prefObj.Continent__c != null)
        {
            whereSQOL = whereSQOL + ' And Continent__c =\''+prefObj.Continent__c+'\'';
        }
        if (prefObj.Country__c != null)
        {
            whereSQOL = whereSQOL + ' And Country__c =\''+prefObj.Country__c+'\'';
        }
        /*else if (prefObj.Language__c != null)
        {
            whereSQOL = whereSQOL + ' And Language__c =:prefObj.Country__c';
        }*/
        if (prefObj.Religion__c != null)
        {
            whereSQOL = whereSQOL + ' And Religion__c =\''+prefObj.Religion__c+'\'';
        }
        if (prefObj.Sex__c != null)
        {
            whereSQOL = whereSQOL + ' And Sex__c =\''+prefObj.Sex__c+'\'';
        }
        
        sOQL = sOQL +  whereSQOL;
        system.debug('<<<<<<<<<<<<<>>>>>>>>>>>>>>');
        System.debug(sOQL + ' == sOQL');
        for (SObject oSobject : Database.Query(sOQL))
        {
            Child__c obj = (Child__c)oSobject;
            ChildDetails oChildDetails = new ChildDetails();
            oChildDetails.Name = obj.Name;
            oChildDetails.id = obj.Id;
            oChildDetails.regDate = obj.Child_Registration_Date__c != null ? obj.Child_Registration_Date__c.format() : '';
            oChildDetails.sex = obj.Sex__c;
            oChildDetails.dob = obj.Date_of_Birth__c != null ? obj.Date_of_Birth__c .format() : '';
            oChildDetails.fieldOfficier = obj.Field_Officer__r.Name;
            oChildDetails.religion = obj.Religion__c;
            oChildDetails.isAssign = false;
            detailsList.add( oChildDetails );
        }
    }
    
    public void getQueryPrefID(){
     prefer =[select id,name,Duration__c,Opportunity__c from Preference__c where Id=:obj.Id limit 1];
    }
    
    public pagereference assignAction()
    
    {
     getQueryPrefID();
     Opportunity oppid =[select id,contact__c from opportunity where id=:prefer.Opportunity__c];
     PageReference pageRef=New PageReference('/'+oppid.contact__c);
     pageRef.setRedirect(true);
      for (ChildDetails obj : detailsList)
        {
            if (obj.isAssign)
            {
               Commitment__c com=new Commitment__c();
               com.Preference__c=prefer.id;
               com.Commitment_Type__c = 'Sponsor Child';
               com.Start_Date__c = Date.today();
               com.End_Date__c =  Date.today().addMonths(Integer.valueOf(prefer.Duration__c));
               com.Child__c =obj.id;
               com.Commitment_Details__c = 'Manual Assignment';
               com.Status__c = 'Assigned';
                
               //system.debug('<<<<<arun>>>>>'+prefer.name+'>>>>>>>>>>>>'+prefer.ID);
               list_commitment.add(com);
               
             
            }
        }
    
       if ( list_commitment != null &&  list_commitment.size() > 0 ) insert list_commitment;
          generatePaymentSchedules(prefer.id);
       return pageRef;  
    }
    
    
              public void generatePaymentSchedules(String PreferenceID)
              {
                 getQueryPrefID();
                 Opportunity oppamt =[select OppAmount__c from opportunity where id=:prefer.Opportunity__c];
                 system.debug('<<<<<<<<<<<venki>>>>>>>>>>');
                 Preference__c payPref = [select Payment_Frequency__c,Payment_Mode__c,Duration__c from preference__c where id=:PreferenceID];
                  Integer divisionRatio = 1;
                    Integer PayDurationInt = Integer.valueOf(payPref.Duration__c);
                  if (payPref.Payment_Frequency__c == 'Monthly')
                  {
                      divisionRatio = 1;
                  }
                  if (payPref.Payment_Frequency__c == 'Quarterly')
                  {
                      divisionRatio = 3;
                    
                
                      if (PayDurationInt  < 6)
                      {
                            divisionRatio = 1;
                      } 
                  }
                  if (payPref.Payment_Frequency__c == 'Half-Yearly')
                  {
                      divisionRatio = 6;
                     if (PayDurationInt < 12)
                      {
                            divisionRatio = 1;
                      }
                  }
                  if (payPref.Payment_Frequency__c == 'Annually')
                  {
                      divisionRatio = 12;
                      if (PayDurationInt  < 12)
                      {
                            divisionRatio = 1;
                      }
                  }
                  List<Payment_Schedule__c> list_schedule = new List<Payment_Schedule__c>();
                  System.debug(divisionRatio + ' == paymentMode == ' + payPref.Payment_Mode__c);
                  Double scheduleAmt = oppamt.OppAmount__c/divisionRatio;
                  Integer scheduleDueDate = 0;
                  for (Integer j = 0; j < (PayDurationInt /divisionRatio); j++)
                  {
                        Payment_Schedule__c obj = new Payment_Schedule__c();
                        obj.opportunity__c = prefer.Opportunity__c;
                        obj.Amount__c = scheduleAmt;
                        scheduleDueDate = scheduleDueDate + divisionRatio;
                        obj.Payment_Start_Date__c = Date.today().addMonths(scheduleDueDate);
                        list_schedule.add(obj);
                  } 
                  if (list_schedule.size() > 0) insert list_schedule;
                  closedOpportunity();
            }
 
    public void closedOpportunity(){
          getQueryPrefID();
          Opportunity opp = [select id,StageName from opportunity where id=:prefer.Opportunity__c];
          opp.StageName ='Closed Won';
           update opp;
        
        }
    
    
    
    public pagereference cancelAction()
    
    {
    getQueryPrefID();
    PageReference pageRef=New PageReference('/'+prefer.Opportunity__c);
      pageRef.setRedirect(true);
        return pageRef;
     
    }
    
}

Please helpme

Hi,

 

Please help me with the test class

 

public class DonorProfileController
{

    public String contactId {get;set;}
    public Contact donorObj {get;set;}
    
    public DonorProfileController() {
        User oUser = [Select Id, ContactId From User Where Id=:UserInfo.getUserId()];
            contactId = oUser.contactId;
            donorObj = [Select FirstName,LastName,BirthDate,Description,Email,Phone,Mobilephone,Fax From Contact Where Id=:contactId];

    }
   
    public String firstname{ get; set; }
    
    public String lastname{ get; set; }
    
    public Date birthdate{ get; set; }

    public String description { get; set; }

    public String email { get; set; }

    public String phone { get; set; }

    public String homephone { get; set; }

    public String fax { get; set; }

    public String mobilephone { get; set; }

     public PageReference saveAction()
    {
    System.debug('saveAction()');
        
//        MyProfile__c profile=[Select Name,First_Name__c,BirthDate__c,Description__c,Fax__c,Email__c,Phone__c from MyProfile__c Where Id=:contactId ];
        MyProfile__c profile=new MyProfile__c();
        profile.Name = this.lastname;
        profile.First_Name__c = this.firstname;
        profile.BirthDate__c = this.birthdate;
        profile.Description__c=this.description;
        profile.Email__c=this.email;
        profile.Phone__c=this.phone;
        profile.Fax__c=this.fax;
        profile.Mobile__c=this.mobilephone;
        insert profile;
        return null;
       
public with sharing class DemoRole 
{
    public List<OppData> list_opportunity {get; set;}
    public DemoRole()
    {
        list_opportunity = new List<OppData>();
        Set<Id> set_ownerId = new Set<Id>();
        List<OpportunityShare> oppList=[select Id,OpportunityId, Opportunity.Name, Opportunity.Owner.Name, UserOrGroupId from OpportunityShare Where Opportunity.Owner.UserRole.Name='UK Junior Representative'];
if(oppList!=null)
{
        for (OpportunityShare opp :oppList )
        {
               list_opportunity.add( getOppData(opp) );   
        }
}
getOppData(null);
        }
public static OppData getOppData(OpportunityShare opp)
{
            OppData oppData = new OppData();
    if(opp==null)
    System.debug('No record Found......');
            oppData.oppId = opp.OpportunityId;
            oppData.ownerName = opp.Opportunity.Owner.Name;
            oppData.managerName = opp.UserOrGroupId;
            oppData.oppName  = opp.Opportunity.Name;
    return oppData;
}
         
    
    public class OppData
    {
        public String oppId { get; set; }
        public String ownerName { get; set; }
        public String managerName { get; set; }
        public String oppName { get; set; }
    }
    
 // test class for the class demorole
 
 static testMethod void DemoRole ()
 {
DemoRole drule=new DemoRole();
OpportunityShare opp=new OpportunityShare();
opp.OpportunityId='00690000006yeky';
//opp.Opportunity.Owner.Name='sample owner';
opp.UserorGroupId='00690000006yeky';
opp.Opportunity.Name='test opportunity';
getOppData(opp);
 }
    
}

the test failure shows

Class.DemoRole.getOppData: line 23, column 1 Class.DemoRole.<init>: line 16, column 1 Class.DemoRole.DemoRole: line 43, column 1
please help me with this.........

Hi,

 

 Please help me writing the testclass below as follows,

 

public class DonorDetailsController
{
        public List<CommitmentDetails> commitmentDetailsList {get;set;}
        public List<PaymentDetails> paymentDetailsList {get;set;}
        public Preference__c preObj {get;set;}
        public String contactId {get;set;}
        public String preferenceId {get;set;}
        public DonorDetailsController()
        {
            User oUser = [Select Id, ContactId From User Where Id=:UserInfo.getUserId()];
            contactId = oUser.contactId;
            preObj = new Preference__c();                
            getAllCommitmentDetails();
            getAllPaymentDetails();
        }   
        public class CommitmentDetails
        { 
            public String childName {get;Set;}
            public String projectName {get;set;}
            public String commitmentType {get;set;}
            public String commitmentStartDate {get;set;}
            public String commitmentEndDate {get;set;}
            public String perferenceId {get;set;}
            public String childId {get;set;}
        }

        public class PaymentDetails
        {
            public Double amount {get;set;}
            public Double opportunityAmount {get;set;}
            public String paymentMode {get;set;}
            public String paymentFrequency {get;set;}
            public Date paymentStartDate {get;set;}
            public Date paymentEndDate {get;set;}
            public String paymentStatus{get;set;}
        }
        public void getAllCommitmentDetails()
        {
            commitmentDetailsList = new List<CommitmentDetails>(); 
            for (Commitment__c oCommitment : [Select Id, Child__c, Child__r.Name, Start_Date__c, Project__c, 
                                                                    Project__r.Name, Commitment_Type__c, End_Date__c,
                                                                    Preference__c, Status__c From Commitment__c Where Contact__c=:contactId])
                                                                     
           //System.debug(oCommitment);
            {
                CommitmentDetails oCommitmentDetails = new CommitmentDetails();
                oCommitmentDetails.childName = oCommitment.Child__r.Name;
                oCommitmentDetails.projectName = oCommitment.Project__r.Name;
                oCommitmentDetails.commitmentType = oCommitment.Commitment_Type__c;
                oCommitmentDetails.commitmentStartDate = oCommitment.Start_Date__c != null ? oCommitment.Start_Date__c.format() : '';
                oCommitmentDetails.commitmentEndDate = oCommitment.End_Date__c != null ? oCommitment.End_Date__c.format() : ''; 
                oCommitmentDetails.perferenceId = oCommitment.Preference__c;
                oCommitmentDetails.childId = oCommitment.Child__c;
                commitmentDetailsList.add(oCommitmentDetails);
                
            }  
           
            
        }
        public void getAllPaymentDetails()
       {
            paymentDetailsList = new List<PaymentDetails>();
            String opportunityId = [Select OpportunityId From OpportunityContactRole Where ContactId=:contactId limit 1].OpportunityId;
            for (Payment_Schedule__c obj : [Select Amount__c, Payment_End_Date__c, Opportunity__r.Amount, 
                                                                      Payment_Frequency__c, Payment_Mode__c, Payment_Start_Date__c
                                                             From Payment_Schedule__c Where Opportunity__c=:opportunityId])
            {
                PaymentDetails oPaymentDetails = new PaymentDetails();
                oPaymentDetails.amount = obj.Amount__c;
                oPaymentDetails.opportunityAmount = obj.Opportunity__r.Amount;
                oPaymentDetails.paymentMode = obj.Payment_Mode__c;
                oPaymentDetails.paymentFrequency = obj.Payment_Frequency__c;
                oPaymentDetails.paymentStartDate = obj.Payment_Start_Date__c;
                oPaymentDetails.paymentEndDate = obj.Payment_End_Date__c;   
                paymentDetailsList.add(oPaymentDetails);
            }
       }
       public void loadPreference() 
      {
          preObj = [Select Id, Age_From__c, Age_To__c, Sex__c, 
                                    Continent__c, Country__c, Language__c, Religion__c
                                    From Preference__c Where Id=:preferenceId];
          System.debug( preObj  + ' == ' );                                     

      }

    }

Hi,

 

 can anyone help me writing test class for the below class

 

global class PDFGencontroller{
String LongDate = ' ';
String hostUrl;
String PreferId=System.currentPagereference().getParameters().get('id'); 
public PDFGencontroller()
{
 hostUrl = 'https://'+ ApexPages.currentPage().getHeaders().get('Host') +'/servlet/servlet.FileDownload?file=';
  }

public list<contact> getcontactinfo(){
   
    system.debug('<<<<<<<<<<<<<Inside getContactInfo>>>>>>>>>>>>>>'+PreferId);
    List<Contact> con = new List<Contact>();
    Preference__c  p=[select opportunity__c from preference__c where id=:PreferId];
    OpportunityContactRole oRole = [Select ContactId from OpportunityContactRole Where OpportunityId=:p.opportunity__c ];
    con =[select firstname,lastname,Birthdate,Email,Phone from contact where id=:oRole.ContactId];
    return con;
    
}

 public list<Preference__c> getPreferenceInfo(){
   
    List<Preference__c> con1 = new List<Preference__c>();
    con1=[select name,Payment_Modes__c,payment_frequency__c,duration__c  from preference__c where id=:PreferId];
    return con1;
   }
   
   public list<commitment__c> getCommitmentInfo(){
    
    
    List<commitment__c> con2 = new List<commitment__c>();
    con2=[select name,Commitment_Type__c,Start_Date__c,End_Date__c,status__c from commitment__c where preference__c=:PreferId];
    return con2;
    
   }
   
 public list<Payment_Schedule__c> getPaymentInfo(){
    
    
    List<Payment_Schedule__c> con3 = new List<Payment_Schedule__c>();
    Preference__c p=[select opportunity__c from preference__c where id=:PreferId];
    con3=[select name,Payment_Start_Date__c,Payment_End_Date__c,Payment_Frequency__c,Payment_Mode__c,Amount__c  from Payment_Schedule__c where Opportunity__c =:p.opportunity__c ];
    
    return con3;
   }
   
    public String getLongDate() {
        Datetime cDT = System.now();
        LongDate = cDT.format('MMMM d,yyyy');
        return LongDate;
      }
     

Hi,

 

 I have the following  class for which i have written the test class

public with sharing class DonorRegisterController {
 
    public DonorRegisterController () {
    }
    public String firstname {get; set;}
    public String LastName {get; set;}
    public String Company {get; set;}
    public String email {get; set;}
    public String address{get; set;}
       public String Status {get; set;}
    public String country{get; set;}
    public String mobilephone{get; set;}
    public String phone{get; set;}
    public String website{get; set;}
    public String fax{get; set;}
    
    public void registerUser() {

        Lead l = new Lead();
        l.firstname = firstname;
        l.LastName= lastname;
        l.Company= Company;
        l.Email = email;
          l.country= country;
                 l.Status = Status ;
         //l.Address=address;

         l.MobilePhone=mobilephone;
        l.Phone=phone;
        l.website=Website;
        l.Fax=fax;
        l.LeadSOurce='Web';
        insert l;
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Registered Succesfully !'));

    }

the test class for the above class is

static testmethod void DonorRegisterController()
    {

    DonorRegisterController registerdate = new DonorRegisterController();
        
       Lead l1 = new Lead();
      l1.firstname = 'test';
       l1.LastName = 'data';
        l1.Company = 'msat';
        l1.Email = 'abc@abc.com';
        l1.company = 'Msat';
        l1.MobilePhone='9895929516';
        l1.Phone='54545451';
        l1.website='www.salesforce.com';
        l1.Fax='45454545';
        l1.LeadSOurce='Web';
        l1.Status ='qualified';
      l1.country ='usa';
        insert l1;
        
      
         Lead l2 = new Lead();
      l2.firstname = 'test';
       l2.LastName = 'dates';
        l2.Company = 'Msat';
        l2.Email = 'abc@abc.com';
        l2.MobilePhone='9895929516';
        l2.Phone='54545451';
        l2.website='www.salesforce.com';
        l2.Fax='45454545';
        l2.Status ='qualified';
       l2.country ='india';
        l2.LeadSOurce='Web';
        insert l2 ;
          registerdate.registerUser();
    
    }
    
}
i have a validation rule on lead making that the coutnry field under lead should be mandatory, but when i fire the test classs it throws an exception that country is missing which i have called,can anyone help me with this case

Help me out with the test classs for the trigger below ,

 

trigger updateContact on MyProfile__c (after insert) {
        MyProfile__c profile=new MyProfile__c();
        Contact donorObj=new Contact();
        donorObj.LastName = profile.Name;
        donorObj.FirstName = profile.First_Name__c;
        donorObj.BirthDate = profile.Birthdate__c;
        donorObj.Description=profile.Description__c;
        donorObj.Email=profile.Email__c;
        donorObj.Phone=profile.Phone__c;
        donorObj.Fax=profile.Fax__c;
        donorObj.Mobilephone=profile.Mobile__C;
        update donorObj;
       
}

Help me with the testclass for the  trigger

 

trigger updateOpportunity on Preference__c (after insert)
{
    if (Trigger.isAfter)
    {
        Map<String, String> map_pref = new Map<String, String>();
        for (Preference__c oPref : Trigger.new)
        {
          map_pref.put(oPref.Opportunity__c, oPref.Id);    
        }
        List<Opportunity> list_opp = new List<Opportunity>();
        for (Opportunity opp : [Select Id, Preference__c,
                                 Preference_Associated__c
                               From
                                 Opportunity
                               Where
                                 Id IN : map_pref.keySet()])
        {
            opp.Preference__c = map_pref.get(opp.Id); 
            opp.Preference_Associated__c = true; 
            list_opp.add(opp);     
        }
        if (list_opp.size() > 0) update list_opp;                                   
    }   
}

can anyone help me writing test class for the following trigger below

trigger displayCommitment on Commitment__c (after insert)
{
   if (Trigger.isAfter)
   {
       Set<String> set_string = new Set<String>();
       Map<String, Commitment__c> map_pref = new Map<String,Commitment__c>(); 
       for ( Commitment__c cmmit : Trigger.new )
       {
           if (cmmit.Preference__c != null)
           {
               set_string.add(cmmit.Preference__c);
               map_pref.put(cmmit.Preference__c, cmmit);
           }
       }
       if (set_string.size() > 0)
       {
           List<Opportunity> list_opportunity = new List<Opportunity>();
           for (Opportunity obj : [Select Id, Preference__c From Opportunity Where Preference__c In : set_string])
           {
             Commitment__c cObj = map_pref.get(obj.Preference__c);
             Opportunity updateOpportunity = obj;
             //updateOpportunity.Commitment_Name__c = cObj.Name;
             updateOpportunity.Commitment_TypePreference__c = cObj.Commitment_Type__c;
             updateOpportunity.StartDate__c = cObj.Start_Date__c;
             updateOpportunity.EndDate__c =cObj.End_Date__c;
             updateOpportunity.Commitment_Details__c =cObj.Commitment_Details__c;
             updateOpportunity.contact__c =cObj.Contact__r.name;
             updateOpportunity.Status__c =cObj.Status__c;
             updateOpportunity.Child__c =cObj.Child__r.name;
             system.debug('<<<<<<<<test>>>>>>'+cObj.Child__r.name);
             list_opportunity.add(updateOpportunity);
             System.Debug('<<Sucess>>');
           } 
           if (list_opportunity != null && list_opportunity.size() > 0) update list_opportunity;
       }
   }
   }

Hi, i have written the test clss for the below class but the coverage shows only 60%, please help me to increase the coverage

global class PDFGencontroller
{
String LongDate = ' ';
String hostUrl;
String PreferId=System.currentPagereference().getParameters().get('id'); 
public PDFGencontroller()
{
 hostUrl = 'https://'+ ApexPages.currentPage().getHeaders().get('Host') +'/servlet/servlet.FileDownload?file=';
  }

public list<contact> getcontactinfo()
{
   
    system.debug('<<<<<<<<<<<<<Inside getContactInfo>>>>>>>>>>>>>>'+PreferId);
    List<Contact> con = new List<Contact>();
    Preference__c  p=[select opportunity__c from preference__c where id=:PreferId];
    OpportunityContactRole oRole = [Select ContactId from OpportunityContactRole Where OpportunityId=:p.opportunity__c ];
    con =[select firstname,lastname,Birthdate,Email,Phone from contact where id=:oRole.ContactId];
  
    return con;
    
}

 public list<Preference__c> getPreferenceInfo()
 {
   
    List<Preference__c> con1 = new List<Preference__c>();
    con1=[select name,Payment_Modes__c,payment_frequency__c,duration__c  from preference__c where id=:PreferId];
    return con1;
   }
   
   public list<commitment__c> getCommitmentInfo()
   {
    
     List<commitment__c> con2 = new List<commitment__c>();
    con2=[select name,Commitment_Type__c,Start_Date__c,End_Date__c,status__c from commitment__c where preference__c=:PreferId];
    return con2;
    
   }
   
 public list<Payment_Schedule__c> getPaymentInfo()
 {
   
    
    List<Payment_Schedule__c> con3 = new List<Payment_Schedule__c>();
    Preference__c p=[select opportunity__c from preference__c where id=:PreferId];
    con3=[select name,Payment_Start_Date__c,Payment_End_Date__c,Payment_Frequency__c,Payment_Mode__c,Amount__c  from Payment_Schedule__c where Opportunity__c =:p.opportunity__c ];
     
    return con3;

   }
   
    public String getLongDate()
     {
        Datetime cDT = System.now();
        LongDate = cDT.format('MMMM d,yyyy');
        return LongDate;
      }
      
      //test methods for the class "PDFGencontroller"
 
  static testmethod void PDFGencontroller()
      {
       
        PDFGencontroller pdfn = new PDFGencontroller();
        String hostUrl='_https://'+ 'ER201109-0000570' +'/servlet/servlet.FileDownload?file=';
        Preference__c pref = new Preference__c();
        pref.opportunity__c='00690000006yeky';
        insert pref;
        
        //OpportunityContactRole oRole = new OpportunityContactRole();
        //oRole.ContactId ='0039000000CvOJa';
       // insert oRole;

        Contact con = new Contact();
        con.firstname='test';
        con.lastname='date';
        con.Birthdate=date.today();
        con.Email='abc@abc.com';
        con.Phone ='6262323';
        insert con;
        
        //pdfn.getcontactinfo();

        Preference__c con1= new Preference__c();
        con1.Payment_Modes__c='cash';
        con1.payment_frequency__c='Annually(Full Payment)';
        con1.duration__c='3';
        insert con1;
        pdfn.getPreferenceInfo();
        commitment__c comm = new commitment__c();
        comm.Commitment_Type__c='Sponsor a child';
        comm.status__c='assigned';
        insert comm;
        
        pdfn.getCommitmentInfo();
                 //  pdfn.getPaymentInfo();  
        Payment_Schedule__c payy =new Payment_Schedule__c();
                  // payy.getPaymentInfo();  
        payy.name='ghd';
         payy.Payment_Start_Date__c=date.today();
          payy.Payment_End_Date__c=date.today();
           payy.Payment_Frequency__c='Annaul';
            payy.Payment_Mode__c='Cash';
             payy.Amount__c=50;
             insert payy;

          
        pdfn.getLongDate();
         
         
         
       Preference__c con11= new Preference__c();
       con11.opportunity__c='00690000006yeky';
       //con11.name='a0990000008T5DB';
       insert con11;
       Payment_Schedule__c payment = new Payment_Schedule__c();
       payment.name='testpayment';
       payment.Payment_Start_Date__c=date.today();
       payment.Payment_End_Date__c=date.today();
        payment.Payment_Frequency__c='Annual(fullpayment)';
        payment.Payment_Mode__c='Cash';
        payment.Amount__c=50;
         insert payment;
        // pdfn.getPaymentInfo();
     
}
}

getPaymentInfo() method and getcontactinfo()method is not covered, please help me out

 

 Error: Compile Error: Constructor not defined: [PreferenceChildController].<Constructor>() at line 410 column 39  for when i attempt to write testclass for the below class

 

public class PreferenceChildController
{
public Preference__c prefer{get;set;}
String LongDate = ' ';
public Preference__c preferobj{get;set;}
List<Commitment__c> list_commitment = new List<Commitment__c>();
private final Preference__c obj;
Public String oppId = System.currentPageReference().getParameters().get('opportunityId');
public List<ChildDetails> detailsList {get; set;}
public PreferenceChildController(ApexPages.StandardController stdController)
    {
        this.preferobj= (Preference__c)stdController.getRecord();
        
    }
   
public class ChildDetails
    {
        public String Name {get; set;}
        public String id {get;set;}
        public String regDate {get;set;}
        public String sex {get; set;}
        public String dob {get;set;}
        public String fieldOfficier{get;set;}
        public String religion {get;set;}
        public String status {get;set;}
        public Boolean isAssign {get;set;}
        
    }
    
    
    public void generateQuery()
    {
        system.debug('<<<<<<<<<<<<<>>>>>>>>>>>>>>'+preferobj.id);
        system.debug('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'+oppId);
      
        detailsList = new List<childDetails>();
         Preference__c prefObj =[Select Id, Age_From__c, Age_To__c, Sex__c, Continent__c, Country__c, Language__c, Religion__c
                                              From Preference__c Where Id=:preferobj.Id];
        List<String> list_status = new List<String>();
        list_status.add('Pooled');
        list_status.add('UnAssigned');
        list_status.add('Cancelled');
         system.debug('<<<<<<<<<<<<<>>>>>>>>>>>>>>');
        String sOQL = 'Select Age__c, Name, Child_Registration_Date__c, Comments__c, Continent__c, Country__c,'
                                + ' Date_of_Birth__c, Field_Officer__r.Name, Language__c, Religion__c, Sex__c, Status__c '
                                + ' From Child__c  Where Status__c IN :list_status';
        String whereSQOL = '';
        if (prefObj.Age_From__c != null && prefObj.Age_To__c != null)
        {
            whereSQOL = whereSQOL + ' And Age__c >='+prefObj.Age_From__c +' And Age__c <= '+ prefObj.Age_To__c;
        }
        else if (prefObj.Age_From__c == null && prefObj.Age_To__c != null)
        {
            whereSQOL = whereSQOL + ' And Age__c >='+prefObj.Age_To__c + ' And Age__c <= ' + prefObj.Age_To__c;
        }
        else if (prefObj.Age_From__c != null && prefObj.Age_To__c == null)
        {
            whereSQOL = whereSQOL + ' And Age__c >= '+ prefObj.Age_From__c + 'And Age__c <= '+prefObj.Age_From__c;
        }
        if (prefObj.Continent__c != null)
        {
            whereSQOL = whereSQOL + ' And Continent__c =\''+prefObj.Continent__c+'\'';
        }
        if (prefObj.Country__c != null)
        {
            whereSQOL = whereSQOL + ' And Country__c =\''+prefObj.Country__c+'\'';
        }
        /*else if (prefObj.Language__c != null)
        {
            whereSQOL = whereSQOL + ' And Language__c =:prefObj.Country__c';
        }*/
        if (prefObj.Religion__c != null)
        {
            whereSQOL = whereSQOL + ' And Religion__c =\''+prefObj.Religion__c+'\'';
        }
        if (prefObj.Sex__c != null)
        {
            whereSQOL = whereSQOL + ' And Sex__c =\''+prefObj.Sex__c+'\'';
        }
        
        sOQL = sOQL +  whereSQOL;
        system.debug('<<<<<<<<<<<<<>>>>>>>>>>>>>>');
        System.debug(sOQL + ' == sOQL');
        for (SObject oSobject : Database.Query(sOQL))
        {
            Child__c obj = (Child__c)oSobject;
            ChildDetails oChildDetails = new ChildDetails();
            oChildDetails.Name = obj.Name;
            oChildDetails.id = obj.Id;
            oChildDetails.regDate = obj.Child_Registration_Date__c != null ? obj.Child_Registration_Date__c.format() : '';
            oChildDetails.sex = obj.Sex__c;
            oChildDetails.dob = obj.Date_of_Birth__c != null ? obj.Date_of_Birth__c .format() : '';
            oChildDetails.fieldOfficier = obj.Field_Officer__r.Name;
            oChildDetails.religion = obj.Religion__c;
            oChildDetails.isAssign = false;
            detailsList.add( oChildDetails );
        }
    }
    public void getOpportunityId(){
    
    prefer =[select id,name,Duration__c,Opportunity__c from Preference__c where Id=:preferobj.id];
    system.debug('<<<<<arun>>>>>'+prefer.id);
    
    }
    
    
    
     
    
    
    public void manualAssignAction()
    
    {
    if(detailsList.size() == 0)
    {
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching record for given criteria.');
    ApexPages.addMessage(myMsg);
    }else{
    Preference__c p=[select opportunity__c from preference__c where id=:preferobj.id];
    system.debug('<<<<<arun>>>>>'+oppId);
     getOpportunityId();
        for (ChildDetails obj : detailsList)
        {
            if (obj.isAssign)
            {
               Commitment__c com=new Commitment__c();
               com.Preference__c=preferobj.id;
               com.Commitment_Type__c = 'Sponsor Child';
               com.Start_Date__c = Date.today();
               com.Commitments__c=p.opportunity__c ;
               com.End_Date__c =  Date.today().addMonths(Integer.valueOf(prefer.Duration__c));
               com.Child__c =obj.id;
               com.Commitment_Details__c = 'Manual Assignment';
               com.Status__c = 'Assigned';
             //system.debug('<<<<<arun>>>>>'+prefer.name+'>>>>>>>>>>>>'+prefer.ID);
               list_commitment.add(com);
               
           }
        }
    
       if ( list_commitment != null &&  list_commitment.size() > 0 ) insert list_commitment;
          generatePaymentSchedules();
        }
    }
 public void autoAssignAction(){
 if(detailsList.size() == 0)
    {
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching record for given criteria.');
    ApexPages.addMessage(myMsg);
    }else{
 
                    List<Preference__c> pref = [Select ID,
                                                    Age_From__c,
                                                    Age_To__c,
                                                    Country__c,
                                                    Continent__c,
                                                    Duration__c,
                                                    Payment_Mode__c,
                                                    Religion__c,
                                                    Sex__c,
                                                    Payment_Frequency__c
                                                From
                                                    Preference__c
                                                Where id=:preferobj.id ];
                    //System.debug('Preference Details : '+ opp1.Preference__c);
                    Preference__c p=[select opportunity__c from preference__c where id=:preferobj.id];
                   OpportunityContactRole oRole = [Select ContactId from OpportunityContactRole Where OpportunityId=:p.opportunity__c ];
                    System.debug('Contact Role : '+ oRole);
                    Opportunity opp = [Select Id, Amount from Opportunity Where Preference__c =:preferobj.id];

                    assignChild(pref.get(0), oRole.ContactId);
                       }
                     }
 
          public void assignChild(Preference__c prefObj, String contactId)
            {
                List<String> list_status = new List<String>();
                list_status.add('Pooled');
                list_status.add('UnAssigned');
                list_status.add('Cancelled');
               Preference__c p=[select opportunity__c from preference__c where id=:preferobj.id];
                //RecordType oRecordType = [Select Id From RecordType Where SObjectType= 'Child__c'];
                system.debug('<<<<<>>>>>>>');
                String sOQL = 'Select Age__c, Name, Child_Registration_Date__c, Comments__c, Continent__c, Country__c, '
                                        + ' Date_of_Birth__c, Field_Officer__r.Name, Language__c, Religion__c, Sex__c, Status__c '
                                        + ' From Child__c  Where Status__c IN :list_status';
                String whereSQOL = '';
                if (prefObj.Age_From__c != null && prefObj.Age_To__c != null)
                {
                    whereSQOL = whereSQOL + ' And Age__c >='+prefObj.Age_From__c +' And Age__c <= '+ prefObj.Age_To__c;
                }
                else if (prefObj.Age_From__c == null && prefObj.Age_To__c != null)
                {
                    whereSQOL = whereSQOL + ' And Age__c >='+prefObj.Age_To__c + ' And Age__c <= ' + prefObj.Age_To__c;
                }
                else if (prefObj.Age_From__c != null && prefObj.Age_To__c == null)
                {
                    whereSQOL = whereSQOL + ' And Age__c >= '+ prefObj.Age_From__c + 'And Age__c <= '+prefObj.Age_From__c;
                }
                if (prefObj.Continent__c != null)
                {
                    whereSQOL = whereSQOL + ' And Continent__c =\''+prefObj.Continent__c+'\'';
                }
                if (prefObj.Country__c != null)
                {
                    whereSQOL = whereSQOL + ' And Country__c =\''+prefObj.Country__c+'\'';
                }
                /*else if (prefObj.Language__c != null)
                {
                    whereSQOL = whereSQOL + ' And Language__c =:prefObj.Country__c';
                }*/
                if (prefObj.Religion__c != null)
                {
                    whereSQOL = whereSQOL + ' And Religion__c =\''+prefObj.Religion__c+'\'';
                }
                if (prefObj.Sex__c != null)
                {
                    whereSQOL = whereSQOL + ' And Sex__c =\''+prefObj.Sex__c+'\'';
                }
                 sOQL = sOQL +  whereSQOL + ' limit 1';
                system.debug('<<<<<<<<<<<<<>>>>>>>>>>>>>>'+contactId);
                System.debug(sOQL + ' == sOQL');
                List<Commitment__c> list_commitment = new List<Commitment__c>();
                for (SObject oSobject : Database.Query(sOQL))
                {
                    Child__c oChild = (Child__c)oSobject;
                    Commitment__c com=new Commitment__c();
                    com.Contact__c = contactId;
                    com.Preference__c=prefObj.ID;
                    com.Commitment_Type__c = 'Sponsor Child';
                    com.Child__c = oChild.Id;
                    com.Commitments__c = p.opportunity__c;
                    com.Start_Date__c = Date.today();
                    com.End_Date__c =  Date.today().addMonths(Integer.valueOf(prefObj.Duration__c));
                    com.Commitment_Details__c = 'Auto Assignment';
                    com.Status__c = 'Assigned';
                    list_commitment.add(com);
                }
                if ( list_commitment != null &&  list_commitment.size() > 0 ) insert list_commitment;
                 generatePaymentSchedules();
            }
 
 
 
 

            
            public void generatePaymentSchedules()
              {
                              Integer calculateduration=0;
              Preference__c p=[select opportunity__c from preference__c where id=:preferobj.id];
              
              system.debug('<<<<<bhart>>>>>');
               Opportunity oppamt =[select OppAmount__c from opportunity where id=:p.opportunity__c ];
                 system.debug('<<<<<<<<<<<venki>>>>>>>>>>');
                 Opportunity opp1=[select Preference__c from opportunity where id=:p.opportunity__c ];
                 Preference__c payPref = [select Payment_Frequency__c,Duration__c from preference__c where id=:opp1.Preference__c];
                  Integer divisionRatio = 1;
                   Integer scheduleDueDate = 0;
                    Integer PayDurationInt = Integer.valueOf(payPref.Duration__c);

                  if (payPref.Payment_Frequency__c == 'Quarterly')
                  {
                      divisionRatio = 3;
                      scheduleDueDate = 3;
                    system.debug('<<<<<<<<<<<schedule date calculation>>>>>>>>>>');
                  }
                  if (payPref.Payment_Frequency__c == 'Half-Yearly')
                  {
                      divisionRatio = 6;
                      scheduleDueDate = 6;
                    
                  }
                  if(payPref.Payment_Frequency__c =='Annually(Full Payment)')
                  {
                  calculateduration =1;
                  
                  
                  }
                  else
                  {
                  calculateduration =(PayDurationInt/divisionRatio);
                  }
                  
                  
                  List<Payment_Schedule__c> list_schedule = new List<Payment_Schedule__c>();
                  System.debug(divisionRatio + ' == paymentMode ==');
                  Double scheduleAmt = oppamt.OppAmount__c/divisionRatio;
                  Integer temp =0;
                  system.debug('<<<<<<<<111111111111>>>>>>>>>>>');
                  for (Integer j = 0; j < calculateduration ; j++)
                  {
                        
                        Payment_Schedule__c obj = new Payment_Schedule__c();
                        obj.opportunity__c = p.opportunity__c ;
                        obj.Amount__c = scheduleAmt;
                        temp+= scheduleDueDate;
                        obj.Payment_Start_Date__c = Date.today().addMonths(temp);
                        list_schedule.add(obj);
                  }
                  
                  if (list_schedule.size() > 0){
                  system.debug('<<<<<<<<222222222222>>>>>>>>>>>');
                   insert list_schedule;
                   closedOpportunity();
                    
                  
                 }
            }
            
            
 
 
  public void closedOpportunity(){
           Preference__c p=[select opportunity__c from preference__c where id=:preferobj.id];
           Opportunity opp = [select id,StageName from opportunity where id=:p.opportunity__c ];
           opp.StageName ='Closed Won';
           update opp;
          EmailReportGen();
       
 }
public void EmailReportGen()
      {
        
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        String[] toAddresses = new String[] {'arunsoftviewrmd@gmail.com'};
        Blob b;
        Messaging.SendEmailResult [] r;
        email.setSubject('Child Assigned');
        email.setToAddresses(toAddresses);
        email.setHtmlBody( 'Hi,<br/><br/> Commitment Details has attached for your reference  <br/><br/>Thank you,<br/>');
        PageReference attachPdf =  Page.PDFGenratorpage;
        String pageUrl=attachPdf.getUrl();
        pageUrl = pageUrl + '?id=' +preferobj.id;
        PageReference pdf = new Pagereference(pageUrl);
        pdf.setRedirect(true);
        b = pdf.getContentAsPdf();
        efa.setFileName('.pdf');
        efa.setBody(b);
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
        r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    }
    
    // test class for the class "PreferenceChildController"
    
    static testmethod void PreferenceChildController()
    {
    
     
    PreferenceChildController pref1 = new PreferenceChildController();
    ApexPages.StandardController sc = new ApexPages.StandardController(pref1);
            
            
         
    }
    
    
   
 
 }


Please anyone help me

public with sharing class DemoRole 
{
    public List<OppData> list_opportunity {get; set;}
    public DemoRole()
    {
        list_opportunity = new List<OppData>();
        Set<Id> set_ownerId = new Set<Id>();
        List<OpportunityShare> oppList=[select Id,OpportunityId, Opportunity.Name, Opportunity.Owner.Name, UserOrGroupId from OpportunityShare Where Opportunity.Owner.UserRole.Name='UK Junior Representative'];
if(oppList!=null)
{
        for (OpportunityShare opp :oppList )
        {
               list_opportunity.add( getOppData(opp) );   
        }
}
getOppData(null);
        }
public static OppData getOppData(OpportunityShare opp)
{
            OppData oppData = new OppData();
    if(opp==null)
    System.debug('No record Found......');
            oppData.oppId = opp.OpportunityId;
            oppData.ownerName = opp.Opportunity.Owner.Name;
            oppData.managerName = opp.UserOrGroupId;
            oppData.oppName  = opp.Opportunity.Name;
    return oppData;
}
         
    
    public class OppData
    {
        public String oppId { get; set; }
        public String ownerName { get; set; }
        public String managerName { get; set; }
        public String oppName { get; set; }
    }
    
 // test class for the class demorole
 
 static testMethod void DemoRole ()
 {
DemoRole drule=new DemoRole();
OpportunityShare opp=new OpportunityShare();
opp.OpportunityId='00690000006yeky';
//opp.Opportunity.Owner.Name='sample owner';
opp.UserorGroupId='00690000006yeky';
opp.Opportunity.Name='test opportunity';
getOppData(opp);
 }
    
}

the test failure shows

Class.DemoRole.getOppData: line 23, column 1 Class.DemoRole.<init>: line 16, column 1 Class.DemoRole.DemoRole: line 43, column 1
please help me with this.........

Hi,

 

 I have the following  class for which i have written the test class

public with sharing class DonorRegisterController {
 
    public DonorRegisterController () {
    }
    public String firstname {get; set;}
    public String LastName {get; set;}
    public String Company {get; set;}
    public String email {get; set;}
    public String address{get; set;}
       public String Status {get; set;}
    public String country{get; set;}
    public String mobilephone{get; set;}
    public String phone{get; set;}
    public String website{get; set;}
    public String fax{get; set;}
    
    public void registerUser() {

        Lead l = new Lead();
        l.firstname = firstname;
        l.LastName= lastname;
        l.Company= Company;
        l.Email = email;
          l.country= country;
                 l.Status = Status ;
         //l.Address=address;

         l.MobilePhone=mobilephone;
        l.Phone=phone;
        l.website=Website;
        l.Fax=fax;
        l.LeadSOurce='Web';
        insert l;
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Registered Succesfully !'));

    }

the test class for the above class is

static testmethod void DonorRegisterController()
    {

    DonorRegisterController registerdate = new DonorRegisterController();
        
       Lead l1 = new Lead();
      l1.firstname = 'test';
       l1.LastName = 'data';
        l1.Company = 'msat';
        l1.Email = 'abc@abc.com';
        l1.company = 'Msat';
        l1.MobilePhone='9895929516';
        l1.Phone='54545451';
        l1.website='www.salesforce.com';
        l1.Fax='45454545';
        l1.LeadSOurce='Web';
        l1.Status ='qualified';
      l1.country ='usa';
        insert l1;
        
      
         Lead l2 = new Lead();
      l2.firstname = 'test';
       l2.LastName = 'dates';
        l2.Company = 'Msat';
        l2.Email = 'abc@abc.com';
        l2.MobilePhone='9895929516';
        l2.Phone='54545451';
        l2.website='www.salesforce.com';
        l2.Fax='45454545';
        l2.Status ='qualified';
       l2.country ='india';
        l2.LeadSOurce='Web';
        insert l2 ;
          registerdate.registerUser();
    
    }
    
}
i have a validation rule on lead making that the coutnry field under lead should be mandatory, but when i fire the test classs it throws an exception that country is missing which i have called,can anyone help me with this case

can we access TestMethod() in trigger?

Help me out with the test classs for the trigger below ,

 

trigger updateContact on MyProfile__c (after insert) {
        MyProfile__c profile=new MyProfile__c();
        Contact donorObj=new Contact();
        donorObj.LastName = profile.Name;
        donorObj.FirstName = profile.First_Name__c;
        donorObj.BirthDate = profile.Birthdate__c;
        donorObj.Description=profile.Description__c;
        donorObj.Email=profile.Email__c;
        donorObj.Phone=profile.Phone__c;
        donorObj.Fax=profile.Fax__c;
        donorObj.Mobilephone=profile.Mobile__C;
        update donorObj;
       
}

Help me with the testclass for the  trigger

 

trigger updateOpportunity on Preference__c (after insert)
{
    if (Trigger.isAfter)
    {
        Map<String, String> map_pref = new Map<String, String>();
        for (Preference__c oPref : Trigger.new)
        {
          map_pref.put(oPref.Opportunity__c, oPref.Id);    
        }
        List<Opportunity> list_opp = new List<Opportunity>();
        for (Opportunity opp : [Select Id, Preference__c,
                                 Preference_Associated__c
                               From
                                 Opportunity
                               Where
                                 Id IN : map_pref.keySet()])
        {
            opp.Preference__c = map_pref.get(opp.Id); 
            opp.Preference_Associated__c = true; 
            list_opp.add(opp);     
        }
        if (list_opp.size() > 0) update list_opp;                                   
    }   
}

can anyone help me writing test class for the following trigger below

trigger displayCommitment on Commitment__c (after insert)
{
   if (Trigger.isAfter)
   {
       Set<String> set_string = new Set<String>();
       Map<String, Commitment__c> map_pref = new Map<String,Commitment__c>(); 
       for ( Commitment__c cmmit : Trigger.new )
       {
           if (cmmit.Preference__c != null)
           {
               set_string.add(cmmit.Preference__c);
               map_pref.put(cmmit.Preference__c, cmmit);
           }
       }
       if (set_string.size() > 0)
       {
           List<Opportunity> list_opportunity = new List<Opportunity>();
           for (Opportunity obj : [Select Id, Preference__c From Opportunity Where Preference__c In : set_string])
           {
             Commitment__c cObj = map_pref.get(obj.Preference__c);
             Opportunity updateOpportunity = obj;
             //updateOpportunity.Commitment_Name__c = cObj.Name;
             updateOpportunity.Commitment_TypePreference__c = cObj.Commitment_Type__c;
             updateOpportunity.StartDate__c = cObj.Start_Date__c;
             updateOpportunity.EndDate__c =cObj.End_Date__c;
             updateOpportunity.Commitment_Details__c =cObj.Commitment_Details__c;
             updateOpportunity.contact__c =cObj.Contact__r.name;
             updateOpportunity.Status__c =cObj.Status__c;
             updateOpportunity.Child__c =cObj.Child__r.name;
             system.debug('<<<<<<<<test>>>>>>'+cObj.Child__r.name);
             list_opportunity.add(updateOpportunity);
             System.Debug('<<Sucess>>');
           } 
           if (list_opportunity != null && list_opportunity.size() > 0) update list_opportunity;
       }
   }
   }

Hello EveryOne,

 

I'm trying to write a Test class for the below Apex class. While runnig the test class i'm getting error like

"System.QueryException: List has no rows for assignment to SObject

 

Class.sendemail.sendEmailOnContacts: line 13, column 1 Class.sendemail.TestshowContacts: line 54, column 1"

 

 

Please find the below mentioned code snippet-

 

public class sendemail
{
String STR;
public sendemail()
{
STR=apexpages.currentpage().getparameters().get('id');
system.debug('Debug Statements=====>'+STR);
}
public pagereference sendEmailOnContacts(){
try
{

contact conobj=[select id,email from contact where id=:STR];
system.debug('Email Data=========>'+conobj.email);



Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String VarEmailSetting=conobj.email;
String[] toAddresses = new String[] {VarEmailSetting};

System.debug('<==============>'+toAddresses);

mail.setToAddresses(toAddresses);
mail.setSubject('Contact Information');
mail.setPlainTextBody('Hi You Are Added To Our System As Contacts');
mail.setReplyTo('jaan.vivek746@gmail.com');
mail.setSenderDisplayName('HR Management');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });


pagereference pagref=new pagereference('/'+conobj.id);
return pagref;
}
catch(System.EmailException ex)
{
system.debug('no emailid========>');
return null;
}

}
//**********************Test Class************************
static testMethod void TestshowContacts()
{
sendemail testObj=new sendemail ();
Contact con = new Contact();
con.FirstName = 'abc';
con.LastName = 'hi';
con.Email = 'abc.hi@gmail.com';
insert con;
Messaging.SingleEmailMessage testmail = new Messaging.SingleEmailMessage();
String testVarEmailSetting=con.Email;
String[] testtoAddresses = new String[] {testVarEmailSetting};
testmail.setToAddresses(testtoAddresses);
testObj.sendEmailOnContacts();
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { testmail });
 }
}

 

 

I don't have much hands on on sfdc but i'm eager to learn it.

 

It would be great help if you suggest me in this case.

 

 

Thanks for your valuable help.

 Your suggestions are always welcome.

 

Vivek


Hi,

 

 I am just trying to add an survey form in salesforce, can anybody tell me how do i do it, can i download it from app exchange , or do i need to write code for it

 

 

Thanks

Hi,

 

Please help me out with my scenario,

 

  i have 5 record types under oppornunity based on country like (uk, spain, belgium)

 

 when i create a new lead record and convert a lead by logging in as uk user ,the field opportunity record type under opportunity takes the default record type as (plan spain) rather than uk record type

 

how do i fix it , will trigger help in this case , or should i create a seperate profile for each user , if so the settings will change based on the permissions..

 

 

anyhelp will be appreciated