• shobana shobana 1
  • NEWBIE
  • 80 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 28
    Replies
Hi i am trying to deploy the apex class,controller and test class from one sandbox environment to another. I have 96% code coverage whil edeploying it showing 64% in destination sanbox environment. I didn't use seealldata also.
can anyone help to solve this.
Hi  i have replicated the duplicate management rule in Apex class for  Account Object. But am getting only 64% code coverage. Can anyone help me to increase the code coverage.
User-added image
In Lead and contact   object i have a trigger which  check if there is any duplicate email Id. If it has duplicate it throw an error "Provided email id already exist for another record". This scenario is working fine.

But in the lead conversion if i try to merge twith exiting account and contact  record   its throwing an error like "Error: Validation error on Contact: Error:Provided email id already exist for another record"

 
trigger InsertingBU on Opportunity (after update) {
  Set<Id> accountIds = new Set<Id>();
  for(Opportunity o : Trigger.New)
     accountIds.add(o.AccountId);
  list<Business_Unit_Company__c> BUCUpdate = new   list<Business_Unit_Company__c>();   
  list<Business_Unit_Company__c> Bus1 = new list<Business_Unit_Company__c>();
  Map<Id,Business_Unit_Company__c> bus = new Map<Id,Business_unit_Company__c>();
  set<string> busStage = new set<string>();
  for(Business_Unit_Company__c bu : [Select Business_Unit__c,Company__c,Stage__c from Business_Unit_Company__c where Company__c IN: accountIds]){
      bus.put(bu.Business_Unit__c, bu);
      busStage.add(bu.Stage__c);
      }
  for(Opportunity o : Trigger.New) {
    if(o.Opportunity_Business_Unit__c != null && bus.get(o.Opportunity_Business_Unit__c) != null){

    if((busStage.Stage__c == 'Closed Lost') && ((o.StageName =='0 - Existing Customer Lead') || (o.StageName =='1 - Prospecting') || (o.StageName =='Qualification') ||(o.StageName =='2 - Client Interaction') ||(o.StageName =='Needs Analysis') ||
       (o.StageName =='3 - Quoting Client') ||(o.StageName =='Value Proposition') ||(o.StageName =='Id. Decision Makers') ||(o.StageName =='Perception Analysis') ||(o.StageName =='4 - Buying Signals') ||
       (o.StageName =='5 - Quoted/Final Negotiation') || (o.StageName =='Proposal/Price Quote') || (o.StageName =='Negotiation/Review'))   
       ){
       Business_Unit_Company__c bu1 = new Business_Unit_Company__c();
       Bu1.stage__c='Closed Lost';
       Bu1.Company__c=o.AccountId;
       Bu1.Business_Unit__c= o.Opportunity_Business_Unit__c;
       Bus1.add(bu1);
       break;
       }else if( (bus1.Stage__c== 'Open') && (o.StageName=='Closed Lost')){
       Business_Unit_Company__c Bu2 = new Business_Unit_Company__c();
       Bu2.stage__c='Closed Lost';
       Bu2.Company__c=o.AccountId;
       Bu2.Business_Unit__c= o.Opportunity_Business_Unit__c;
       Bus1.add(Bu2);
       break;
       }else if((bus1.Stage__c== 'Closed Lost') && (o.StageName=='Closed Won')){
       Business_Unit_Company__c Bu3 = new Business_Unit_Company__c();
       Bu3.stage__c='Closed Won';
       Bu3.Company__c=o.AccountId;
       Bu3.Business_Unit__c= o.Opportunity_Business_Unit__c;
       Bus1.add(Bu3);
       break;
       }       
  }else{
  Business_Unit_Company__c BUC = new  Business_Unit_Company__c();
        BUC.Company__c=o.AccountId;
        BUC.Business_Unit__c=o.Opportunity_Business_Unit__c;
        if(o.StageName == 'Closed Won' || o.StageName == 'Closed Lost'){
        BUC.Stage__c=o.StageName;
        }else{
        BUC.Stage__c='Open';
        } 
        BUCUpdate.add(BUC);       
        }
 
    
                          
}
    if(Bus1!= Null)
    update Bus1;
    if(BUCUpdate!= Null)
    insert BUCUpdate;
}
In the third for loop am getting error can anyone help me out to solve this...

Thanks
Shobana
 
