• Heather Mickey
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 13
    Replies
There is a field that currently stores Office Times in the following format, based on the input from a Custom S-Control.
Field Name: Office Times
Data Stored (example): &m=60,1320&tu=105,1370&w=73,1343&th=75,1365&f=150,1260&sa=480,1020

I'd like to create a new field which takes this data stored and makes it more user reading friendly.
M: 01:00-22:00
Tu: 01:45-22:50
W: 01:13-22:23
Th: 01:15-22:45
F: 02:30-21:00
Sa: 08:00-17:00
**The number stored in the long text field from the custom s-control is in minutes. So it needs to get converted into military (24h) time.

I'm having a difficult time figuring out how to do this as I am still very new to Apex. I tried addressing this via a workflow and formulas but I haven't had any luck.

*There is one other tricky part to this. Someone could enter "&tu=360,615;780,1020", meaning
Tu: 06:00-10:15, 13:00-17:00

Thank you so much,
Heather
There is a field that currently stores Office Times in the following format, based on the input from a Custom S-Control.
Field Name: Office Times
Data Stored (example): &m=60,1320&tu=105,1370&w=73,1343&th=75,1365&f=150,1260&sa=480,1020

I'd like to create a new field which takes this data stored and makes it more user reading friendly.
M: 01:00-22:00
Tu: 01:45-22:50
W: 01:13-22:23
Th: 01:15-22:45
F: 02:30-21:00
Sa: 08:00-17:00

I'm having a difficult time figuring out how to do this as a formula. Any ideas? If not possible with a formula, what should I be doing?

*There is one other tricky part to this. Someone could enter "&tu=360,615;780,1020", meaning
Tu: 06:00-10:15, 13:00-17:00

Thank you so much,
Heather
I'm new to APEX so any help troubleshooting errors to letting me know where I went wrong with my code is greatly appreciated. Currently I am getting an error on the global string query line (2). Error: expecting a semi-colon, found 'Open'

Account is a standard object and Program is a custom object with a lookup relationship of Program to Account, so I need to write APEX to set a field on Account with a value from Program. There are many Programs related to an Account.
I'd like to have a field on the Account to reflect "Next Project Date" when the Project has a Status = "Open" and Date is >= to Today
Example:
**Pretend TODAY is 2015/05/26
Account a
Program 1 for Account a with Date=2015/05/24 and Status=closed
Program 2 for Account a with Date=2015/05/25 and Status=open
Program 3 for Account a with Date=2015/05/26 and Status=open
Program 4 for Account a with Date=2015/05/27 and Status=open
--The Next Program Date on a should be set to 2015/05/26

Account b
Program 5 for Account b with Date=2015/05/24 and Status=closed
Program 6 for Account b with Date=2015/05/25 and Status=open
Program 7 for Account b with Date=2015/05/27 and Status=open
Program 8 for Account b with Date=2015/05/28 and Status=open
--The Next Program Date on b should be set to 2015/05/27

Below is the current code that I have compiled:
global class Acc_SetNextProgramDateBatch implements Database.Batchable<sObject>, Database.Stateful{
	global String query = 'SELECT Id,Acc_Next_Program_Date__c,(SELECT Id,AccountId__c,Program_Date__c FROM Program__r WHERE Status__c='Open' AND Program_Date__c >= TODAY ORDER BY Program_Date__c ASC LIMIT 1) FROM Account';

	//This list contains the IDs of Accounts, which produced failures
    global List<Id> accsIDsFailed= new List<Id>();   
     
    //This method implements the interface method start.
    global Database.QueryLocator start(Database.BatchableContext BC){       
        return Database.getQueryLocator(query);
    }
  
    //This method implements the interface method execute.
    global void execute(Database.BatchableContext BC, List<Account> scope){
        //Step through all account records
        for(Account acc : scope){
        	Date NextProgramDate; 
            //Assign the Next Program Date to the Account
            if(acc.Program__r != null) {
                for(Program__c ca : acc.Program__r){
                    if(ca.Program_Date__c != null) {
                    	NextProgramDate = ca.Program_Date__c;
                    }
                }
                acc.Acc_Next_Program_Date__c = NextProgramDate;
            }        
       }
        
       Integer i = 0;
       List<Database.SaveResult> updateResults = Database.update(scope, false);
       for (Database.SaveResult res : updateResults) {
           if (! res.isSuccess()) {
               // send Email for not updated accounts
               accsIDsWithFailure.add(scope[i].Id);
           }
           i++;
       }        
       
    }  
    
    //This method implements the interface method finish.
    global void finish(Database.BatchableContext BC) { }
}
I have also tried another way of writing this, but was unsuccessful because I was getting a different error and didn't know how to handle the error since it was my first time looping in a list. The script would run, but I would get a Failed error of: System.ListException: List index out of bounds: 0

