• Mohan Selvam
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 13
    Replies
Hi
Please guide me to reach 75% in my test class

My apex class as follows,
Public Class ProductTriggerHandler{
  public void OnAfterUpdate(Map<Id,Product2> newProductMap,Map<Id,Product2> oldProductMap){ 
            Boolean Checkin = false;
            for(Product2 prod: newProductMap.values())  {
            if(prod.cost__c!= oldProductMap.get(prod.id).cost__c){
                    Checkin = True;
                 }
            }    
                
            if(Checkin == true){  
            UpdateGpPercentage(newProductMap,oldProductMap);
            }
        }
   
      Private void UpdateGpPercentage(Map<Id,Product2> newProductMap,Map<Id,Product2> oldProductMap){
    List<OpportunityLineItem> OppProductList = new List<OpportunityLineItem>([ Select id,opportunityid from OpportunityLineItem where PricebookEntry.Product2.id IN :newProductMap.Keyset() and opportunityid != null]);
    List<Id> OppIds = new List<Id>();
      List<Id> SSOppIds = new List<Id>();
      for(OpportunityLineItem oli:OppProductList ){
              OppIds.add(oli.opportunityid);
      } 
    
      List<Opportunity> OppList = new List<Opportunity>();
      List<Opportunity> OppListNew = new List<Opportunity>();
      OppList  = [Select id, Service_Sheet__c from Opportunity where id In :OppIds];
      if(OppList.size() > 0){
          For(Opportunity OPP : OppList){
              if(OPP.Service_Sheet__c!=NULL){
                   SSOppIds.add(OPP.id);

               }
           }
           
           if(SSOppIds.size() > 0){ 
               Try{
                  Database.executeBatch(new UpdateOpportunityByBatch(SSOppIds));

               } catch(Exception E){System.debug('Errors Msg'+E);}
           }
       } 
         
   }
   
}


My test class as follows

@IsTest(SeeallData=True)
Private class ProductTriggerHandlerTest{
    Static TestMethod Void UpdateGpPercentageTest(){
     Test.StartTest(); 
         Product2 Ins_Prod = New Product2(Name='Test Product', ProductCode='DHI_6677_Test', Cost__c=5);
         Insert Ins_Prod;
     Product2  Prod =[Select Id, Cost__c from Product2 where ID=:Ins_Prod.id];
         Prod.Cost__c=10.00;
         Update Prod;
       Opportunity Opp =[Select id,Service_Sheet__c From Opportunity Limit 1];
         List<Id> OppIds = New List<id>();
         OppIds.add(Opp.id);
         Database.executeBatch(new UpdateOpportunityByBatch(OppIds));
     Test.stopTest();   
     
    }
    
}

Note : Unerlined lines are not covered in my test class.. i got 69% ... please guide me to reach 75%. Lines covered 16/23
Hi

I have done workflow and created field updated based on some criteria in opportunity object ...
I have enabled field track to that particular field.. it will tracking only with the first time it meets the criteria..
but it will not tracking everytime the criteria meets..

Thanks and Regards

S.Mohan
In my Apex Code I have Default Start time and Default End Time named as start and stop, code as follows
 time start = time.newInstance(8,30,0,0);
 time stop = time.newInstance(17,0,0,0);

and I am getting start time and endtime from Object [field type DateTime] from that i am getting only time in Starttime and Endtime, code as follows

time Starttime = Time.newInstance(SSJ.Start_Date_and_Time__c.hour(),SSJ.Start_Date_and_Time__c.minute(),SSJ.Start_Date_and_Time__c.second(),SSJ.Start_Date_and_Time__c.millisecond());

 time Endtime = Time.newInstance(SSJ.End_Date_and_Time__c.hour(),SSJ.End_Date_and_Time__c.minute(),SSJ.End_Date_and_Time__c.second(),SSJ.End_Date_and_Time__c.millisecond());

