• jhartfield
  • NEWBIE
  • 25 Points
  • Member since 2009

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 14
    Replies

I had a need to sort several small lists of SelectOptions (<100 items) and wrote this basic quicksort to do it.  I decided to share it in case anyone else finds it useful.

 

Be advised this will probably only work for smaller lists because the call stack may get large, in which case you will want to use one of the more complex versions of quicksort which are posted around the forums. 

 

// This is a simple quicksort algorithm to sort a SelectOption list (dropdown)
// by label alphabetically.
public static List<SelectOption> SortOptionList(List<SelectOption> ListToSort)
{
if(ListToSort == null || ListToSort.size() <= 1)
return ListToSort;

List<SelectOption> Less = new List<SelectOption>();
List<SelectOption> Greater = new List<SelectOption>();
integer pivot = 0;

// save the pivot and remove it from the list
SelectOption pivotValue = ListToSort[pivot];
ListToSort.remove(pivot);

for(SelectOption x : ListToSort)
{
if(x.getLabel() <= pivotValue.getLabel())
Less.add(x);
else if(x.getLabel() > ListToSort[pivot].getLabel()) Greater.add(x);
}
List<SelectOption> returnList = new List<SelectOption> ();
returnList.addAll(SortOptionList(Less));
returnList.add(pivotValue);
returnList.addAll(SortOptionList(Greater));
return returnList;
}

 

 

 

 

Message Edited by jhartfield on 03-15-2010 11:17 AM

 Hello,

 

I have a process that automatically builds a scheduled job a few minutes in the future every time it fires.  This works great, but after there are ten such jobs, I get an Apex limit exception: You have exceeded the maximum number (10) of Apex scheduled jobs.

 

These jobs are all completed and I did check to make sure they have a status of 'COMPLETED' as well.  When I delete them by going in through the UI, then the process works again.

 

1. Is this intended behavior? 

 

2. Is there any way to programatically delete these old completed jobs?

Message Edited by jhartfield on 02-12-2010 02:35 PM
Message Edited by jhartfield on 02-12-2010 02:35 PM

Is there any way to change or delete a Scheduled Job ?  I am able to create one easily enough, but once it is made I can only look at the values in the CronTrigger object, but not update them.  Also, it seems I cannot delete them.  I also looked at the System.AbortJob method, but that seems to only stop a job that is already running - I get an error if I try it on a Queued job.

 

The reason I am doing this is to try to create a 'sliding' job.  So, when a trigger is fired the job will run in 5 minutes.  But if the trigger is fired again before that 5 minutes is up, it will find the old job and either delete it and make a new one for 5 minutes out, or update the old one so the next scheduled time is in 5 minutes.

 

Any ideas are welcome!

 

Jason

 

 

I randomly was trying a split today on a '*' field and got the following error:

 

System.StringException: Invalid regex: Dangling meta character '*' near index 0 * ^

 

Out of curiosity, I tried to split on '+' and got the same error.  

 

This is easily reproducible for me by running the following code in the execute anonymous window - can anyone else  confirm?

string sString = 'someStuff'; string[] splitted = sString.split('*');

 

 

Just wanted to share this as it caused us a lot of headaches.

 

We have a batch jobs set up that has the following QueryLocator definition:

 

global Database.QueryLocator start(Database.batchableContext bc)
{

string sQuery = 'SELECT ID,Name,CustomField__c, CustomField2__c FROM MyCustomObj__c';

return Database.getQueryLocator(sQuery);

}

 

This began failing immediately on us without sending any notification emails about the failures once we added a namespace.  Having no debugging info, this took us a long time to sort out.

 

In the end, we needed to add our new namespace to each field we were querying, like the following:

 

 

global Database.QueryLocator start(Database.batchableContext bc)
{

string sQuery = 'SELECT ID,Name,MyNamespace__CustomField__c, MyNamespace__CustomField2__c FROM MyNamespace__MyCustomObj__c';

return Database.getQueryLocator(sQuery);

}

 

And then it worked!

 

Message Edited by jhartfield on 02-05-2010 08:30 AM

What user context is used to do run apex code/dml operations when a record is inserted or updated using salesforce to salesforce?  Is there a way to set this user?

In the past three days I intermittently receive an error that says "Bad developer mac" when I try to perform various functions through the Eclipse IDE such as run tests or save a file.

 

Has anyone else had this issue and/or know what it means?

When I try to run all the unit tests via the 'Run All Tests' button found in Develop->Apex Classes, I have started getting the following message:

 

Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 150.625K

 

We have a pretty large ORG set up, so I'm sure it's because the system log has simply gotten too huge.  When we run all the unit tests by using the Eclipse IDE, the tests complete just fine, except we don't get a snapshot of the overall code coverage.  We just get code coverage on a class by class basis.

 

We want to be able to see where our overall code coverage is at.  Is there any other way to do this other than through the web interface?  Or, is there any way to make the unit tests less verbose through the web interface to reduce the size of the view state?

I randomly was trying a split today on a '*' field and got the following error:

 

System.StringException: Invalid regex: Dangling meta character '*' near index 0 * ^

 

Out of curiosity, I tried to split on '+' and got the same error.  

 

This is easily reproducible for me by running the following code in the execute anonymous window - can anyone else  confirm?

string sString = 'someStuff'; string[] splitted = sString.split('*');

 

 

