• sumit pawar
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 4
    Replies
i have two text boxes with number data type.
weight in lbs
weight in kgs

i want to convert from lbs to kgs and kgs to lbs...
when i will enter data in lbs its kgs value should display and kg textbox will get disable.
and same vice versa.

i used disabled in inputcheckbox but its not fuctioning correctly..
can u pls suggest me how to do this in javascript..?
I tried to get up below class coverage from 62% to 100% but no luck..
what i am missing...?Please help me out...bold code in test class has not covered...

Apex class:

public with sharing class InvoiceGenerator {

    public void generateInvoices() { 
        Invoice_Generation_Frequency__c igf = Invoice_Generation_Frequency__c.getInstance('Default');
        system.debug('igf.Days__c:'+igf.Days__c);
                               
        Integer currentYear = system.today().year();
        Integer currentDay = (system.today().addDays((integer)igf.Days__c)).day();
        system.debug('--day--'+currentDay);
         
        List<Account> accList = [Select Id,Group__c,Group_Signup_Start_Date__c,Group_Renewal_Date__c,Invoice_Amount__c From Account  where
 
  Group__c='yes' and CALENDAR_YEAR(Group_Renewal_Date__c) < = :currentYear and DAY_IN_MONTH(Group_Renewal_Date__c) = :currentDay];
         
        String currYear = system.today().year() + '%';
        //List<AggregateResult> arList = [select count(id) cnt from Invoice__c where Invoice_Number__c like :currYear];
        //nextInvNum = (integer)arList[0].get('cnt');
       
        List<Invoice__c> invnumberList = [select Invoice_Number__c from Invoice__c where Invoice_Number__c like:currYear order by Invoice_Number__c desc];
        List<Invoice__c> InvoiceList = new List<Invoice__c>();
       
  if(invnumberList.size() > 0){ 
            string invhighestnum = invnumberList[0].Invoice_Number__c;
         string convertedlast = invhighestnum.substring(5,9);
         integer InvNumhighest = integer.valueOf(convertedlast);
         system.debug('132654'+InvNumhighest); 
        
         system.debug('--InvNumhighestnew--'+InvNumhighest); 
         for(Account a : accList) {
          InvNumhighest++;
             Invoice__c Inv = new Invoice__c();
             Inv.Account__c = a.Id; 
             Inv.Paid__c = false;
             Inv.Group_Start_Date__c = a.Group_Signup_Start_Date__c;
             Inv.Group_Renewal_Date__c = a.Group_Renewal_Date__c;
             Inv.Invoice_Amount__c = a.Invoice_Amount__c; 
             Inv.Invoice_Number__c = (system.today().year() + '-' + InvNumhighest);
             InvoiceList.add(Inv);
             system.debug('--invList--'+InvoiceList);
   }
   insert InvoiceList;
  }
  else {
          integer nextInvNum;
          nextInvNum = 0000;                  
          nextInvNum = nextInvNum + 2000;
    system.debug('--nextInvNum--'+nextInvNum);
     for(Account a : accList) {
      nextInvNum++;
              Invoice__c Inv = new Invoice__c();
              Inv.Account__c = a.Id; 
              Inv.Paid__c = false;
              Inv.Start_Date__c = a.Group_Signup_Start_Date__c;
              Inv.Renewal_Date__c = a.Group_Renewal_Date__c;
              Inv.Invoice_Amount__c = a.Invoice_Amount__c;
              Inv.Invoice_Number__c = (system.today().year() + '-' + nextInvNum);
              InvoiceList.add(Inv); 
     }
     insert InvoiceList;

   }                       
    }
}

Test class:

