• Matthew Holdgate
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 9
    Replies
Hi All

I am really struggling to find my error here. 

My Apex Class is 
Global class DOUM_WaitingOnApprovals implements Schedulable{
    
    Global static Void ListDOUs() {
        
        List<DOUM_DOU__c> Waitings = [SELECT Id, Name, DOUM_Req_BMgr__r.Email, DOUM_Requester_IT_Mgr__r.Email, DOUM_Domain_Lead__r.Email, DOUM_IT_Domain_Lead__r.Email, DOUM_DOU__c.DOUM_DOU_Approval_Status__c, DOUM_DOU__c.LastModifiedDate, DOUM_DOU__c.DOUM_Req_BMgr__c, DOUM_DOU__c.DOUM_Requester_IT_Mgr__c, DOUM_DOU__c.DOUM_Domain_Lead__c, DOUM_DOU__c.DOUM_WAF__c, DOUM_DOU__c.DOUM_IT_Domain_Lead__c, DOUM_DOU__c.DOUM_BM_Approval__c, DOUM_DOU__c.DOUM_ITM_Approval__c, DOUM_DOU__c.DOUM_DL_Approval__c, DOUM_DOU__c.DOUM_ITDL_Approval__c FROM DOUM_DOU__c WHERE DOUM_DOU_Approval_Status__c = 'In Approval'  AND  LastModifiedDate >: System.now()-3];
        
        
        String Email;
        Boolean BM;
        Boolean ITM;
        Boolean DL;
        Boolean ITDL;
        
        for(DOUM_DOU__c rec : Waitings){
            
            String Name = rec.Name;
            System.debug('Name: '+Name);
            
            IF(String.ValueOf(rec.DOUM_Req_BMgr__c) == Null){ 
                BM = TRUE ;
            }
            ELSE{ 
                IF(rec.DOUM_BM_Approval__c == TRUE){ BM = TRUE; }
                ELSE{ BM = FALSE; }
            }
            
            System.debug('BM'+BM);
            
            IF(String.ValueOf(rec.DOUM_Requester_IT_Mgr__c) == Null){ 
                ITM = TRUE ;
            }
            ELSE{ 
                IF(rec.DOUM_ITM_Approval__c == TRUE){ ITM = TRUE; }
                ELSE{ ITM = FALSE; }
            }
            
            System.debug('ITM'+ITM);
            
            IF(String.ValueOf(rec.DOUM_Domain_Lead__c) == Null){ 
                DL = TRUE ;
            }
            ELSE{ 
                IF(rec.DOUM_DL_Approval__c == TRUE){ DL = TRUE; }
                ELSE{ DL = FALSE; }
            }
            
            System.debug('DL'+DL);
            
            IF(String.ValueOf(rec.DOUM_IT_Domain_Lead__c) == Null){ 
                ITDL = TRUE ;
            }
            ELSE{ 
                IF(rec.DOUM_ITDL_Approval__c == TRUE){ ITDL = TRUE; }
                ELSE{ ITDL = FALSE; }
            }
            
            System.debug('ITDL'+ITDL);
        
            IF( BM == FALSE ){ Email = rec.DOUM_Req_BMgr__r.Email ; System.debug('BM IF');} 
            ELSE IF(ITM == FALSE ){ Email = rec.DOUM_Requester_IT_Mgr__r.Email ; System.debug('ITM IF');}
            ELSE IF(DL == FALSE ){ Email = rec.DOUM_Domain_Lead__r.Email ; System.debug('DL IF');}
            ELSE IF(ITDL == FALSE ){ Email = rec.DOUM_IT_Domain_Lead__r.Email ; System.debug('ITDL IF');} 
            ELSE { break; }
            
            System.debug('Email'+Email);
        
            rec.DOUM_WAF__c = Email ;
            
            System.debug('WAF:'+rec.DOUM_WAF__c);
        
            update rec;
            
            System.debug('After Update WAF'+rec.DOUM_WAF__c);
        }
    }   
    
       global void execute(SchedulableContext sc) {
    
        DOUM_WaitingOnApprovals WA = new DOUM_WaitingOnApprovals();
        
        String DOU = '0 0 0 ? * MON-FRI';
        String jobID = System.schedule('DOUM_WaitingOnApprovals', DOU, WA);

        
   }
}
It pulls the list of records where their approval status is "In Approval" and was edited more than 3 days ago. When it finds a record it does some other checks and populates an email field with a user email. It works when I run it from a button but when writing the test class it works in the debug correctly but fails the assertion checks.