Now i want to find the difference between
Stop to Starttime and
Start to Endtime . how to calculate this?

Thanks and Regards 
S.Mohan
 
Hi all

I have a report on opportunity object to know the technician turnover and achievement percentage(Every technician have some target amount).
Here is the new requirement as follows
If the visit object has two technician like technician1 and technician2 then the opportunity amount should be divided and added to both of them.
If the visit object has only one technician then the amount should be added into technician1.
I need to achieve this in Exisiting report. 

Regards 
S.Mohan
 
Hi all,
we have reached 64% in Data Storage, Is there any possibilities to Archive records?
There are 2 possibilities to solve this problem.
One way is to puchase additional sapce from salesforce
and anothere one is to backup our records and delete them.
Please tell me is there any other methods avalibale to resolve this issue.
Please send me the link.
Thanks and Regards 
S Mohan
Hi all
i am a Beginner 
Please can anyone guide me to write test class for the following. 

Description: Based on Object1's fields input i am updating Object2's field. i have achieved the reqirement. But i couldn't write test class for my method. 
Object1 fields : a)Arrival time    b)Departure time 
Object2 field:Outofhours.
My code as follows
Public string CalculateOutOfOfficeHour(datetime inTime, datetime outTime){
    Map<String, String> listDayMap = new Map<String, String>{'Monday' => 'Monday', 'Tuesday' => 'Tuesday','Wednesday' => 'Wednesday' , 'Thursday' => 'Thursday' ,'Friday' => 'Friday','Saturday'=>'Saturday','Sunday'=>'Sunday'};
    String StartdayOfWeek =inTime.format('EEEE');
    String EnddayOfWeek = outTime.format('EEEE');
    time start = Time.newInstance(8,30,0,0);
    time stop = Time.newInstance(17,0,0,0);
    string bookingStarttime = string.valueOf( Time.newInstance(inTime.hour(),inTime.minute(),inTime.second(),inTime.millisecond()));
    string bookingEndtime = string.valueOf(Time.newInstance(outTime.hour(),outTime.minute(),outTime.second(),outTime.millisecond()));
    Date mysDate = Date.newInstance(inTime.year(), inTime.month(), inTime.day());
    Date myeDate = Date.newInstance(outTime.year(), outTime.month(), outTime.day());
    String result='';     
    integer numberDaysDue = mysDate.daysBetween(myeDate);

  if(numberDaysDue >= 5 )
  {
     result='BOTH';
  }            
  if((numberDaysDue == 0))
  {
     if((StartdayOfWeek == 'Saturday'||StartdayOfWeek =='Sunday')){
             result='OUT';}
     else if((StartdayOfWeek == 'Monday')&&(bookingStarttime < string.valueOf(start))&&(bookingEndtime < string.valueOf(start))){
             result='OUT';}
     else if((StartdayOfWeek == 'Monday')&&(bookingStarttime <= string.valueOf(start))&&(bookingEndtime > string.valueOf(start))){
             result='BOTH';}
     else if((StartdayOfWeek == 'Friday')&&(bookingStarttime <= string.valueOf(start))&&(bookingEndtime > string.valueOf(stop))){
             result='BOTH';}
     else if((StartdayOfWeek == 'Friday')&&(bookingEndtime > string.valueOf(stop))&&(bookingStarttime > string.valueOf(stop))){
             result='OUT';}
     else{
             result='IN';}
  }

 return result ;
  
}    
 
hi
i want to create one alert message with ok button in existing visualforce page and i need to use that message
in a perticullar method of exisiting controller[apex classes]
For example
i am having visualforce page named as 'visitWarning'. In that i need to add a code to create alert message with ok button and i should call this alert in AbilityChecking() method [this method occured in my VisitAlertController Class]
Code Example :
Page
VisitWarning

<apex:page standardController="Visits__c"  extensions="VisitAlertPageController" >
 <apex:outputPanel layout="block" style="overflow:auto;height:100px" >
 <apex:pageMessages />
 </apex:outputPanel>
