• jen.nelsonDEV@configero.com
  • NEWBIE
  • 10 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies

This is my first week working with Salesforce, coming from a Coldfusion (don't be a hater!) and SQL Server background. 

 

Our users want to be able to see the number of Contacts for an account at a glance. To accommodate this, we've developed a custom field -- Account.Contact_Count__c which is an integer. Now for the hard part; populating it. We can't do a rollup because you can't roll up child data. So I wrote this bulk updater to do the work. I scheduled it (successfully) in the hopes that would get around the data governance limits, but no such luck.

 

We have thousands of accounts, and I won't know if they require updating unless I run a query on them. Is there a good way to run this in a background at low demand times? Is there a way that I can run it in blocks of data? Is there some super-duper easy way of running this that I simply didn't know about? Can I have this class call another class in order to reset the count of transactions?  Also, please note that as far as I can tell you can't combine count() with sub queries. I tried to make variations on this query work a number of different ways:

 

Select a.Contact_Count__C, count(Select ID From Contact Where AccountID = a.ID)

From Account a

 

I never got it to work. 

 

I'm currently orders of magnitude away from being able to execute this code. Help me understand that right way to accomplish a task like this in salesforce!

 

 I've run this both on-demand (so I can see errors) and scheduled. 

global class ModifyContractCount {

//completeRecount updates all records with the latest count of contacts

//the @future makes this available to be scheduled

@future(callout=true)

public static void completeRecount()

{ //Identify the number of contacts for a particular account and update the Contact Count variable appropriately //Create list of records to update.

List<Account> AcctsToUpdate = [ SELECT A.ID, A.Contact_Count__c FROM Account A LIMIT 50 //NOTE: Works with 50 or fewer ];

//Loop through returned records

for(Account a : AcctsToUpdate)

{

//Identify number of child contacts

Integer NumberOfContacts =

[ SELECT count()FROM Contact WHERE AccountID = :a.Id

];

//If the Accounts.Contact_Count__c is not the same as the number of child contacts, update the record

if (NumberOfContacts != a.Contact_Count__c)

{

a.Contact_Count__c = NumberOfContacts; update a; } //end for loop } //end completeRecount method }

];

//If the Accounts.Contact_Count__c is not the same as the number of child contacts, update the record

if (NumberOfContacts != a.Contact_Count__c)

{a.Contact_Count__c = NumberOfContacts;

update a;}

//end for loop

}

//end completeRecount method }

 

 

Message Edited by BrendaFlynn on 03-05-2010 10:24 AM
Welcome to the Force.com Labs discussion board -- I'm glad you're here.  This is an experiment in connecting Force.com Labs users with Force.com Labs authors.  Have a question about an app?  A feature request?  An app request?  Just want to talk about your favorite or least favorite?  You're in the right place.
  • March 02, 2010
  • Like
  • 0
I was working on uploading some APEX code in our production environment, using the APEX Deployment Tool add-on for Apache Ant.  I downloaded the most recent version of this tool this morning, as I understand there were some issues with it over the last day or so.

Before I uploaded the code, I had wanted to delete a class created the other day, which had no triggers depending upon it.  However, I received the following error message when I attempted to do so.

BUILD FAILED
C:\Documents and Settings\RoarkM\Desktop\Apache Ant Files\build.xml:16: Failed:
Failed to delete class compileAndTest: Cannot complete this operation. Cannot delete classes/triggers in production.  Use compileAndTest verb to delete. : null

I have included the 'build.xml' file for this build below for anyone who would like to review it.

After realizing that I could not delete this class, I looked to find if there was a way of deactivating APEX triggers or classes in our production environment, as might be necessary if code were to become depreciated.  I could find no documented way through the UI or through the APEX Deployment Tools add-on to do this.

Are there plans to add this functionality, or an undocumented way to deactivate classes?  Has anyone else encountered issues deleting APEX code in production?  Did I misconfigure one of the elements below?

Any assistance would be greatly appreciated.


<project name="Sample usage of Salesforce Ant tasks" basedir="." xmlns:sf="antlib:com.salesforce">
  <property file="build.properties" />
  <property environment="env" />
- <!--
 Deploy to server 
  --> 
- <target name="deploy">
- <sf:compileAndTest username="${sf.username}" password="${sf.password}" server="${sf.serverurl}" apiversion="10.0" baseDir=".">
- <runTests>
  <class>compileAndTest</class>
  </runTests>
  </sf:compileAndTest>
  </target>
- <!--
 Cleans up above. (Deletes can be combined with compiles.) 
  -->
- <target name="delete">
- <sf:compileAndTest username="${sf.username}" password="${sf.password}" server="${sf.serverurl}" apiversion="10.0">
  <deleteClass>compileAndTest</deleteClass>
  <deleteTrigger>addTasksOnComplete</deleteTrigger>
  <deleteTrigger>reassignChildItems</deleteTrigger>
  </sf:compileAndTest>
  </target>
  </project>