My Test Class is 
@isTest
public class TEST_DOUM_WaitingOnApprovals {
	static testMethod void TestWoA(){
    Profile profileId = [SELECT Id FROM Profile WHERE Name='GSO Basic User_Platform'];
        User u = new user();
        u.LastName = 'Test Coe';
        u.Email = 'test1@test.com';
        u.Alias = 'Tcode';
        u.Username = 'test1234fdfdfefe4trfd34@test.com';
        u.CommunityNickname = 'test122';
        u.LocaleSidKey = 'en_US';
        u.ProfileId = profileId.Id;
        u.TimeZoneSidKey = 'GMT';
        u.LanguageLocaleKey = 'en_US';
        u.EmailEncodingKey = 'UTF-8';
        insert u;
        
        User uBM = new user();
        uBM.LastName = 'Test BM';
        uBM.Email = 'testBM@test.com';
        uBM.Alias = 'BM';
        uBM.Username = 'test1234fdfdfefe4trfd34BM@test.com';
        uBM.CommunityNickname = 'test122BM';
        uBM.LocaleSidKey = 'en_US';
        uBM.ProfileId = profileId.Id;
        uBM.TimeZoneSidKey = 'GMT';
        uBM.LanguageLocaleKey = 'en_US';
        uBM.EmailEncodingKey = 'UTF-8';
        insert uBM;
        
        User uITM = new user();
        uITM.LastName = 'Test ITM';
        uITM.Email = 'testITM@test.com';
        uITM.Alias = 'ITM';
        uITM.Username = 'test1234fdfdfefe4trfd34ITM@test.com';
        uITM.CommunityNickname = 'test122ITM';
        uITM.LocaleSidKey = 'en_US';
        uITM.ProfileId = profileId.Id;
        uITM.TimeZoneSidKey = 'GMT';
        uITM.LanguageLocaleKey = 'en_US';
        uITM.EmailEncodingKey = 'UTF-8';
        insert uITM;

        User uDL = new user();
        uDL.LastName = 'Test DL';
        uDL.Email = 'testDL@test.com';
        uDL.Alias = 'DL';
        uDL.Username = 'test1234fdfdfefe4trfd34DL@test.com';
        uDL.CommunityNickname = 'test122DL';
        uDL.LocaleSidKey = 'en_US';
        uDL.ProfileId = profileId.Id;
        uDL.TimeZoneSidKey = 'GMT';
        uDL.LanguageLocaleKey = 'en_US';
        uDL.EmailEncodingKey = 'UTF-8';
        insert uDL;
        
        User uITDL = new user();
        uITDL.LastName = 'Test ITDL';
        uITDL.Email = 'testITDL@test.com';
        uITDL.Alias = 'ITDL';
        uITDL.Username = 'test1234fdfdfefe4trfd34ITDL@test.com';
        uITDL.CommunityNickname = 'test122ITDL';
        uITDL.LocaleSidKey = 'en_US';
        uITDL.ProfileId = profileId.Id;
        uITDL.TimeZoneSidKey = 'GMT';
        uITDL.LanguageLocaleKey = 'en_US';
        uITDL.EmailEncodingKey = 'UTF-8';
        insert uITDL;
        
        DOUM_Terms_Conditions__c ter = new DOUM_Terms_Conditions__c();
        ter.DOUM_TCs_A_D__c = date.Today();
        ter.DOUM_TCsContent__c = 'New Terms of Conditions';
        ter.DOUM_TCs_Approval_Status__c = 'Approved';
        ter.DOUM_TCs_RD__c = NULL;
        insert ter;
        
        DOUM_Requester__c req = new DOUM_Requester__c();
        req.Name = 'Apex Tester Requester';
        req.DOUM_MoC__c = uBM.Id;
        insert req;
        
        DOUM_DOU__c DOU = new DOUM_DOU__c();
        DOU.DOUM_Requester__c = req.Id;
        DOU.DOUM_Domain__c = 'Activity';
        DOU.DOUM_DOUVersion__c = 1;
        DOU.DOUM_DOU_Approval_Status__c = 'In Approval';
        DOU.DOUM_Req_BMgr__c = uBM.Id;
        DOU.DOUM_Requester_IT_Mgr__c = uITM.Id;
        DOU.DOUM_Domain_Lead__c = uDL.Id;
        DOU.DOUM_IT_Domain_Lead__c = uITDL.Id;
        DOU.DOUM_BM_Approval__c = FALSE;
        DOU.DOUM_ITM_Approval__c = FALSE;
        DOU.DOUM_DL_Approval__c = FALSE;
        DOU.DOUM_ITDL_Approval__c = FALSE;
        DOU.DOUM_WAF__c = NULL;
        DOU.CreatedDate = System.now() - 10;
        DOU.LastModifiedDate = System.Now()- 5;
        insert DOU;
            
        DOUM_DOU__c DOU2 = new DOUM_DOU__c();
        DOU2.DOUM_Requester__c = req.Id;
        DOU2.DOUM_Domain__c = 'Activity';
        DOU2.DOUM_DOUVersion__c = 2;
        DOU2.DOUM_DOU_Approval_Status__c = 'In Approval';
        DOU2.DOUM_Req_BMgr__c = uBM.Id;
        DOU2.DOUM_Requester_IT_Mgr__c = uITM.Id;
        DOU2.DOUM_Domain_Lead__c = uDL.Id;
        DOU2.DOUM_IT_Domain_Lead__c = uITDL.Id;
        DOU2.DOUM_BM_Approval__c = FALSE;
        DOU2.DOUM_WAF__c = NULL;
        DOU2.DOUM_ITM_Approval__c = FALSE;
        DOU2.DOUM_DL_Approval__c = FALSE;
        DOU2.DOUM_ITDL_Approval__c = FALSE;
        insert DOU2;
        
		DOUM_DOU__c DOU3 = new DOUM_DOU__c();
        DOU3.DOUM_Requester__c = req.Id;
        DOU3.DOUM_Domain__c = 'Alignment';
        DOU3.DOUM_DOUVersion__c = 1;
        DOU3.DOUM_DOU_Approval_Status__c = 'In Approval';
        DOU3.DOUM_Req_BMgr__c = uBM.Id;
        DOU3.DOUM_Requester_IT_Mgr__c = uITM.Id;
        DOU3.DOUM_Domain_Lead__c = uDL.Id;
        DOU3.DOUM_IT_Domain_Lead__c = uITDL.Id;
        DOU3.DOUM_BM_Approval__c = TRUE;
        DOU3.DOUM_ITM_Approval__c = TRUE;
        DOU3.DOUM_DL_Approval__c = FALSE;
        DOU3.DOUM_ITDL_Approval__c = FALSE;
        DOU3.DOUM_WAF__c = NULL;
        DOU3.CreatedDate = System.now() - 10;
        DOU3.LastModifiedDate = System.Now()- 3;
        insert DOU3;

		DOUM_DOU__c DOU4 = new DOUM_DOU__c();
        DOU4.DOUM_Requester__c = req.Id;
        DOU4.DOUM_Domain__c = 'Customer';
        DOU4.DOUM_DOUVersion__c = 1;
        DOU4.DOUM_DOU_Approval_Status__c = 'In Draft';
        DOU4.DOUM_Req_BMgr__c = uBM.Id;
        DOU4.DOUM_Requester_IT_Mgr__c = uITM.Id;
        DOU4.DOUM_Domain_Lead__c = uDL.Id;
        DOU4.DOUM_IT_Domain_Lead__c = uITDL.Id;
        DOU4.DOUM_BM_Approval__c = TRUE;
        DOU4.DOUM_ITM_Approval__c = TRUE;
        DOU4.DOUM_DL_Approval__c = FALSE;
        DOU4.DOUM_ITDL_Approval__c = FALSE;
        DOU4.DOUM_WAF__c = NULL;
        DOU4.CreatedDate = System.now() - 10;
        DOU4.LastModifiedDate = System.Now()- 3;
        insert DOU4;
		
        system.runas(u){
                        
            Test.startTest();
            
            DOUM_WaitingOnApprovals.ListDOUs();
            
            system.debug('DOU'+DOU);
            system.debug('DOU2'+DOU2);
            system.debug('DOU3'+DOU3);
            system.debug('DOU4'+DOU4);
            
                                  
            system.debug('DOU'+DOU.DOUM_WAF__c);
            system.debug('DOU2'+DOU2.DOUM_WAF__c);
            system.debug('DOU3'+DOU3.DOUM_WAF__c);
            system.debug('DOU4'+DOU4.DOUM_WAF__c);
            
            
            system.assert(DOU.DOUM_WAF__c == NULL);
            system.assert(DOU2.DOUM_WAF__c == NULL);
            system.assert(DOU3.DOUM_WAF__c == uDL.Email);
            system.assert(DOU4.DOUM_WAF__c == NULL);
            
            Test.stopTest();
        }        

	}
}

 In the debug list the debug in the class for the email, waf, and "after update Waf" all have the correct value but in the test class the system.debug('DOU'+DOU.DOUM_WAF__c), system.debug('DOU2'+DOU2.DOUM_WAF__c), system.debug('DOU3'+DOU3.DOUM_WAF__c), system.debug('DOU4'+DOU4.DOUM_WAF__c) are all null. I cant seem to find why the values get set to null after the update works.
 
