3

First question to the Salesforce StackExchange; I apologize in advance for not adhering to any community rules.

I'm trying to execute an Apex method through the anonymous execution via Developer Console. Part of the overall process involves kicking off a Process Builder process. I know that the Process Builder doesn't support bulk operations so I was purposely trying to de-bulkify the method. The method is supposed to loop through a list of Ids and mimic going to a Visualforce page and clicking a button. My code is thus:

public class ManualScorecardSend {

public void sendScorecard() {

    Rare_Campaign__c [] cResults = [SELECT Id FROM Campaign__c where Status__c = 'Active' 
                                    AND Program__r.Name IN ('SomeProgram')];

    For (Campaign__c c: cResults) {
        SetupNewScoreCardExtension setupnsc = new SetupNewScoreCardExtension(new ApexPages.StandardController(c));
        setupnsc.SendScorecard();
    }

}
}

ManualScorecardSend mss = new ManualScorecardSend();
mss.sendScorecard();

Every time I execute this code I get the 'too many SOQL' queries error from Process Builder. But if I go to the V-force page for each Id and kick off the process manually, it works fine.

For further information, the total number of Ids that result from my SOQL query is like 30. Not talking about a lot of records here. I just wanted to write up something quick to execute these processes so I wouldn't have to go to 30 different V-force pages and do them manually until the scheduling part of the project was set up.

Please let me know if you have any questions or need more information.

  • 1
    The Process Builder is still moving towards bulkification. However, IMO you should write your code to be as bulk safe as possible, they are improving it as quickly as they can. – Adrian Larson Jun 29 '15 at 17:12
  • I totally agree. This is a temporary solution that I need to run just this one time. But since bulk support isn't currently available and I'm not dealing with a ton of DML operations, I felt this was temporarily OK in lieu of pushing a button 30 times. – justinpdove Jun 29 '15 at 17:48
  • 1
    I just think you're concept of "supported" is off base. It's not like 'Process Builder` "doesn't support bulk operations," but as you add cross-object logic it will consume limits more quickly than a well designed Apex Trigger. Some Apex Triggers are not so well designed and will perform worse. It's not a dichotomy between "supported" and "unsupported," but rather a scale where Process Builder sits somewhere in the middle. – Adrian Larson Jun 29 '15 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.