• SFDC-Acumen
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Due to some other issues (http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=8720 , http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=8138 ) I am unable to deploy code with the Eclipse Force.com toolkit.

I have looked over the ant documentation but to be honest I need it dumbed down a little....errr maybe a lot.

- I have installed ant here: c:\ant
- I have placed the ant-salesforce.jar file here: c:\ant\lib

Now I am supposed to set the environment variables (such as ANT_HOME, JAVA_HOME, and PATH) but I have no idea where I do this.

I think this is my correct Java directory: C:\Program Files\Java\jre1.6.0_07.

Once this is complete I'm still not sure how to proceed.

Thanks,
Jason


Message Edited by TehNrd on 10-14-2008 05:02 PM
  • October 14, 2008
  • Like
  • 0

I wrote the following code (replaced object/field names for simplicity) to handle rollup summary fields in Apex. It works pretty well but I frequently get errors when operating on bulk records or if no records exist (out of bounds, etc).

ParentObject__c :has_many Objects__c

Can anyone provide input as to whether or not I'm handling this type of task properly?

Code:
trigger rollupTrigger on Object__c (after insert, after update, after delete) {
    
    double totalSum = 0;
  
    Object__c myObjects = trigger.new;
    
    if(Trigger.isUpdate || Trigger.isInsert)
    {
            for(Object__c object : myObjects) //assume more than 1 record in trigger.new
            {
              for(ParentObject__c parent : [select Id, Name from ParentObject__c where Id = :object.Parent_Object__c]) //get the parent object
              {
                for(Object__c childObject : [select Id, Name, Number__c where Parent_Object__c = :parent.Id]) //get all the objects that belong to the parent object
                {
                  totalSum += childObject.Number__c;   //sum the field of choice
                }
                parent.Total__c = totalSum;   //set the total in the parent
                update parent                       // update the parent
              }
            }
    }
    else if(Trigger.isDelete)
    {
        Object__c [] oldObjects = Trigger.old;
        
      for(Object__c oldObject :oldObjects)    //assume deletion of more than 1 record
      {
        for (ParentObject__c parentObject : [select id, Name, Number__c, Total__c where Id = :oldObject.Parent_Object__c]) //get the parent object(s)
        {
          for (Object__c childObject : [select id, Name, Number__c from Object__c where Parent_Object__c = :parentObject.id])   //get the records that belong to the parent
          {
             totalSum += childObject.Number__c;  //sum the fields after a record has been deleted
          }
            parentObject.Total__c = totalSum;   //set new total in parent
            update parentObject;                      //update parent
        }   
      } //end oldObject for loop
    } //end else if
    
} //end trigger

Thanks!