@isTest(SeeAllData=true)
class TestInvoiceUpdate{
 

public static String CRON_EXP = '0 00 01 * * ?';

static testmethod void test() {
 
   Test.startTest();
  
   Account a = new Account();
    a.Name = 'test';
    a.Group__c = 'Yes';
    Date myDate = date.newinstance((system.today().addYears(-1)).year(), (system.today().addDays(45)).month(), (system.today().addDays(45)).day());
    a.Group_Renewal_Date__c = myDate;
    insert a;
    system.debug('Myinsert'+a);
   
    Invoice__c i = new Invoice__c();
    i.Paid__c = false;
    i.Account__c = a.id;
    i.Invoice_Number__c = '1111';
    insert i;
    
   String InvId = System.schedule('testBasicScheduledApex',CRON_EXP,new InvoiceUpdate());
   // Get the information from the CronTrigger API object
   CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :InvId];
   // Verify the expressions are the same
   System.assertEquals(CRON_EXP, ct.CronExpression);
   // Verify the job has not run
   System.assertEquals(0, ct.TimesTriggered);
   Test.stopTest();
  
    }
   
    static testmethod void test1() {
 
    Test.startTest();
  
   Account a = new Account();
    a.Name = 'test1';
    a.Group__c = 'Yes';
    Date myDate1 = date.newinstance((system.today().addYears(-1)).year(), (system.today().addDays(45)).month(), (system.today().addDays(45)).day());
    a.Group_Renewal_Date__c = myDate1;
    insert a;
    system.debug('Myinsert'+a);
   
    Invoice__c i = new Invoice__c();
    i.Paid__c = false;
    i.Account__c = a.id;
    i.Invoice_Number__c = '2222';
    insert i;
    
   String InvId = System.schedule('testBasicScheduledApex',CRON_EXP,new InvoiceUpdate());
   // Get the information from the CronTrigger API object
   CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :InvId];
   // Verify the expressions are the same
   System.assertEquals(CRON_EXP, ct.CronExpression);
   // Verify the job has not run
   System.assertEquals(0, ct.TimesTriggered);
   Test.stopTest();
    }    
}
i want to create test class for below apex class... i have created test class but its giving only 64% code coverage...
Please help to create test class for below apex class...

bold lines shows code not covered...

Apex class:

public with sharing class StageUpdateInformation {
    //public Opportunity oop {get;set;}
    //public string Hour {get;set;}
    //public string Minute {get;set;}
    //public list<SelectOption> UserList{get;set;}
    //public list<SelectOption> SelectedUserList{get;set;}
    public list<WrapperStage> wrapperList{get;set;}
   
    public StageUpdateInformation(){
        //oop = new Opportunity();
        wrapperList = new list<WrapperStage>();
        list<string> stlist = OppStagesUtility.oppStage();
        for(string s :stlist){
            wrapperList.add(new WrapperStage(s));
        }
        /*SelectedUserList = new list<SelectOption>();
        list<User> usList = [select Id, Name from User];
        UserList = new list<SelectOption>();
        for(User u:usList){
            UserList.add(new SelectOption(u.Id, u.Name));
        }*/
    }
   
    public Pagereference save(){
        string idNew = '';
        string nameNew = '';
        list<Stage_Update_Information__c> stgUpList = new list<Stage_Update_Information__c>();
        list<string> existStagelist = new list<string>();
        for(WrapperStage wc :wrapperList){
            if(wc.SelectedUserList.size()>0){
                system.debug('============wc.SelectedUserList================'+wc.SelectedUserList);
                system.debug('============wc.Stage================'+wc.Stage);
                existStagelist.add(wc.stage);
                for(SelectOption s :wc.SelectedUserList){
                    if(idNew == ''){
                        idNew += s.getValue();
                        nameNew += s.getLabel();

                    }
                    else{
                        idNew += ','+s.getValue();
                        nameNew += ','+s.getLabel();

                    }
                }
                if(idNew != ''){
                    Stage_Update_Information__c sui = new Stage_Update_Information__c();
                    sui.Owner_Name__c = nameNew;
                    sui.Owner_Id__c = idNew;
                    sui.Stage_Name__c = wc.stage;
                    sui.Hour__c = wc.Hour;
                    sui.Minute__c = wc.Minute;
                    stgUpList.add(sui);

                }
            }
        }
        list<Stage_Update_Information__c> suiList = [select Id, Stage_Name__c from Stage_Update_Information__c where Stage_Name__c IN :existStagelist];
        if(suiList.size()>0){
            delete suiList;
        }
        insert stgUpList; 
        /*string idNew = '';
        string nameNew = '';
        for(SelectOption s :SelectedUserList){
            if(idNew == ''){
                idNew += s.getValue();
                nameNew += s.getLabel();
            }
            else{
                idNew += ','+s.getValue();
                nameNew += ','+s.getLabel();
            }
        }*/
        //system.debug('===============Id list Final============'+idNew);
       
    }
    public class WrapperStage{
        public string stage {get;set;}
        public list<SelectOption> UserList{get;set;}
        public list<SelectOption> SelectedUserList{get;set;}
        //public Opportunity oop {get;set;}
        public string Hour {get;set;}
        public string Minute {get;set;}
       
        public WrapperStage(string s){
            stage = s;
            SelectedUserList = new list<SelectOption>();
            list<User> usList = [select Id, Name from User];
            UserList = new list<SelectOption>();
            for(User u:usList){
                UserList.add(new SelectOption(u.Id, u.Name));
            }
        }
    }
}
Test class:

@isTest
private class TestStageUpdateInformation {