I was trying to update the code of our managed package. The Force IDE worked as usual, but after a refresh there were no changes on the code.

I tried to edit the Visualforce directly within the org and edited it by hand. After Saving without any errors I refreshed the code and there were also no changes!

 

Does anyone else have these problems since the rollback of the Spring 10 release?

 

Is there any tipp on how to save anyway?

 

I opened a case in the partner portal, but there are 4 Bugs with status new since the last 3 weeks without any reaction?!

Current documents has no example on how to schedule apex jobs every 10 mins. I tried with unix cron job syntax style (like 0,10,20,30,40,50 slots), that doesn't work.

 

Any help would be appreciated.

 

Thanks

  • February 17, 2010
  • Like
  • 0

 So what is the different? To illustrate my point, here are both way returning a similar set.

 

 #1

Set<String> nameSet = new Set<String>(); List<Account> acct = [SELECT Name FROM Account]; for(Account a_insert: acct){ nameSet.add(a_insert.Name); }

 

#2

Set<String> nameSet = new Set<String>(); for(Account acct : [SELECT Name FROM Account]){ nameSet.add(Name); }

 

Would I hit a limit earlier with #2 since I am storing the results in the sObject instead a list?




 

 

I randomly was trying a split today on a '*' field and got the following error:

 

System.StringException: Invalid regex: Dangling meta character '*' near index 0 * ^

 

Out of curiosity, I tried to split on '+' and got the same error.  

 

This is easily reproducible for me by running the following code in the execute anonymous window - can anyone else  confirm?

string sString = 'someStuff'; string[] splitted = sString.split('*');

 

 

Group and Professional Editions support Apex only in certified managed packages. If a certified managed package is installed into an org that doesn't otherwise support Apex, if that package contains an Apex class that implements the Schedulable interface, will we be able to schedule that class using the new scheduler?

  • February 08, 2010
  • Like
  • 0

I'm developing a VF page with a custom controller. I should be able to click the System Log link at the top of the page, see the System Log window appear, go back to my VF page, reload it, and then see a new Log appear in the System Log window, right?

 

The problem is that I don't see a new Log appear in the System Log window.

 

I've tried setting the Filter Settings to the lowest level possible (e.g., Finest), to no avail.  I've tried with the default Filter Settings. Nothing shows up in the "Logs recorded since..." list.

 

If I enter some Apex into the Execute Apex area and execute it, a log does show up in the list. But there doesn't seem to be anything I can do in my VF page that causes a log to be captured.

 

The only way I can get my VF page to display anything in the System Log window is if I turn on System / Monitoring / Debug Logs. But that's only good for 20 logs -- after that, I have to go back to System / Monitoring / Debug Logs and turn it back on again.  It's really unwieldy to have to do that when I'm trying to debug a VF page.

 

Before the new System Log feature, I could monitor what my VF page/controller was doing by just watching the System Log window. Now I have to repeatedly turn on Debug Logs -- is that really true? If so, is there any plan to correct that?

Message Edited by JeriMorris on 01-29-2010 12:48 PM

Hi All:  We have a managed app published on the AppExchange, and have recently created a new version where the only change made is that our Custom Tab uses the FULL WIDTH of the framed page versus the 2 column layout and the framed page length has been changed to 1300 pixels from 600.  We also changed the color of the tab.

 

I have confirmed these changes are inside the new package version we uploaded, and when I install the upgrade I see a notice that the Custom tab is the single component which will get upgraded....BUT...

 

PROBLEM:  Any SF instance which upgrades to our new version does NOT get the full width page, but instead gets the 2 column layout.   Interestingly, they do get the change to 1300 pixel page length from 600, but the change in the full width versus 2 column layout does NOT occur.  They also do not get the tab color change.

 

I'm going crazy with this!  Why can't we upgrade existing installs to switch from a 2 column layout to a full width layout??  Anyone have any insights?

 

Thanks in advance for any help!

 

Mark Cira @ PrintSf.com 

Message Edited by markcira on 01-04-2010 10:35 AM

Hi,

 

I have created some batch apex code alongwith other triggers and class/controller codes. 

 

When I run individual test methods on them, I am able to get test success result alongwith nice code coverage %. However when I run all tests together, I get following test failure errors:-

 

1)System.AsyncException: Database.executeBatch cannot be called from a batch or future method.

2)System.AsyncException: Future method cannot be called from a future method: changeOwners(String, String)

3)System.AsyncException: Future method cannot be called from a future method: getLead_Rollup_Amount(Id)

4)System.AsyncException: Future method cannot be called from a future method: changeOwners(String, String)

 

Please note again that the exceptions dont come when tested individually.

 

Please advise on same.

 

 

Thanks,

 

Vimal 

When I try to run all the unit tests via the 'Run All Tests' button found in Develop->Apex Classes, I have started getting the following message:

 

Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 150.625K

 

We have a pretty large ORG set up, so I'm sure it's because the system log has simply gotten too huge.  When we run all the unit tests by using the Eclipse IDE, the tests complete just fine, except we don't get a snapshot of the overall code coverage.  We just get code coverage on a class by class basis.

 

We want to be able to see where our overall code coverage is at.  Is there any other way to do this other than through the web interface?  Or, is there any way to make the unit tests less verbose through the web interface to reduce the size of the view state?