• Prathyusha
  • NEWBIE
  • 0 Points
  • Member since 2013

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

Hi,

Hi,

Need to write a trigger on the following requirement:

 

When the ‘Active’ status on the attached Service Agreement object goes to ‘Inactive’, the associated Equipment Object's field is marked on the ‘Contract Status’ field with ‘Under Expired Contract’.

 

The service agreement object is in lookup relationship with the equipment object.

I have written a piece of trigger. Is there any failure or Governer Limits of Apex will it serve my purpose.

 

 

 

trigger serviceAgreementInactive on Service_Agreement__c(after update){

Map<ID, Service_Agreement__c > oldMap = new Map<ID,
Service_Agreement__c >(Trigger.old);
List<Id> equipmentIds = new List<Id>();
for(Service_Agreement__c serv : trigger.new){

if(serv.status__c == 'Inactive' && oldMap.get(serv.Id).status__c !='Inactive')
equipmentIds.add(serv.Id);

    }
    List<Equipment__c> equipmentsToMakeExpire = [Select id, Contract_Status__c from Equipment__c where id IN :equipmentIds];

    for(Equipment__c e : equipmentsToMakeExpire)
        e.Contract_Status__c = 'Under Expired Contract';

    if(!equipmentsToMakeExpire.isEmpty()) update equipmentsToMakeExpire;

  • November 15, 2013
  • Like
  • 0

Below is my Code.   I am getting an error that I am attepting to dereference a null object.  I am not sure how to fix it.   I am very new to writtng triggers and any help would be very appriciated. 

 

 

 

trigger LastActDate3 on Task (after insert, after update) {

Set <ID> OptyIDs = new Set <ID> ();

Set<Id> Ready4Update = new Set<Id>();

List<Opportunity> OppList = new List<Opportunity>();

for (Task t: Trigger.new){

OptyIDs.add(t.WhatID);

}

Map<ID, Opportunity> OptyMap = new Map<ID, Opportunity> ([Select ID,Last_Activity__c from Opportunity where ID in :OptyIDs]);

for (Task t: Trigger.new){

if (t.WhatID != NULL){

 

Opportunity OptyRec = OptyMap.get(t.WhatID);

If (((!t.subject.contains('Act-On Email')) )){

 

Optyrec.Last_Activity__c = t.ActivityDate;

 

}

if(!Ready4Update.contains(OptyRec.id)){

 

   OppList.add(OptyRec);   

   Ready4Update.add(OptyRec.id);

 

}

 

}

}

if(OppList.size() > 0){

update oppList;

}

}

   
 

Hi All

 

I want to update the OwnerId of a record based on a value of picklist (UCB_Status__c). 

Normally it would be easy to do with a before insert, before update trigger. But there is already a Before Insert, Before Update trigger in the system for the same object and I can not touch that trigger. 

 

My trigger:

trigger UCB_Coaching_Report_A_I_A_U on Coaching_Report_vod__c (after Insert, after Update)
{
      UCB_ManageCoachingReport.assignOwner(Trigger.newMap.keySet());
}

 The trigger that can not be touched: 

trigger VOD_COACHING_REPORT_BEFORE_INSUPD_TRIGGER on Coaching_Report_vod__c ( before insert, before update) {
    if(VEEVA_PROCESS_FLAGS.getUpdateCR()== true){
        System.Debug('Veeva process_Flags');
        return;
    }
    
    //UCB_ManageCoachingReport.assignOwner(Trigger.New, Trigger.oldMap);
    
   for (Integer i = 0 ; i < Trigger.new.size(); i++) 
    {
        System.Debug('In Veeva for lus');
       if (Trigger.new[i].Employee_vod__c != null ) 
         {
             System.Debug('In Veeva if employee is verschillend van 0');
             Trigger.new[i].OwnerId = Trigger.new[i].Employee_vod__c;
         }
    }   
}

 

 

The class which contains the invoked method:

public class UCB_ManageCoachingReport{   
   public static void assignManager(List<Coaching_Report_vod__c> coachingReportList){
        for(Coaching_Report_vod__c cr: coachingReportList){
            System.Debug('de user met id ' + UserInfo.getUserId() + ' wordt toegewezen aan het mananager veld');
            cr.Manager_vod__c = UserInfo.getUserId();
        }
    }

public static void assignOwner(Set<Id> crIds)
{         
       List<Coaching_Report_vod__c> crList = 
         [select Id, OwnerId, UCB_Status__c, Review_Date__c, Manager_vod__c, Employee_vod__c from Coaching_Report_vod__c where Id in:crIds];
       
          for(Coaching_Report_vod__c cr: crList )
          {               
                     if(cr.UCB_Status__c == 'Sent')
                     {
                       cr.OwnerId = cr.Employee_vod__c;
                     }
                     else
                     {
                        cr.OwnerId = cr.Manager_vod__c;
                     }     
           }
         
          update crList;      
    }
}

 

When I create a new Coaching Report I get the following error:

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UCB_Coaching_Report_A_I_A_U caused an unexpected exception, contact your administrator: UCB_Coaching_Report_A_I_A_U: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id a1DZ0000000WFLmMAO; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UCB_Coaching_Report_A_I_A_U: maximum trigger depth exceeded Coaching_Report_vod trigger event AfterInsert for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm] Coaching_Report_vod trigger event AfterUpdate for [a1DZ0000000WFLm]: []: Class.UCB_ManageCoachingReport.assignOwner: line 33, column 1

 

 

I spend multiple our, changed my code 23235235253 times and still don't got a solution. 

Is it just not possible due to the trigger I can not change? 

 

Thanks in advance!!! 

Our architecture is that we are storing contact info from a NPPES data base which they will provide monthly 5000 contacts 

 

we need to load into salesforce contacts but immediately we have to create an account with contact firstname,lastname .

 

And also need to verify if this firstname, lastname already exists must attach the contact to that account if not creat new account.

 

So how to achieve this any suggestions or code snippets either bulk trigger,batch,@future class which best fits to my

 

 

requirement Iam pretty new to development.Please let me know .

  • November 15, 2013
  • Like
  • 0