Hi Everyone,

I have an apex class that I have developed and tested that it works by calling it from a JavaScript button but now I want to schedule it to run daily to prevent someone having to press the button. My code is
 
global class DOUM_RetireDOUs implements Schedulable{

    global static boolean repeatedDOU(DOUM_DOU__c obj,List<DOUM_DOU__c> objects,String DOUName){ 
       
        for(DOUM_DOU__c rec: objects){
            if(obj.Id == rec.Id){
                continue;
            }
            else{
                if(DOUName == rec.DOUM_DOU_Name__c){
                    //if(obj.DOUM_DOUVersion__c > 1){
                        return true;                    
                    //}
                }
            }
        }
        return false;
    }
    
    
    
   webService static void checkUpdate(){
    
        List<DOUM_DOU__c> objects = [SELECT Id, Name, DOUM_DOUVersion__c, DOUM_Domain__c, DOUM_Requester__r.Name, DOUM_DOU_Approval_Status__c, DOUM_DOU_Name__c, DOUM_DofRetire__c, DOUM_RfR__c, DOUM_RetirePerson__c, DOUM_Retired__c FROM DOUM_DOU__c WHERE DOUM_DOU_Approval_Status__c ='Approved'];
        
        for(DOUM_DOU__c obj: objects){
        
    Integer Version = Integer.ValueOf(obj.DOUM_DOUVersion__c) + 1;
    String OldVersNo = String.ValueOf(Version);
    String Domain = obj.DOUM_Domain__c;
    String JoinDOU = '-DOU-';
    String Requester = obj.DOUM_Requester__r.Name;
    String JoinVers = ' V';
    String DOUName = Domain + JoinDOU + Requester + JoinVers + OldVersNo;
    
        system.debug(Domain);        
        system.debug(Version);
        system.debug(Requester);
        system.debug(OldVersNo);
            
        system.debug(DOUName);
        
        
        System.debug('if statatment'+repeatedDOU(obj,objects,DOUName));
            
        System.debug('obj dou name '+obj.DOUM_DOU_Name__c);
        System.debug('Dou name '+DOUName);
            
            if(repeatedDOU(obj,objects,DOUName)){
                  obj.DOUM_DofRetire__c = Date.today();
                  obj.DOUM_RfR__c = 'New Version Approved';
                  obj.DOUM_RetirePerson__c = String.ValueOf(obj.CreatedBy.Id); 
                  obj.DOUM_Retired__c = TRUE;
                  update obj;
            }
        }
    }
    
    global void execute(SchedulableContext sc) {
    
        DOUM_RetireDOUs CU = new DOUM_RetireDOUs();
        
        String DOU = '0 0 0 ? * MON-FRI';
        String jobID = System.schedule('RetireDOUs', DOU, CU);

        
   }
In the schedule apex I have set it to run Mon-Fri at prefered time of 00:00. In the list view of scheduled jobs my apex shows that it was submitted but never started. As well as this the code hasnt run and changed my data.

Any ideas?


 
Hi everyone ive asked this question alot and am yet to get a solution. I need to populate a lookup field with a record that matches some criteria. Attached is my code and entity model etc
trigger setTermsConditions on DOUM_DOU__c (before insert, before update) {

Map<Id,Id> cases = new Map<Id,Id>(); 
 
    List<DOUM_Terms_Conditions__c> listGL = new List<DOUM_Terms_Conditions__c>(); 

try{     

listGL = [Select DOUM_TermsConditions.Name, DOUM_Terms_Conds__c from DOUM_DOU__c where Id In: trigger.newMap.keySet() AND DOUM_Terms_Conditions__c.DOUM_TCs_RD__c = NULL]; 

}catch(exception e){ 

 system.debug(e.getmessage()); 

} 

if(listGL !=null && ! listGL.isempty()){  

    for(DOUM_DOU__c objGL: listGL) 
 
    { 

        cases.put(objGL.id,objGL.DOUM_TermsConditions__r.Name); 
        
    } 

} 

    for (DOUM_DOU__c a : Trigger.new) 

    { 
    
        if(a.DOUM_Terms_Conds__c != nul && cases.containskey(a.DOUM_Terms_Conds__c)) 

        { 
            a.DOUM_Terms_Conds__c = cases.get(a.DOUM_Terms_Conds__c); 

        } 
    } 

} 


}
My code doesnt save because i get this error
 