</apex:page>
Apex classes

public class VisitAlertPageController {
.....
......
......

public void VisitScheduledAbility(){
.........
..........
if((currentVisit.Type__c =='Hello' )
{
// I should call the alert here
}
}

}


how can i create a visuvalforce page with ok button to clear and how to invoke this in corresponding apex classes.
Hi all,
we have reached 64% in Data Storage, Is there any possibilities to Archive records?
There are 2 possibilities to solve this problem.
One way is to puchase additional sapce from salesforce
and anothere one is to backup our records and delete them.
Please tell me is there any other methods avalibale to resolve this issue.
Please send me the link.
Thanks and Regards 
S Mohan
Hi
Please guide me to reach 75% in my test class

My apex class as follows,
Public Class ProductTriggerHandler{
  public void OnAfterUpdate(Map<Id,Product2> newProductMap,Map<Id,Product2> oldProductMap){ 
            Boolean Checkin = false;
            for(Product2 prod: newProductMap.values())  {
            if(prod.cost__c!= oldProductMap.get(prod.id).cost__c){
                    Checkin = True;
                 }
            }    
                
            if(Checkin == true){  
            UpdateGpPercentage(newProductMap,oldProductMap);
            }
        }
   
      Private void UpdateGpPercentage(Map<Id,Product2> newProductMap,Map<Id,Product2> oldProductMap){
    List<OpportunityLineItem> OppProductList = new List<OpportunityLineItem>([ Select id,opportunityid from OpportunityLineItem where PricebookEntry.Product2.id IN :newProductMap.Keyset() and opportunityid != null]);
    List<Id> OppIds = new List<Id>();
      List<Id> SSOppIds = new List<Id>();
      for(OpportunityLineItem oli:OppProductList ){
              OppIds.add(oli.opportunityid);
      } 
    
      List<Opportunity> OppList = new List<Opportunity>();
      List<Opportunity> OppListNew = new List<Opportunity>();
      OppList  = [Select id, Service_Sheet__c from Opportunity where id In :OppIds];
      if(OppList.size() > 0){
          For(Opportunity OPP : OppList){
              if(OPP.Service_Sheet__c!=NULL){
                   SSOppIds.add(OPP.id);

               }
           }
           
           if(SSOppIds.size() > 0){ 
               Try{
                  Database.executeBatch(new UpdateOpportunityByBatch(SSOppIds));

               } catch(Exception E){System.debug('Errors Msg'+E);}
           }
       } 
         
   }
   
}


My test class as follows

@IsTest(SeeallData=True)
Private class ProductTriggerHandlerTest{
    Static TestMethod Void UpdateGpPercentageTest(){
     Test.StartTest(); 
         Product2 Ins_Prod = New Product2(Name='Test Product', ProductCode='DHI_6677_Test', Cost__c=5);
         Insert Ins_Prod;
     Product2  Prod =[Select Id, Cost__c from Product2 where ID=:Ins_Prod.id];
         Prod.Cost__c=10.00;
         Update Prod;
       Opportunity Opp =[Select id,Service_Sheet__c From Opportunity Limit 1];
         List<Id> OppIds = New List<id>();
         OppIds.add(Opp.id);
         Database.executeBatch(new UpdateOpportunityByBatch(OppIds));
     Test.stopTest();   
     
    }
    
}

Note : Unerlined lines are not covered in my test class.. i got 69% ... please guide me to reach 75%. Lines covered 16/23
Hi

I have done workflow and created field updated based on some criteria in opportunity object ...
I have enabled field track to that particular field.. it will tracking only with the first time it meets the criteria..
but it will not tracking everytime the criteria meets..

Thanks and Regards

S.Mohan
In my Apex Code I have Default Start time and Default End Time named as start and stop, code as follows
 time start = time.newInstance(8,30,0,0);
 time stop = time.newInstance(17,0,0,0);

and I am getting start time and endtime from Object [field type DateTime] from that i am getting only time in Starttime and Endtime, code as follows

time Starttime = Time.newInstance(SSJ.Start_Date_and_Time__c.hour(),SSJ.Start_Date_and_Time__c.minute(),SSJ.Start_Date_and_Time__c.second(),SSJ.Start_Date_and_Time__c.millisecond());