This was the code I had previous tried:
global class Acc_SetNextProgramDateBatch implements Database.Batchable<sObject>, Database.Stateful{
	global String query = 'SELECT Id,Acc_Next_Program_Date__c FROM Account';

    //This method implements the interface method start.
    global Database.QueryLocator start(Database.BatchableContext BC){       
        return Database.getQueryLocator(query);
    }
  
    //This method implements the interface method execute.
    global void execute(Database.BatchableContext BC, List<Account> scope){
        Set<Id> accountIdSet=new Set<Id>();
        for(Account acc : scope){
            accountIdSet.add(acc.Id);        
        }
        
       List<Account> accListToUpdate=new List<Account>();
       for(Account ac :[SELECT Id,Acc_Next_Program_Date__c,
                        (SELECT Id,AccountId__c, Program_Date__c 
                         FROM Program__r 
                         WHERE Status__c='Open' AND Program_Date__c >= TODAY 
                         ORDER BY Program_Date__c 
                         ASC LIMIT 1)
                        FROM Account 
                        WHERE Id IN: accountIdSet]){
			ac.Acc_Next_Program_Date__c=ac.Program__r[0].Program_Date_vod__c;  
         	accListToUpdate.add(ac);
       }
        
       try{
         update accListToUpdate;
       }catch(DmlException de){
         System.debug(de);
       }
        
    }  
    
    //This method implements the interface method finish.
    global void finish(Database.BatchableContext BC) { }
}

Any advice and guidance is greatly appreciated. I've been working on this for over a week without any avail.

Thank you,

Heather

 

Hi,

I am very (read very) new to apex and am trying to create a trigger.

Object A:
id
date
hours
ownerid

Object B:
id
date
modify date
ownerid

Trigger to occur on Object B upon create, update, delete:

The Object B: ownerid wants to create, update or delete a record on Object B for date >= today() or modify_date >= today()

In order to allow the create, update, delete of record on Object B, the same ownerid of Object A must have a sum of X hours for date = last_week on Object A

If sum is < X hours, then create an error message that states X hours are not complete and do not allow create, update, delete of record on Object B.

How would I go about scripting this?

Thank you so, so much for helping my pursuit to learn apex! I truly appreciate it.
I'm trying to get the background color of my text template in a visual flow to be white. However, whenever I use standard HTML syntax it doesn't reflect on the output. 

I've tried putting it in a header
<h2 style="background-color:white">
Background-color set by using red
</h2>

I've tried putting the text inside a table and setting the color of the background of the table. 

Is this a limitation of text templates in visual flows? Or am I missing something obvious? 
I'm new to APEX so any help troubleshooting errors to letting me know where I went wrong with my code is greatly appreciated. Currently I am getting an error on the global string query line (2). Error: expecting a semi-colon, found 'Open'

Account is a standard object and Program is a custom object with a lookup relationship of Program to Account, so I need to write APEX to set a field on Account with a value from Program. There are many Programs related to an Account.
I'd like to have a field on the Account to reflect "Next Project Date" when the Project has a Status = "Open" and Date is >= to Today
Example:
**Pretend TODAY is 2015/05/26
Account a
Program 1 for Account a with Date=2015/05/24 and Status=closed
Program 2 for Account a with Date=2015/05/25 and Status=open
Program 3 for Account a with Date=2015/05/26 and Status=open
Program 4 for Account a with Date=2015/05/27 and Status=open
--The Next Program Date on a should be set to 2015/05/26

Account b
Program 5 for Account b with Date=2015/05/24 and Status=closed
Program 6 for Account b with Date=2015/05/25 and Status=open
Program 7 for Account b with Date=2015/05/27 and Status=open
Program 8 for Account b with Date=2015/05/28 and Status=open
--The Next Program Date on b should be set to 2015/05/27