Error: Compile Error: Didn't understand relationship 'DOUM_TermsConditions' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 9 column 10


User-added image
Hi

I have the Apex code and have no idea about Apex code or triggers so I can't solve any issues that appear. I get this error when creating a new record.

Apex trigger DOUM_SetTermsConditions caused an unexpected exception, contact your administrator: DOUM_SetTermsConditions: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.DOUM_SetTermsConditions: line 4, column 1

Any ideas as to how I can fix it?
trigger DOUM_SetTermsConditions on DOUM_Version__c (before insert, before update) {
Map<Id,Id> cases = new Map<Id,Id>();
    List<DOUM_Version__c> listGL = new List<DOUM_Version__c>();
    listGL = [Select DOUM_Terms_Conditions__r.Name, DOUM_Terms_Conditions__c from DOUM_Version__c where Id In: trigger.newMap.keySet() AND DOUM_Terms_Conditions__c <> null];
    for(DOUM_Version__c objGL: listGL)
    {
        cases.put(objGL.id,objGL.DOUM_Terms_Conditions__r.Name);
    }
    for (DOUM_Version__c a : Trigger.new)
    {
        if(a.DOUM_Terms_Conditions__c != null)
        {
            a.DOUM_Terms_Conditions__c = cases.get(a.DOUM_Terms_Conditions__c);
        }
    }
}

 
Hi