 time Endtime = Time.newInstance(SSJ.End_Date_and_Time__c.hour(),SSJ.End_Date_and_Time__c.minute(),SSJ.End_Date_and_Time__c.second(),SSJ.End_Date_and_Time__c.millisecond());

Now i want to find the difference between
Stop to Starttime and
Start to Endtime . how to calculate this?

Thanks and Regards 
S.Mohan
 
Hi,

How to reset Sandbox account's password in Production account?

Thanks
Hi all,
we have reached 64% in Data Storage, Is there any possibilities to Archive records?
There are 2 possibilities to solve this problem.
One way is to puchase additional sapce from salesforce
and anothere one is to backup our records and delete them.
Please tell me is there any other methods avalibale to resolve this issue.
Please send me the link.
Thanks and Regards 
S Mohan
Hi all
i am a Beginner 
Please can anyone guide me to write test class for the following. 

Description: Based on Object1's fields input i am updating Object2's field. i have achieved the reqirement. But i couldn't write test class for my method. 
Object1 fields : a)Arrival time    b)Departure time 
Object2 field:Outofhours.
My code as follows
Public string CalculateOutOfOfficeHour(datetime inTime, datetime outTime){
    Map<String, String> listDayMap = new Map<String, String>{'Monday' => 'Monday', 'Tuesday' => 'Tuesday','Wednesday' => 'Wednesday' , 'Thursday' => 'Thursday' ,'Friday' => 'Friday','Saturday'=>'Saturday','Sunday'=>'Sunday'};
    String StartdayOfWeek =inTime.format('EEEE');
    String EnddayOfWeek = outTime.format('EEEE');
    time start = Time.newInstance(8,30,0,0);
    time stop = Time.newInstance(17,0,0,0);
    string bookingStarttime = string.valueOf( Time.newInstance(inTime.hour(),inTime.minute(),inTime.second(),inTime.millisecond()));
    string bookingEndtime = string.valueOf(Time.newInstance(outTime.hour(),outTime.minute(),outTime.second(),outTime.millisecond()));
    Date mysDate = Date.newInstance(inTime.year(), inTime.month(), inTime.day());
    Date myeDate = Date.newInstance(outTime.year(), outTime.month(), outTime.day());
    String result='';     
    integer numberDaysDue = mysDate.daysBetween(myeDate);

  if(numberDaysDue >= 5 )
  {
     result='BOTH';
  }            
  if((numberDaysDue == 0))
  {
     if((StartdayOfWeek == 'Saturday'||StartdayOfWeek =='Sunday')){
             result='OUT';}
     else if((StartdayOfWeek == 'Monday')&&(bookingStarttime < string.valueOf(start))&&(bookingEndtime < string.valueOf(start))){
             result='OUT';}
     else if((StartdayOfWeek == 'Monday')&&(bookingStarttime <= string.valueOf(start))&&(bookingEndtime > string.valueOf(start))){
             result='BOTH';}
     else if((StartdayOfWeek == 'Friday')&&(bookingStarttime <= string.valueOf(start))&&(bookingEndtime > string.valueOf(stop))){
             result='BOTH';}
     else if((StartdayOfWeek == 'Friday')&&(bookingEndtime > string.valueOf(stop))&&(bookingStarttime > string.valueOf(stop))){
             result='OUT';}
     else{
             result='IN';}
  }

 return result ;
  
}    
 
how can i create a visuvalforce page with ok button to clear and how to invoke this in corresponding apex classes.