Below is the current code that I have compiled:
global class Acc_SetNextProgramDateBatch implements Database.Batchable<sObject>, Database.Stateful{
	global String query = 'SELECT Id,Acc_Next_Program_Date__c,(SELECT Id,AccountId__c,Program_Date__c FROM Program__r WHERE Status__c='Open' AND Program_Date__c >= TODAY ORDER BY Program_Date__c ASC LIMIT 1) FROM Account';

	//This list contains the IDs of Accounts, which produced failures
    global List<Id> accsIDsFailed= new List<Id>();   
     
    //This method implements the interface method start.
    global Database.QueryLocator start(Database.BatchableContext BC){       
        return Database.getQueryLocator(query);
    }
  
    //This method implements the interface method execute.
    global void execute(Database.BatchableContext BC, List<Account> scope){
        //Step through all account records
        for(Account acc : scope){
        	Date NextProgramDate; 
            //Assign the Next Program Date to the Account
            if(acc.Program__r != null) {
                for(Program__c ca : acc.Program__r){
                    if(ca.Program_Date__c != null) {
                    	NextProgramDate = ca.Program_Date__c;
                    }
                }
                acc.Acc_Next_Program_Date__c = NextProgramDate;
            }        
       }
        
       Integer i = 0;
       List<Database.SaveResult> updateResults = Database.update(scope, false);
       for (Database.SaveResult res : updateResults) {
           if (! res.isSuccess()) {
               // send Email for not updated accounts
               accsIDsWithFailure.add(scope[i].Id);
           }
           i++;
       }        
       
    }  
    
    //This method implements the interface method finish.
    global void finish(Database.BatchableContext BC) { }
}
I have also tried another way of writing this, but was unsuccessful because I was getting a different error and didn't know how to handle the error since it was my first time looping in a list. The script would run, but I would get a Failed error of: System.ListException: List index out of bounds: 0

This was the code I had previous tried:
global class Acc_SetNextProgramDateBatch implements Database.Batchable<sObject>, Database.Stateful{
	global String query = 'SELECT Id,Acc_Next_Program_Date__c FROM Account';

    //This method implements the interface method start.
    global Database.QueryLocator start(Database.BatchableContext BC){       
        return Database.getQueryLocator(query);
    }
  
    //This method implements the interface method execute.
    global void execute(Database.BatchableContext BC, List<Account> scope){
        Set<Id> accountIdSet=new Set<Id>();
        for(Account acc : scope){
            accountIdSet.add(acc.Id);        
        }
        
       List<Account> accListToUpdate=new List<Account>();
       for(Account ac :[SELECT Id,Acc_Next_Program_Date__c,
                        (SELECT Id,AccountId__c, Program_Date__c 
                         FROM Program__r 
                         WHERE Status__c='Open' AND Program_Date__c >= TODAY 
                         ORDER BY Program_Date__c 
                         ASC LIMIT 1)
                        FROM Account 
                        WHERE Id IN: accountIdSet]){
			ac.Acc_Next_Program_Date__c=ac.Program__r[0].Program_Date_vod__c;  
         	accListToUpdate.add(ac);
       }
        
       try{
         update accListToUpdate;
       }catch(DmlException de){
         System.debug(de);
       }
        
    }  
    
    //This method implements the interface method finish.
    global void finish(Database.BatchableContext BC) { }
}

Any advice and guidance is greatly appreciated. I've been working on this for over a week without any avail.

Thank you,

Heather

 

Hi,

I am very (read very) new to apex and am trying to create a trigger.

Object A:
id
date
hours
ownerid

Object B:
id
date
modify date
ownerid

Trigger to occur on Object B upon create, update, delete:

The Object B: ownerid wants to create, update or delete a record on Object B for date >= today() or modify_date >= today()

In order to allow the create, update, delete of record on Object B, the same ownerid of Object A must have a sum of X hours for date = last_week on Object A

If sum is < X hours, then create an error message that states X hours are not complete and do not allow create, update, delete of record on Object B.

How would I go about scripting this?

Thank you so, so much for helping my pursuit to learn apex! I truly appreciate it.