So im hoping this is possible as it's an excellent "nice to have". At the moment I have an approval process I can reply to and approve/reject with comments. I can also have a mailto link to pre populate the body with approve/reject with comments. Is it possible to merge the two so the user can click the link in the email and have the reply to email address populated. Problem at the moment is that I can reply and have to type approve or reject (user error possible) or have the text pre entered but no email address to send it to. Ive dug down on the raw html of the email and found the reply to email address which looks like a scrambled value. Is there a merge field or something similar that can be called upon in this mailto function?  Your help will be recieve gratefully and with much joy (if it's possible :D)
Hi

I have a field where the lookup filter always delivers one record. Is it possible to build a trigger that populates this in the back end and prevents the user having to have to click on this. If so how would it look?

My Parent object is called "terms and conditions" and has fields for ID, Content, Retirement date and Active date. the filter on the lookup at the minute it shows the record that has no retirement date and the active date is after the current date.

The child object has a lookup field on that calles DOUM_TCs. 

Any help as I have never heard of apex or triggers before starting this development. Cheers
Hi I have the code that worked when the day was bigger than the 10th of a month but when I do it when the date is say the 5th etc it fails because the code doesn't return DD and just returns D (i think this is the problem) I'm guessing the same will happen in January with the month too

{!REQUIRESCRIPT("/soap/ajax/37.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/37.0/apex.js")}
 
var acc = new sforce.SObject("DOUVersion__c"); 

NULL = " ";

acc.Id = "{!DOUVersion__c.Id}";
acc.RetiredHidden__c = NULL;                  
acc.Retired__c = "true";               
acc.Date_of_Retirement__c = "{!YEAR(TODAY())}-{!MONTH(TODAY())}-{!DAY(TODAY())}"; 

         
result = sforce.connection.update([acc]); 
window.location.reload();

your help would be appreciated
Hi

I have a field where the lookup filter always delivers one record. Is it possible to build a trigger that populates this in the back end and prevents the user having to have to click on this. If so how would it look?

