+ Start a Discussion
:) :) :) :) :):) :) :) :) :) 

How can get all condition satisfied of this particular trigger

Test Class

@isTest
private Class oppoUpdate{
static testMethod void Test_LeadConvert(){


Lead myLead = new Lead(LastName = 'Fry', Company='Fry And Sons',Ownerid='005d0000000rtY4AAI');
insert myLead;

Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.id);

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);

Database.LeadConvertResult lcr = Database.convertLead(lc);
// System.assert(lcr.isSuccess());

lead mylead2 = [Select CreatedDate, OwnerId from lead where ConvertedOpportunityId =:lcr.getOpportunityId() Limit 1];

opportunity opp = [select ownerid from opportunity where id=:lcr.getOpportunityId() Limit 1];

opp.ownerid = '005d0000001TaWwAAK';
update opp;
double m = 123456789;

}
}

 

My trigger

 

trigger timeCaculatation on Opportunity (before insert,before update) {
double m;
double d1,d2,d3;
Integer i1,i2,i3;
Integer dy=0,hr=0,min=0,sec=0;
String timeValue;
List<lead> list1 = new List<lead>();
for(opportunity oppo : trigger.new){
list1 = [Select CreatedDate, OwnerId from lead where ConvertedOpportunityId =:oppo.id];

for(lead l : list1){
if(l.OwnerId != oppo.OwnerId){
for(opportunity oppo1 : trigger.old){
if(oppo1.Assignment_Time__c == NULL){
m = (System.now().getTime()-l.CreatedDate.getTime())/1000;
system.debug(m);
if(m>=86400){
d1 = m/86400; // need to take before decimal point NO DAYS
dy = d1.intValue();
if((math.mod(integer.valueof(m),86400) > 0))
{
i1 = math.mod(integer.valueof(m),86400);
system.debug(i1);
if(i1>=3600){
d2 = i1/3600; // need to take before decimal point NO Hours
hr = d2.intValue();
if((math.mod(integer.valueof(i1),3600) > 0))
{
i2 = math.mod(integer.valueof(i1),3600);
system.debug(i2);
if(i2>=60){
d3 = i2/60; // need to take before decimal point NO Mintues
min = d3.intValue();
sec = math.mod(integer.valueof(i2),60); // No seconds
}
}
}
}
timeValue = string.valueof(dy)+ ' Days, ' +string.valueof(hr)+ ' Hr, ' +string.valueof(min)+ ' Min, ' +string.valueof(sec)+ ' Sec';
oppo.Assignment_Time__c = timeValue;
}
else if(m<86400 && m>=3600){
d2 = m/3600; // need to take before decimal point NO Hours
hr = d2.intValue();
if((math.mod(integer.valueof(m),3600) > 0))
{
i2 = math.mod(integer.valueof(m),3600);
if(i2>=60){
d3 = i2/60; // need to take before decimal point NO Mintues
min = d3.intValue();
sec = math.mod(integer.valueof(i2),60); // NO seconds
}
}
timeValue = string.valueof(hr)+ ' Hr, ' +string.valueof(min)+ ' Min, ' +string.valueof(sec)+ ' Sec';
oppo.Assignment_Time__c = timeValue;
}
else if (m<3600 && m>=60){
d3 = m/60; // need to take before decimal point NO Mintues
min = d3.intValue();
sec = math.mod(integer.valueof(m),60); // NO seconds
timeValue = string.valueof(min)+ ' Min, ' +string.valueof(sec)+ ' Sec';
oppo.Assignment_Time__c = timeValue;
}
else if (m<60){
sec = integer.valueof(m);
timeValue = string.valueof(sec)+ ' Sec';
oppo.Assignment_Time__c = timeValue;
}
}

}
}
}
}
}