• amit_sfdcT-2
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies

I want find the Age of Employee With the help of Trigger Based on Date of Birth and Todays Date?

Hi,

 

New to Apex and programming in Java in general here, so bear with me.

 

I have a junction object  set up CaseServiceOrderAssoc__c to connect cases to a custom object called Orders__c. The junction object is needed because I need a many to many relationship to orders and cases and this works great.  However, in the business process, we want to check to make sure all related cases to an order are closed, before I can also close the order.  I can create a roll-up summary field in Orders__c from CaseServiceOrderAssoc__c to do counting of open cases, but I need a trigger from the Case object to set the related junction object records to "true". This is what I've got as a trigger (through reading other solutions and piecing my solution from them.) Like I said, I have little experience with all this, so if the code is funny looking, you know why.

 

What am I doing wrong?

 

trigger updateCaseClosed on Case (after update) {
    
    // This trigger will update the closed case countable field in the Case 2 Order Association Object 
    
    Integer i = 0;
    Set<ID> CaseServiceOrderAssocIds = new Set<ID>();
    Map<ID, Boolean> id2CaseClosed = new Map<ID, Boolean>();
    
    for (Case c : Trigger.new)
    {
        if(c.IsClosed == True)
        {
            CaseServiceOrderAssocIds.add(c.Id);
            id2CaseClosed.put(c.Id, c.IsClosed);
        }
        i++;    
    } 
    List<CaseServiceOrderAssoc__c> c2oassocs = [select Id  from CaseServiceOrderAssoc__c where Id in :CaseServiceOrderAssocIds];
    
    for (CaseServiceOrderAssoc__c assocs : c2oassocs)
    {
        assocs.Related_Case_Closed_Countable__c = id2CaseClosed.get(assocs.Id);
    }
    
    update c2oassocs;
}

I have a controller that sends notications a month before a candidate's birthday. I can't seem to cover the else part of my if statements in my test class.The red parts being the ones not covered.

Kindly assist:

 

public class candidateEmailNotification{

public List<Candidates__c> candidates = [select First_Name__c,Name,Date_of_Birth__c
                         from Candidates__c];
       
 
       public List<Candidates__c> includeInEmail(){  
            
              List<Candidates__c> newcadidates = new  List<Candidates__c>(); 
              for(Candidates__c c: candidates) {

                  
                    if(c.Date_of_Birth__c==null){
                    
                    }
               else{
                    
              
               if(c.Date_of_Birth__c.dayOfYear() - System.today().dayOfYear()==30){

               
               newcadidates.add(c);
             
               }
               
           }
          } 

          return newcadidates;
        } 
        
        
        
     public String composeMessage(){
     
        
       String emailMsg = '';
       List<Candidates__c> c = includeInEmail();

       if(includeInEmail().size()==0){
       return null;
          }else{
       for(Integer i = 0;i< c.size(); i++){ emailMsg += '<tr><td>'+c.get(i).First_Name__c +'</td><td>'+c.get(i).Name+'</td><td style = color:red> '+c.get(i).Date_of_Birth__c.day()+ ' - '+c.get(i).Date_of_Birth__c.month() +' - '+System.today().year()+'</td></tr>';
       
    
       }
      
       
        } 
         
       return '<table><tr><th>First Name </th><th>Last Name</th><th>Birthday</th></tr>'+emailMsg+'</table>';
        }           
  
    public void sendMail() {
         if(composeMessage()==null){
         
         }else{
 
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {'martin.mathu@jjpeople.com'}; mail.setToAddresses(toAddresses); mail.setSubject(' Birthday Notification'); mail.setUseSignature(false); mail.setHtmlBody('<div style=color:green;><u>The Following Candidate(s) Have Birthday in one Month Time</u></div><br>' + composeMessage()); // Send the email Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });  
    }
    }

}

 Below is my test class:

@isTest
public class CandidateEmailNotificationTest {
    static testMethod void EmailNotificationTest() {
        List<Candidates__c> cand =  new List<Candidates__c>();
        Candidates__c candidate = new Candidates__c(Candidate_Source__c='Monster',Main_Email__c='emaill@email.com',Candidate_Mobile_Phone__c='000',Name ='LastN',First_Name__c = 'Tester',Candidate_Address__c='000',Date_of_Birth__c = System.today());
        Candidates__c candidate2 = new Candidates__c(Candidate_Source__c='test',Main_Email__c='emaill2@email.com',Candidate_Mobile_Phone__c='0011',Name ='LastN2',First_Name__c = 'Tester2',Candidate_Address__c='00022',Date_of_Birth__c = System.today());
        cand.add(candidate);
        cand.add(candidate2);
        insert cand;        
        
        Test.startTest();
        candidateEmailNotification cn =  new candidateEmailNotification();
        cn.candidates = cand;
        cn.includeInEmail();
        cn.composeMessage();
        cn.sendMail();       
        Test.stopTest();
                
        System.assertEquals(candidate.Date_of_Birth__c, System.today());
        }

}

 

Hello,

 

I try to deploy a trigger and its test class in production but I have this error :

Failure Message: "System.LimitException: Too many query rows: 50001", Failure Stack Trace:...

 

The code coverage of this trigger is 100%.

 

I think the pb is due to another test class for another trigger but the both (the 2 triggers and the 2 test classes) are on the same object (Opportunity).

The other trigger is already deployed.

 

How can I solve this problem ?

 

Thank you.

Hello,

 

I have a simple trigger on the Opportunity object that fires when an Opportunity is edited and forces an edit/save on the OpportunityLineItems associated with the Opportunity.  When I try to Data Load some bulk changes, I get the following error:

 

System.LimitException: Too many SOQL queries: 101

 

I'm fairly new to Apex code.  I believe the problem is that I am running SOQL inside a FOR loop, but I'm not quite sure how to resolve it.  My trigger is below.  Any help would be appreciated.  Thanks.

 

 

trigger UpdateDeliverables on Opportunity (after insert, after update) {
   // Forces Edit/Save on Deliverables in order to fire Workflow field Update to update quantity field with Q__c value    

FOR(Opportunity opp : Trigger.new)  {

    LIST<OpportunityLineItem> oppLine = [SELECT Id
    FROM OpportunityLineItem
    WHERE OpportunityId = :opp.Id
    AND Flat_Price__c != TRUE];
    
    IF(oppLine.size() > 0)
    update oppLine;
    }

}