My Parent object is called "terms and conditions" and has fields for ID, Content, Retirement date and Active date. the filter on the lookup at the minute it shows the record that has no retirement date and the active date is after the current date.

The child object has a lookup field on that calles DOUM_TCs. 

Any help as I have never heard of apex or triggers before starting this development. Cheers
Hi everyone ive asked this question alot and am yet to get a solution. I need to populate a lookup field with a record that matches some criteria. Attached is my code and entity model etc
trigger setTermsConditions on DOUM_DOU__c (before insert, before update) {

Map<Id,Id> cases = new Map<Id,Id>(); 
 
    List<DOUM_Terms_Conditions__c> listGL = new List<DOUM_Terms_Conditions__c>(); 

try{     

listGL = [Select DOUM_TermsConditions.Name, DOUM_Terms_Conds__c from DOUM_DOU__c where Id In: trigger.newMap.keySet() AND DOUM_Terms_Conditions__c.DOUM_TCs_RD__c = NULL]; 

}catch(exception e){ 

 system.debug(e.getmessage()); 

} 

if(listGL !=null && ! listGL.isempty()){  

    for(DOUM_DOU__c objGL: listGL) 
 
    { 

        cases.put(objGL.id,objGL.DOUM_TermsConditions__r.Name); 
        
    } 

} 

    for (DOUM_DOU__c a : Trigger.new) 

    { 
    
        if(a.DOUM_Terms_Conds__c != nul && cases.containskey(a.DOUM_Terms_Conds__c)) 

        { 
            a.DOUM_Terms_Conds__c = cases.get(a.DOUM_Terms_Conds__c); 

        } 
    } 

} 


}
My code doesnt save because i get this error
 
Error: Compile Error: Didn't understand relationship 'DOUM_TermsConditions' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 9 column 10


User-added image
Hi

I have the Apex code and have no idea about Apex code or triggers so I can't solve any issues that appear. I get this error when creating a new record.

Apex trigger DOUM_SetTermsConditions caused an unexpected exception, contact your administrator: DOUM_SetTermsConditions: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.DOUM_SetTermsConditions: line 4, column 1

Any ideas as to how I can fix it?
trigger DOUM_SetTermsConditions on DOUM_Version__c (before insert, before update) {
Map<Id,Id> cases = new Map<Id,Id>();
    List<DOUM_Version__c> listGL = new List<DOUM_Version__c>();
    listGL = [Select DOUM_Terms_Conditions__r.Name, DOUM_Terms_Conditions__c from DOUM_Version__c where Id In: trigger.newMap.keySet() AND DOUM_Terms_Conditions__c <> null];
    for(DOUM_Version__c objGL: listGL)
    {
        cases.put(objGL.id,objGL.DOUM_Terms_Conditions__r.Name);
    }
    for (DOUM_Version__c a : Trigger.new)
    {
        if(a.DOUM_Terms_Conditions__c != null)
        {
            a.DOUM_Terms_Conditions__c = cases.get(a.DOUM_Terms_Conditions__c);
        }
    }
}

 
Hi

I have a field where the lookup filter always delivers one record. Is it possible to build a trigger that populates this in the back end and prevents the user having to have to click on this. If so how would it look?

My Parent object is called "terms and conditions" and has fields for ID, Content, Retirement date and Active date. the filter on the lookup at the minute it shows the record that has no retirement date and the active date is after the current date.

The child object has a lookup field on that calles DOUM_TCs. 

Any help as I have never heard of apex or triggers before starting this development. Cheers
Hi I have the code that worked when the day was bigger than the 10th of a month but when I do it when the date is say the 5th etc it fails because the code doesn't return DD and just returns D (i think this is the problem) I'm guessing the same will happen in January with the month too

{!REQUIRESCRIPT("/soap/ajax/37.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/37.0/apex.js")}
 
var acc = new sforce.SObject("DOUVersion__c"); 

NULL = " ";

acc.Id = "{!DOUVersion__c.Id}";
acc.RetiredHidden__c = NULL;                  
acc.Retired__c = "true";               
acc.Date_of_Retirement__c = "{!YEAR(TODAY())}-{!MONTH(TODAY())}-{!DAY(TODAY())}"; 

         
result = sforce.connection.update([acc]); 
window.location.reload();

your help would be appreciated