The requirement is, When the user tries to update the address field in detail page using inline editing. When he click SAVE button in account,at that time it should save the Account and it should show an pop up window (In that i want to display related contact Name,Address field and checkbox as well as update button).

Am new to Apex coading, can anyone help me how to override the save button to show a pop up window if the address field is updated.
My scenario is ,If the user edit the opportunity after three business days from the closed date it should throw the error message.
(CASE(
MOD( CloseDate - DATE(1900, 1, 7), 7),
0, CloseDate+3, 
1, CloseDate+3, 
2, CloseDate+3, 
3, CloseDate+5, 
4, CloseDate+5, 
5,CloseDate+5, 
6,CloseDate+4, 

CloseDate))<=  TODAY()

It throwing an error but if i edit the Closed_Date at that time also its throwing an error. Can anyone help me out to solve this issue.

Thanks In Advance

My scenario is to show an error message if lead as duplicate email ID. In lead i have three email field .Email, Alternate email 1, Alternate email 2 should be checked to keep the email ids unique. For e.g. If an email has been entered as a primary email id then it cannot be entered as a primary or as an alternate email id for another contact and the vice versa. 

I wrote a code but its not working. Can anyone help me out to solve this.
 

trigger DuplicateLead on Lead(before insert, before update) {
 Map<String, Id> mapLeads = NEW Map<String, String>();
 for(Lead l : [SELECT Email, Alternate_Email1__c,Alternate_Email_2__c FROM Lead]) {
  if(l.Email != NULL) {
   mapLeads.put(l.Email, l.Id);
  }
  if(l.Alternate_Email1__c != NULL) {
   mapLeads.put(l.Alternate_Email1__c , l.Id);
  }
  if(l.Alternate_Email_2__c != NULL) {
   mapLeads.put(l.Alternate_Email_2__c, l.Id);
  }
 }
 for(Lead l : Trigger.NEW) {
  Boolean flag = FALSE;
   if ((l.Email==l.Alternate_Email1__c) || (l.Email==l.Alternate_Email_2__c) || (l.Alternate_Email1__c== l.Alternate_Email_2__c))
  if (mapLeads.containsKey(l.Email)) {
   flag = TRUE;
  }
  if (mapLeads.containsKey(l.Alternate_Email1__c )) {
   flag = TRUE;
  }
  if (mapLeads.containsKey(l.Alternate_Email_2__c )) {
   flag = TRUE;
  }
  if(flag) {
  l.addError('Error:Provided email id already exist for another record');
  }
 }
Thanks In Advance

My scenario is to calculate the holidays for an opportunity.  For this i have created an custom field(DateType: Integer) in opportunity called "Holidayslist__c"(This field i want to display no of holidays).

1.If my opportunity is in "Open" , i want to calculate the holidays between the opportunity CreatedDate field to TODAY.

2.If Opportunity is "Closed", i want to calculate the holidays between the CreatedDate field to ClosedDate.

I wrote a trigger but its not working and it will hit the governer limit. Can anyone give me suggestion how to do this.

Thanks In Advance.

trigger testholidays on Opportunity (before insert, before update) 
{
List<opportunity> lstOpp = new List<opportunity>();
        List<opportunity> lstOppToUpdate = new List<opportunity>();
        Map<Date,Integer> mapActivDateToCount = new Map<Date,Integer>();
        Set<Date> setDateOppCreated = new Set<Date>();
        list<opportunity> opp1 = [select id,Name,CreatedDate,Holidayslist__c
                                    from opportunity 
                                    where IsClosed =False];      
        for(Opportunity objOpp : opp1 )
        {
            lstOpp.add(objOpp);
            setDateOppCreated.add(objOpp.CreatedDate.date());
            
        }
        
         for(Holiday objHoilday : [ SELECT Id, ActivityDate
                                    FROM Holiday
                                    WHERE ActivityDate < TODAY 
                                    AND ActivityDate >: setDateOppCreated
                                    ])
        {
            Date dt = objHoilday.ActivityDate;
            if(mapActivDateToCount.containsKey(dt))
            {
                mapActivDateToCount.put(dt, mapActivDateToCount.get(dt)+1);
            }
            else
            {
                mapActivDateToCount.put(dt, 1);
            }
        }
        
        // I am not getting any way to avoid for inside for .
        for(Opportunity objOpp : lstOpp)
        {
           opp1[0].Holidayslist__c = 0;

            for(Date dtActivity : mapActivDateToCount.keySet())
            {
                if(dtActivity < objOpp.CreatedDate.date())
                {
                    opp1[0].Holidayslist__c +=  mapActivDateToCount.get(dtActivity);
                }
            }
            lstOppToUpdate.add(objOpp);
        }
        
        system.debug('=====lstOppToUpdate===='+lstOppToUpdate);
        
        Database.update(lstOppToUpdate, true);

}

I wrote a trigger which will count the contact and update in Accout field(Number_of_Contacts__c). But trigger will only work when i create a record in contact.But i want to do updation on existing records too. Can anyone help me out to solve this issue.

trigger ContactCount on Contact (after insert, after update, after delete, after undelete) {
    Map<Id, List<Contact>> mapAcctIdContactList = new Map<Id, List<Contact>>();
    Map<Id, List<Contact>> mapAcctIdDelContactList = new Map<Id, List<Contact>>();
    Set<Id> AcctIds = new Set<Id>();    
    List<Account> listAcct = new List<Account>();
    
    if(trigger.isInsert) {
        for(Contact Con : trigger.New) {
            if(String.isNotBlank(Con.AccountId)) {
                if(!mapAcctIdContactList.containsKey(Con.AccountId)) {
                    mapAcctIdContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdContactList.get(Con.AccountId).add(Con); 
                AcctIds.add(Con.AccountId);
            }   
        }  
    }
    
    if(trigger.isUpdate) {
        for(Contact Con : trigger.New) {
            if(String.isNotBlank(Con.AccountId) && Con.AccountId != trigger.oldMap.get(Con.Id).AccountId) {
                if(!mapAcctIdContactList.containsKey(Con.AccountId)){
                    mapAcctIdContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdContactList.get(Con.AccountId).add(Con); 
                AcctIds.add(Con.AccountId);
            } else if(String.isBlank(Con.AccountId) && String.isNotBlank(trigger.oldMap.get(Con.Id).AccountId)) {
                if(!mapAcctIdDelContactList.containsKey(Con.AccountId)){
                    mapAcctIdDelContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdDelContactList.get(Con.AccountId).add(Con);   
                AcctIds.add(trigger.oldMap.get(Con.Id).AccountId);
            }
        }  
    }
    
    if(trigger.isUndelete) {
        for(Contact Con : trigger.new) {
            if(String.isNotBlank(Con.AccountId)){
                if(!mapAcctIdContactList.containsKey(Con.AccountId)){
                    mapAcctIdContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdContactList.get(Con.AccountId).add(Con);     
                AcctIds.add(Con.AccountId);
            }
        }  
    }      

    if(trigger.isDelete) {
        for(Contact Con : trigger.Old) {
            if(String.isNotBlank(Con.AccountId)){
                if(!mapAcctIdDelContactList.containsKey(Con.AccountId)){
                    mapAcctIdDelContactList.put(Con.AccountId, new List<Contact>());
                }
                mapAcctIdDelContactList.get(Con.AccountId).add(Con);    
                AcctIds.add(Con.AccountId); 
            }
        }  
    }   
    
    if(AcctIds.size() > 0) {
        listAcct = [SELECT Id, Number_of_Contacts__c FROM Account WHERE Id IN : AcctIds];
        
        for(Account acct : listAcct) {
            Integer noOfConts = 0;
            if(mapAcctIdContactList.containsKey(acct.Id)) {
                noOfConts += mapAcctIdContactList.get(acct.Id).size();
            }
            if(mapAcctIdDelContactList.containsKey(acct.Id)) {
                noOfConts -= mapAcctIdDelContactList.get(acct.Id).size();
            }
            acct.Number_of_Contacts__c = acct.Number_of_Contacts__c == null ? noOfConts : (acct.Number_of_Contacts__c + noOfConts);
        }
        
        update listAcct;    
    }
}
My scenario is i want to insert a orderItem whenever the opportunitylineItem is created(only when opportunity's StageName is "closedWon").
Actually in my Triggers its not throughing any error but trigger is not firring.
Anyone give me an suggestion to solve this issue.
My code is
trigger ToUpdateProduct on OpportunityLineItem (before insert) {
Map<String,Order> od = new Map<String,Order>();
Set<Id> s = new Set<Id>();
List<OrderItem> oiList = new List<OrderItem>();
for(OpportunityLineItem olt : Trigger.New) 
 If(olt.Opportunity.StageName == 'Closed Won')
   s.add(olt.OpportunityId);

for(Order o : [select Id,OpportunityId from Order where OpportunityId IN:s])  
   od.put(String.valueOf(o.OpportunityId),o);

for(OpportunityLineItem olt : Trigger.New) 
{
  If(olt.Opportunity.StageName == 'Closed Won'){
    OrderItem oi = new OrderItem();
    oi.OrderId = od.get(String.valueOf(olt.OpportunityId)).Id;
    oi.Quantity = olt.Quantity;
    oi.PricebookEntryId = olt.PricebookEntryId;
    oi.UnitPrice = olt.UnitPrice;  
    oiList.add(oi); }
}

If(oiList.size() > 0)
 insert oiList;


}
Thanks in Advance

 
My task is when opportunity is "closed won"  automaticlly it should create order(populate opportunity fields) and orderitems(all opportunitylineitem products should be created in it).

I am pretty new to Salesforce development. Can anyone give me suggestion to do this.
trigger name on Opportunity (after update) {
set<id> ids = new set<id>();
for(opportunity O:trigger.new) {
if(O.StageName =='ClosedWon'){
ids.add(O.id);
}}
orderItem orl = new orderItem(); 
Opportunity opp = [select id,AccountId,CloseDate,(select Name,ProductCode,Quantity,OpportunityId 
                                  from OpportunityLineItems)
                           from Opportunity 
                           where  id in:Trigger.NewMap.keySet() AND Opportunity.StageName =: 'Closed Won'];


Order ord = new Order();
  ord.OpportunityId=opp.id;
  ord.AccountId =opp.AccountId;
  ord.EffectiveDate = opp.CloseDate;
  ord.Status= 'Draft'; 
  insert ord;
for(OpportunityLineItem opl : opp.OpportunityLineItems){
   orl.Order= ord; 
  orl.Quantity=opl.Quantity;

  
  }
  
  insert orl;
  
                                              
}



 

My scenario is to create a Custom button in Account object while clicking that button it show a form which has   Case field and i have  created two custom fields in Case  Account_Name__c(reads the value of Name from Account),Account_Type__C(reads the value of Type from Account) then I want to add submit custom button  in that form after clicking that it will create a case record for a related account.

 Actually Case is creating but i want to update the Account_Name__c(reads the value of Name from Account),Account_Type__C(reads the value of Type from Account) before case is created which means i want to see those data in a form itself. But for me after creating case only it showing the Account_Name__c,Account_Type__C
 

public class CreateCaseController {
public Case objCase { get; set; }
public Id AId;  
public Account c { get; set; }
public CreateCaseController() {
AId = ApexPages.currentPage().getParameters().get('id');
objCase = NEW Case();
}
public PageReference createCase() {
c =[SELECT Name,Id,Type
                    FROM Account WHERE Id =: AId];
objCase.AccountId = AId;
objCase.Account_Name__c = c.Name;
objCase.Account_Type__c = c.Type;
insert objCase;
PageReference pRef = NEW PageReference('/'+objCase.Id);
pRef.setRedirect(TRUE);
return pRef;
    }
}

VF Page: 

<apex:page controller="CreateCaseController">
<apex:form >
<apex:PageBlock title="Create Case" >
<apex:pageBlockSection columns="2">
<apex:inputField value="{!objCase.Account_Name__c}" />
<apex:inputField value="{!objCase.Status}"/>
<apex:inputField value="{!objCase.Origin}"/>
<apex:inputField value="{!objCase.Account_Type__c}"/>
<apex:inputField value="{!objCase.Type}"/>
<apex:inputField value="{!objCase.Reason}"/>
<apex:inputField value="{!objCase.ContactId}"/>
<apex:inputField value="{!objCase.Description}"/>               
</apex:pageBlockSection>
<apex:pageBlockButtons location="Bottom" >
<apex:commandButton value="Submit" action="{!createCase}" />
</apex:pageBlockButtons>
</apex:PageBlock>
</apex:form>
</apex:page>
My scenario is to create a Custom button in Account object while clicking that button it show some required field in Case their I want to add submit custom button after clicking that it will create a case record from that account.

I am pretty new to Salesforce development. Can anyone give me suggestion to do this.

Thanks in Advance.
The requirement is, When the user tries to update the address field in detail page using inline editing. When he click SAVE button in account,at that time it should save the Account and it should show an pop up window (In that i want to display related contact Name,Address field and checkbox as well as update button).

Am new to Apex coading, can anyone help me how to override the save button to show a pop up window if the address field is updated.
Hi i am trying to deploy the apex class,controller and test class from one sandbox environment to another. I have 96% code coverage whil edeploying it showing 64% in destination sanbox environment. I didn't use seealldata also.
can anyone help to solve this.
Hi  i have replicated the duplicate management rule in Apex class for  Account Object. But am getting only 64% code coverage. Can anyone help me to increase the code coverage.
User-added image
In Lead and contact   object i have a trigger which  check if there is any duplicate email Id. If it has duplicate it throw an error "Provided email id already exist for another record". This scenario is working fine.

But in the lead conversion if i try to merge twith exiting account and contact  record   its throwing an error like "Error: Validation error on Contact: Error:Provided email id already exist for another record"

 
trigger InsertingBU on Opportunity (after update) {
  Set<Id> accountIds = new Set<Id>();
  for(Opportunity o : Trigger.New)
     accountIds.add(o.AccountId);
  list<Business_Unit_Company__c> BUCUpdate = new   list<Business_Unit_Company__c>();   
  list<Business_Unit_Company__c> Bus1 = new list<Business_Unit_Company__c>();
  Map<Id,Business_Unit_Company__c> bus = new Map<Id,Business_unit_Company__c>();
  set<string> busStage = new set<string>();
  for(Business_Unit_Company__c bu : [Select Business_Unit__c,Company__c,Stage__c from Business_Unit_Company__c where Company__c IN: accountIds]){
      bus.put(bu.Business_Unit__c, bu);
      busStage.add(bu.Stage__c);
      }
  for(Opportunity o : Trigger.New) {
    if(o.Opportunity_Business_Unit__c != null && bus.get(o.Opportunity_Business_Unit__c) != null){

    if((busStage.Stage__c == 'Closed Lost') && ((o.StageName =='0 - Existing Customer Lead') || (o.StageName =='1 - Prospecting') || (o.StageName =='Qualification') ||(o.StageName =='2 - Client Interaction') ||(o.StageName =='Needs Analysis') ||
       (o.StageName =='3 - Quoting Client') ||(o.StageName =='Value Proposition') ||(o.StageName =='Id. Decision Makers') ||(o.StageName =='Perception Analysis') ||(o.StageName =='4 - Buying Signals') ||
       (o.StageName =='5 - Quoted/Final Negotiation') || (o.StageName =='Proposal/Price Quote') || (o.StageName =='Negotiation/Review'))   
       ){
       Business_Unit_Company__c bu1 = new Business_Unit_Company__c();
       Bu1.stage__c='Closed Lost';
       Bu1.Company__c=o.AccountId;
       Bu1.Business_Unit__c= o.Opportunity_Business_Unit__c;
       Bus1.add(bu1);
       break;
       }else if( (bus1.Stage__c== 'Open') && (o.StageName=='Closed Lost')){
       Business_Unit_Company__c Bu2 = new Business_Unit_Company__c();
       Bu2.stage__c='Closed Lost';
       Bu2.Company__c=o.AccountId;
       Bu2.Business_Unit__c= o.Opportunity_Business_Unit__c;
       Bus1.add(Bu2);
       break;
       }else if((bus1.Stage__c== 'Closed Lost') && (o.StageName=='Closed Won')){
       Business_Unit_Company__c Bu3 = new Business_Unit_Company__c();
       Bu3.stage__c='Closed Won';
       Bu3.Company__c=o.AccountId;
       Bu3.Business_Unit__c= o.Opportunity_Business_Unit__c;
       Bus1.add(Bu3);
       break;
       }       
  }else{
  Business_Unit_Company__c BUC = new  Business_Unit_Company__c();
        BUC.Company__c=o.AccountId;
        BUC.Business_Unit__c=o.Opportunity_Business_Unit__c;
        if(o.StageName == 'Closed Won' || o.StageName == 'Closed Lost'){
        BUC.Stage__c=o.StageName;
        }else{
        BUC.Stage__c='Open';
        } 
        BUCUpdate.add(BUC);       
        }
 
    
                          
}
    if(Bus1!= Null)
    update Bus1;
    if(BUCUpdate!= Null)
    insert BUCUpdate;
}
In the third for loop am getting error can anyone help me out to solve this...

Thanks
Shobana
 
The requirement is, When the user tries to update the address field in detail page using inline editing. When he click SAVE button in account,at that time it should save the Account and it should show an pop up window (In that i want to display related contact Name,Address field and checkbox as well as update button).

Am new to Apex coading, can anyone help me how to override the save button to show a pop up window if the address field is updated.

My scenario is to show an error message if lead as duplicate email ID. In lead i have three email field .Email, Alternate email 1, Alternate email 2 should be checked to keep the email ids unique. For e.g. If an email has been entered as a primary email id then it cannot be entered as a primary or as an alternate email id for another contact and the vice versa. 

I wrote a code but its not working. Can anyone help me out to solve this.
 

trigger DuplicateLead on Lead(before insert, before update) {
 Map<String, Id> mapLeads = NEW Map<String, String>();
 for(Lead l : [SELECT Email, Alternate_Email1__c,Alternate_Email_2__c FROM Lead]) {
  if(l.Email != NULL) {
   mapLeads.put(l.Email, l.Id);
  }
  if(l.Alternate_Email1__c != NULL) {
   mapLeads.put(l.Alternate_Email1__c , l.Id);
  }
  if(l.Alternate_Email_2__c != NULL) {
   mapLeads.put(l.Alternate_Email_2__c, l.Id);
  }
 }
 for(Lead l : Trigger.NEW) {
  Boolean flag = FALSE;
   if ((l.Email==l.Alternate_Email1__c) || (l.Email==l.Alternate_Email_2__c) || (l.Alternate_Email1__c== l.Alternate_Email_2__c))
  if (mapLeads.containsKey(l.Email)) {
   flag = TRUE;
  }
  if (mapLeads.containsKey(l.Alternate_Email1__c )) {
   flag = TRUE;
  }
  if (mapLeads.containsKey(l.Alternate_Email_2__c )) {
   flag = TRUE;
  }
  if(flag) {
  l.addError('Error:Provided email id already exist for another record');
  }
 }
Thanks In Advance

My scenario is to calculate the holidays for an opportunity.  For this i have created an custom field(DateType: Integer) in opportunity called "Holidayslist__c"(This field i want to display no of holidays).

1.If my opportunity is in "Open" , i want to calculate the holidays between the opportunity CreatedDate field to TODAY.

2.If Opportunity is "Closed", i want to calculate the holidays between the CreatedDate field to ClosedDate.

I wrote a trigger but its not working and it will hit the governer limit. Can anyone give me suggestion how to do this.

Thanks In Advance.

trigger testholidays on Opportunity (before insert, before update) 
{
List<opportunity> lstOpp = new List<opportunity>();
        List<opportunity> lstOppToUpdate = new List<opportunity>();
        Map<Date,Integer> mapActivDateToCount = new Map<Date,Integer>();
        Set<Date> setDateOppCreated = new Set<Date>();
        list<opportunity> opp1 = [select id,Name,CreatedDate,Holidayslist__c
                                    from opportunity 
                                    where IsClosed =False];      
        for(Opportunity objOpp : opp1 )
        {
            lstOpp.add(objOpp);
            setDateOppCreated.add(objOpp.CreatedDate.date());
            
        }
        
         for(Holiday objHoilday : [ SELECT Id, ActivityDate
                                    FROM Holiday
                                    WHERE ActivityDate < TODAY 
                                    AND ActivityDate >: setDateOppCreated
                                    ])
        {
            Date dt = objHoilday.ActivityDate;
            if(mapActivDateToCount.containsKey(dt))
            {
                mapActivDateToCount.put(dt, mapActivDateToCount.get(dt)+1);
            }
            else
            {
                mapActivDateToCount.put(dt, 1);
            }
        }
        
        // I am not getting any way to avoid for inside for .
        for(Opportunity objOpp : lstOpp)
        {
           opp1[0].Holidayslist__c = 0;

            for(Date dtActivity : mapActivDateToCount.keySet())
            {
                if(dtActivity < objOpp.CreatedDate.date())
                {
                    opp1[0].Holidayslist__c +=  mapActivDateToCount.get(dtActivity);
                }
            }
            lstOppToUpdate.add(objOpp);
        }
        
        system.debug('=====lstOppToUpdate===='+lstOppToUpdate);
        
        Database.update(lstOppToUpdate, true);

}