Guest User

Untitled

a guest
Apr 25th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. trigger Effectivefilingdate on Patent__c (after insert,after update) {
  2. if(trigger.isAfter)
  3. if(trigger.isinsert || trigger.isupdate)
  4. {
  5. List<Patent__c> objPatsToUpdate = NEW List<Patent__c>();
  6. Set<Id> PatIds = new Set<Id>();
  7. for (Patent__c Pat : Trigger.new){
  8. PatIds.add(Pat.id);
  9. }
  10. for (Patent__c objPatent : [select Id,Effective_Filing_Date__c,Application_Date__c,Priority_Dates__c from Patent__c where Id IN:PatIds])
  11. {
  12. //Patent__c oldpat = Trigger.oldMap.get(objPatent.Id);
  13.  
  14. if (objPatent.Priority_Dates__c == Null)
  15. {
  16. objPatent.Effective_Filing_Date__c = objPatent.Application_Date__c;
  17. }
  18. if (objPatent.Priority_Dates__c !=null)
  19. {
  20. List<date> lstDtPrioirtyDates = New List<date>();
  21. List<date> lstDtPrioirtyDates1 = New List<date>();
  22. List<String> lstStrPriorityDates = objPatent.Priority_Dates__c.replaceAll( '\s+', '').split(',');
  23. date mydate;
  24. system.debug(lstStrPriorityDates);
  25. for(string st : lstStrPriorityDates)
  26. {
  27. date dt = date.valueof(st);
  28. if(mydate == null)
  29. {
  30. mydate = dt;
  31. }
  32. else{
  33. if(mydate > dt)
  34. mydate=dt;
  35. }
  36. }
  37. objPatent.Effective_Filing_Date__c = mydate;
  38. system.debug('Small date'+mydate);
  39. }
  40. objPatsToUpdate.add(objPatent);
  41. }
  42. if(!objPatsToUpdate.isEmpty())
  43. {
  44. update objPatsToUpdate;
  45. }
  46. }}
Add Comment
Please, Sign In to add comment