    static testMethod void myUnitTest() {
        StageUpdateInformation Stageupdate = new StageUpdateInformation();
  Stageupdate.save();

       
    }
}
I have created a code to get picklistfield dynamically and its values...
now i want to create test class for it i have created test class but its seems wrong...
Please help to create test class for belo apex class...

Apex class:

public with sharing class OppSt {

public List<string> Opp{get;set;}

public static list<string> oppstm(){
  list<string> Opp = new list<string>();
  Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe();
  SObjectType accountType = Schema.getGlobalDescribe().get('Opportunity');
  Map<String,Schema.SObjectField> mfields = accountType.getDescribe().fields.getMap();
 
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple)
        {
      Opp.add(f.getLabel());
       }
       system.debug('============='+Opp);
       return Opp; 
}
          
}

Test class:

@isTest
private class TestOpportunityStageUtility {

    static testMethod void myUnitTest() {
       
  Opportunity o = new Opportunity ();
  o.StageName = 'abc';
  insert o;
    }
   
}
i have 3 objects project,saler,recordupdates

project object having level name picklistfield and having values a,b,c

i have records in recordupdates object which contains level name and field name

and now i want to set validation for saler object fields...on which fields are in recordupdates object records.

Please suggest...
i want to develop page as like,

checkbox stage name  1     checkbox  field1   checkbox  field1
checkbox stage name  2     checkbox  field1   checkbox  field2
checkbox stage name  3     checkbox  field1   checkbox  field3
checkbox stage name  4     checkbox  field1   checkbox  field4  and so on....


above is the brief gui of page i am going to add 7 fields with checkboxes.
from oppportunity object i am selecting stages and from B object i am selecting fields...

and then after i will select any stage and i will check any checkboxes of fields.
and after that i will click on SAve button then record will get created in C object
as e.g 
if i select stage name 3  and fields 2,3,6 then 3 different record should get created...
stage name 3  field 2
stage name 3  field 3
stage name 3  field 6


Please suggest on this...
here a small requirement i having..

i having contacts.. and default description field in contact object...(Populated)
now i created another description1 textarea field in contact object..

i want to add contents of description field in description1 field.

what i do Please suggest?
here a small requirement i having..

i having contacts.. and default description field in contact object...
now i created another description1 textarea field in contact object..

i want to copy automatically everytime contents of description field in description1 field.

what i do Please suggest?
 how to create below html body to set in mail? i got stuck in following issue...suggest on this..

Hi (contact name), >> contact name is dynamic.

Please check this out for (...) and (....) >> dynamic values.

Regards, ABC

Like set.htmlbody('hi' +contactname+ ','); and now stuck for next one.... above showing like hi(abc),this also wrong. Please help me out...
I cannot create a new Activity History record when using message.setSaveAsActivity(true);

so i added mail.setTargetObjectId(con.id); its working fine.

but actual issue is when i am sending mail to my gmail id its coming properly. and when i am sending mail to my organization email id its coming multiple times.

e.g for 2 accounts sending mail to gmail id recieving 2 only. !!!working!!!

for 2 accounts sending mail to my organization email id recieving 4. !!!multiple same mails!!! 2 for each.

This is my code:

    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    String[] toAddresses = new String[] {recipient.Email};
    mail.setToAddresses(toAddresses);
    mail.setBccSender(true);
    String[] bccAddresses = new String[] {person.Email};
    mail.setBccAddresses(bccAddresses);
    mail.setTargetObjectId(con.id);
    mail.setSaveAsActivity(true);
    mail.setSubject(subject);
    mail.setPlainTextBody(templateBody);
   Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
Am I doing something wrong?
i have two text boxes with number data type.
weight in lbs
weight in kgs

i want to convert from lbs to kgs and kgs to lbs...
when i will enter data in lbs its kgs value should display and kg textbox will get disable.
and same vice versa.

i used disabled in inputcheckbox but its not fuctioning correctly..
can u pls suggest me how to do this in javascript..?
I tried to get up below class coverage from 62% to 100% but no luck..
what i am missing...?Please help me out...bold code in test class has not covered...

Apex class:

public with sharing class InvoiceGenerator {

    public void generateInvoices() { 
        Invoice_Generation_Frequency__c igf = Invoice_Generation_Frequency__c.getInstance('Default');
        system.debug('igf.Days__c:'+igf.Days__c);
                               
        Integer currentYear = system.today().year();
        Integer currentDay = (system.today().addDays((integer)igf.Days__c)).day();
        system.debug('--day--'+currentDay);
         
        List<Account> accList = [Select Id,Group__c,Group_Signup_Start_Date__c,Group_Renewal_Date__c,Invoice_Amount__c From Account  where
 
  Group__c='yes' and CALENDAR_YEAR(Group_Renewal_Date__c) < = :currentYear and DAY_IN_MONTH(Group_Renewal_Date__c) = :currentDay];
         
        String currYear = system.today().year() + '%';
        //List<AggregateResult> arList = [select count(id) cnt from Invoice__c where Invoice_Number__c like :currYear];
        //nextInvNum = (integer)arList[0].get('cnt');
       
        List<Invoice__c> invnumberList = [select Invoice_Number__c from Invoice__c where Invoice_Number__c like:currYear order by Invoice_Number__c desc];
        List<Invoice__c> InvoiceList = new List<Invoice__c>();
       
  if(invnumberList.size() > 0){ 
            string invhighestnum = invnumberList[0].Invoice_Number__c;
         string convertedlast = invhighestnum.substring(5,9);
         integer InvNumhighest = integer.valueOf(convertedlast);
         system.debug('132654'+InvNumhighest); 
        
         system.debug('--InvNumhighestnew--'+InvNumhighest); 
         for(Account a : accList) {
          InvNumhighest++;
             Invoice__c Inv = new Invoice__c();
             Inv.Account__c = a.Id; 
             Inv.Paid__c = false;
             Inv.Group_Start_Date__c = a.Group_Signup_Start_Date__c;
             Inv.Group_Renewal_Date__c = a.Group_Renewal_Date__c;
             Inv.Invoice_Amount__c = a.Invoice_Amount__c; 
             Inv.Invoice_Number__c = (system.today().year() + '-' + InvNumhighest);
             InvoiceList.add(Inv);
             system.debug('--invList--'+InvoiceList);
   }
   insert InvoiceList;
  }
  else {
          integer nextInvNum;
          nextInvNum = 0000;                  
          nextInvNum = nextInvNum + 2000;
    system.debug('--nextInvNum--'+nextInvNum);
     for(Account a : accList) {
      nextInvNum++;
              Invoice__c Inv = new Invoice__c();
              Inv.Account__c = a.Id; 
              Inv.Paid__c = false;
              Inv.Start_Date__c = a.Group_Signup_Start_Date__c;
              Inv.Renewal_Date__c = a.Group_Renewal_Date__c;
              Inv.Invoice_Amount__c = a.Invoice_Amount__c;
              Inv.Invoice_Number__c = (system.today().year() + '-' + nextInvNum);
              InvoiceList.add(Inv); 
     }
     insert InvoiceList;

   }                       
    }
}

Test class:

@isTest(SeeAllData=true)
class TestInvoiceUpdate{
 

public static String CRON_EXP = '0 00 01 * * ?';

static testmethod void test() {
 
   Test.startTest();
  
   Account a = new Account();
    a.Name = 'test';
    a.Group__c = 'Yes';
    Date myDate = date.newinstance((system.today().addYears(-1)).year(), (system.today().addDays(45)).month(), (system.today().addDays(45)).day());
    a.Group_Renewal_Date__c = myDate;
    insert a;
    system.debug('Myinsert'+a);
   
    Invoice__c i = new Invoice__c();
    i.Paid__c = false;
    i.Account__c = a.id;
    i.Invoice_Number__c = '1111';
    insert i;
    
   String InvId = System.schedule('testBasicScheduledApex',CRON_EXP,new InvoiceUpdate());
   // Get the information from the CronTrigger API object
   CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :InvId];
   // Verify the expressions are the same
   System.assertEquals(CRON_EXP, ct.CronExpression);
   // Verify the job has not run
   System.assertEquals(0, ct.TimesTriggered);
   Test.stopTest();
  
    }
   
    static testmethod void test1() {
 
    Test.startTest();
  
   Account a = new Account();
    a.Name = 'test1';
    a.Group__c = 'Yes';
    Date myDate1 = date.newinstance((system.today().addYears(-1)).year(), (system.today().addDays(45)).month(), (system.today().addDays(45)).day());
    a.Group_Renewal_Date__c = myDate1;
    insert a;
    system.debug('Myinsert'+a);
   
    Invoice__c i = new Invoice__c();
    i.Paid__c = false;
    i.Account__c = a.id;
    i.Invoice_Number__c = '2222';
    insert i;
    
   String InvId = System.schedule('testBasicScheduledApex',CRON_EXP,new InvoiceUpdate());
   // Get the information from the CronTrigger API object
   CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :InvId];
   // Verify the expressions are the same
   System.assertEquals(CRON_EXP, ct.CronExpression);
   // Verify the job has not run
   System.assertEquals(0, ct.TimesTriggered);
   Test.stopTest();
    }    
}
here a small requirement i having..

i having contacts.. and default description field in contact object...(Populated)
now i created another description1 textarea field in contact object..

i want to add contents of description field in description1 field.

what i do Please suggest?