Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger Effectivefilingdate on Patent__c (after insert,after update) {
- if(trigger.isAfter)
- if(trigger.isinsert || trigger.isupdate)
- {
- List<Patent__c> objPatsToUpdate = NEW List<Patent__c>();
- Set<Id> PatIds = new Set<Id>();
- for (Patent__c Pat : Trigger.new){
- PatIds.add(Pat.id);
- }
- for (Patent__c objPatent : [select Id,Effective_Filing_Date__c,Application_Date__c,Priority_Dates__c from Patent__c where Id IN:PatIds])
- {
- //Patent__c oldpat = Trigger.oldMap.get(objPatent.Id);
- if (objPatent.Priority_Dates__c == Null)
- {
- objPatent.Effective_Filing_Date__c = objPatent.Application_Date__c;
- }
- if (objPatent.Priority_Dates__c !=null)
- {
- List<date> lstDtPrioirtyDates = New List<date>();
- List<date> lstDtPrioirtyDates1 = New List<date>();
- List<String> lstStrPriorityDates = objPatent.Priority_Dates__c.replaceAll( '\s+', '').split(',');
- date mydate;
- system.debug(lstStrPriorityDates);
- for(string st : lstStrPriorityDates)
- {
- date dt = date.valueof(st);
- if(mydate == null)
- {
- mydate = dt;
- }
- else{
- if(mydate > dt)
- mydate=dt;
- }
- }
- objPatent.Effective_Filing_Date__c = mydate;
- system.debug('Small date'+mydate);
- }
- objPatsToUpdate.add(objPatent);
- }
- if(!objPatsToUpdate.isEmpty())
- {
- update objPatsToUpdate;
- }
- }}
Add Comment
Please, Sign In to add comment