• JuFe
  • NEWBIE
  • 40 Points
  • Member since 2012
  • Applications Developer
  • Desynit


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 8
    Replies
Hi Guys,

I'm running into to the governor limit - Too many SOQL query 101
My trigger works normally until I tried to dump 2.5k worth of records in. I thought I was batchifying code properly, but now I'm confused. (btw I tried moving the AggregatedResult out from - for(AggregatedResult ar) - to it's own line and it ran into the same issue. May be I'm looking in the wrong place?

trigger HQDisplayTotalNewAccount on Account (after insert, after undelete)
{
	//variable to keep all HQ IDs for processing
	Set<Id> parentIds = new Set<Id>();
	
	//grab what was being saved first
    for (Account acc : Trigger.new)
    {
    	//process if a child, else change the values back
        if (acc.ParentId != null)
        {
            parentIds.add(acc.ParentId);
        }
    }
    
    if (parentIds.size() > 0)
    {
        List<Account> updates = new List<Account>();
        
        // Leave the job of calculating the sum to the database
        for (AggregateResult ar : 
        		[
                SELECT ParentId p
                		,sum(Couture_Display__c) sumCD
                		,sum(Abode_Display__c) sumAD
                		,sum(KW_Gallery_Display__c) sumKGD
                		,sum(KW_Gallery_Cabinet__c) sumKGC
                		,sum(KW_Tower_Display__c) sumKTD
                		,sum(KW_Wire_Rack__c) sumKWR
                		,sum(KW_Mod_10__c) sumKMT
                		,sum(Evoke_Lam_Gallery_Display__c) sumELGD
                		,sum(Evoke_LV_Gallery_Display__c) sumELVG
                		,sum(Evoke_Gallery_Cabinet__c) sumEGC
                		,sum(Evoke_Tower_Display__c) sumETD
                		,sum(Evoke_Wire_Rack__c) sumEWR
                		,sum(Evoke_Mod_10__c) sumEMT
                		,sum(X2012_Sales__c) sumTW
                		,sum(X2013_Sales__c) sumTR
                		,sum(X2014_Sales__c) sumFO
                FROM Account
                WHERE ParentId in :parentIds
                GROUP BY ParentId
                ])
        {
        	
            // Update without the cost of a preceding query
            updates.add(new Account(Id = (Id) ar.get('p')
            						, Couture_Display__c = (Decimal) ar.get('sumCD')
            						, Abode_Display__c = (Decimal) ar.get('sumAD')
            						, KW_Gallery_Display__c = (Decimal) ar.get('sumKGD')
            						, KW_Gallery_Cabinet__c = (Decimal) ar.get('sumKGC')
            						, KW_Tower_Display__c = (Decimal) ar.get('sumKTD')
            						, KW_Wire_Rack__c = (Decimal) ar.get('sumKWR')
            						, KW_Mod_10__c = (Decimal) ar.get('sumKMT')
            						, Evoke_Lam_Gallery_Display__c = (Decimal) ar.get('sumELGD')
            						, Evoke_LV_Gallery_Display__c = (Decimal) ar.get('sumELVG')
            						, Evoke_Gallery_Cabinet__c = (Decimal) ar.get('sumEGC')
            						, Evoke_Tower_Display__c = (Decimal) ar.get('sumETD')
            						, Evoke_Wire_Rack__c = (Decimal) ar.get('sumEWR')
            						, Evoke_Mod_10__c = (Decimal) ar.get('sumEMT')
            						, X2012_Sales__c = (Decimal) ar.get('sumTW')
            						, X2013_Sales__c = (Decimal) ar.get('sumTR')
            						, X2014_Sales__c = (Decimal) ar.get('sumFO')
            						)
            		   );
        }
        
        
        // This update will cause this trigger to fire again
        update updates;
    }

}
Oh, and this trigger is suppose to add up each column from all the child under a parent and then update that column in the parent with the total.

Thanks,

  • August 11, 2014
  • Like
  • 0
Basically Im getting problem after problem, I had to make an Apex class to use as a coustom contoller which all worked well and then I proceeded to "try" and put it on live where I was stopped dead in my tracks because of code coverage after struggling for ages then finally getting an answer on the form I was able to achive 77% coverage. I went to upload to live again and then I got the error :-The error
After applying a work around my code coverage has dropped to 70% and im really struggling to get the coverage back upto the 75% threshold to even begin testing if the work around does the job. The testing still compleatly confuses me and Im an absolute begginer so I dont know how to format or develop in Apex too well as of yet. Was just hoping if somone can point me in the right direction for gaining the 75% required.

This is my 70% that is covered:-
User-added image  
Here is my Testing Class:-
 User-added image

Thankyou,
Sorry if its super simple and I cant process it.
Hi All,

We are looking to integrate salesforce with onedrive for storing attachemnts. We have a file upload option in VF page, once user selects file and upload then file should be store in onedrive and a link has to be provided in salesforce custom object. Is there any examples/steps available for this process.

Thanks in Advance!!
Hi Guys,

I'm running into to the governor limit - Too many SOQL query 101
My trigger works normally until I tried to dump 2.5k worth of records in. I thought I was batchifying code properly, but now I'm confused. (btw I tried moving the AggregatedResult out from - for(AggregatedResult ar) - to it's own line and it ran into the same issue. May be I'm looking in the wrong place?

trigger HQDisplayTotalNewAccount on Account (after insert, after undelete)
{
	//variable to keep all HQ IDs for processing
	Set<Id> parentIds = new Set<Id>();
	
	//grab what was being saved first
    for (Account acc : Trigger.new)
    {
    	//process if a child, else change the values back
        if (acc.ParentId != null)
        {
            parentIds.add(acc.ParentId);
        }
    }
    
    if (parentIds.size() > 0)
    {
        List<Account> updates = new List<Account>();
        
        // Leave the job of calculating the sum to the database
        for (AggregateResult ar : 
        		[
                SELECT ParentId p
                		,sum(Couture_Display__c) sumCD
                		,sum(Abode_Display__c) sumAD
                		,sum(KW_Gallery_Display__c) sumKGD
                		,sum(KW_Gallery_Cabinet__c) sumKGC
                		,sum(KW_Tower_Display__c) sumKTD
                		,sum(KW_Wire_Rack__c) sumKWR
                		,sum(KW_Mod_10__c) sumKMT
                		,sum(Evoke_Lam_Gallery_Display__c) sumELGD
                		,sum(Evoke_LV_Gallery_Display__c) sumELVG
                		,sum(Evoke_Gallery_Cabinet__c) sumEGC
                		,sum(Evoke_Tower_Display__c) sumETD
                		,sum(Evoke_Wire_Rack__c) sumEWR
                		,sum(Evoke_Mod_10__c) sumEMT
                		,sum(X2012_Sales__c) sumTW
                		,sum(X2013_Sales__c) sumTR
                		,sum(X2014_Sales__c) sumFO
                FROM Account
                WHERE ParentId in :parentIds
                GROUP BY ParentId
                ])
        {
        	
            // Update without the cost of a preceding query
            updates.add(new Account(Id = (Id) ar.get('p')
            						, Couture_Display__c = (Decimal) ar.get('sumCD')
            						, Abode_Display__c = (Decimal) ar.get('sumAD')
            						, KW_Gallery_Display__c = (Decimal) ar.get('sumKGD')
            						, KW_Gallery_Cabinet__c = (Decimal) ar.get('sumKGC')
            						, KW_Tower_Display__c = (Decimal) ar.get('sumKTD')
            						, KW_Wire_Rack__c = (Decimal) ar.get('sumKWR')
            						, KW_Mod_10__c = (Decimal) ar.get('sumKMT')
            						, Evoke_Lam_Gallery_Display__c = (Decimal) ar.get('sumELGD')
            						, Evoke_LV_Gallery_Display__c = (Decimal) ar.get('sumELVG')
            						, Evoke_Gallery_Cabinet__c = (Decimal) ar.get('sumEGC')
            						, Evoke_Tower_Display__c = (Decimal) ar.get('sumETD')
            						, Evoke_Wire_Rack__c = (Decimal) ar.get('sumEWR')
            						, Evoke_Mod_10__c = (Decimal) ar.get('sumEMT')
            						, X2012_Sales__c = (Decimal) ar.get('sumTW')
            						, X2013_Sales__c = (Decimal) ar.get('sumTR')
            						, X2014_Sales__c = (Decimal) ar.get('sumFO')
            						)
            		   );
        }
        
        
        // This update will cause this trigger to fire again
        update updates;
    }

}
Oh, and this trigger is suppose to add up each column from all the child under a parent and then update that column in the parent with the total.

Thanks,

  • August 11, 2014
  • Like
  • 0
Our Org has a number of workflow generated tasks to help our users know what to do for an opportunity depending on which stage the opportunity is in. This is working well, but we are running into the issue of tasks coming due on weekends. I know this has been asked a number of times and I have done some digging and found an answer here (https://developer.salesforce.com/forums/ForumsMain?id=906F00000008uTgIAI) that worked quite well for a specific subject.

I am very new to Apex triggers and could use some help customizing the code to only work for opportunities of certain record types. Here is the code I am using:
trigger WeekendTasks on Task (after insert)
{ for (Task tas : Trigger.new)
  {  if (Opp.RecordType == 'RPA NTE-Perm' , 'RPA NTE(No Bid)' , 'RPA RFQ' , 'RPA Capital')
   {   Date origin = Date.newInstance(1900,1,6);
      Date due = tas.ActivityDate;
        Integer x = origin.daysBetween(due);
     Integer day = Math.mod(x,7);
     if (day < 2 )
     {    Task tt = new Task (
          Id = tas.Id,
           ActivityDate = (tas.ActivityDate + 2),
        Description = String.valueOf(day)    );
           update tt;
     } 
   }
  }
}
This trigger does not work as you probably already knew. If I replace the bold underlined line with:
if (tas.Subject == 'Change Stage - Awarded')
Everything works perfectly, but I do not want the trigger to fire off the Subject.  Could someone help me out with how to fire this trigger only for tasks associated with opportunity record types RPA RFQ, RPA NTE-Perm, RPA Capital and RPA NTE(No Bid)?

Thank you
This is my requirement?
 
Hi,

    i installed package from old org to new org, But i didn't get records from old org.

   How to get old environment data into New Environment?
   is it Possible ?

Building on the highly successful "Force West" Salesforce networking community for the South West, a developer spin off community, "Force by Force West" (FxFW) is starting.

The aim of this new group is to share experiences and thoughts on all things Force.com over a pint or two, from Apex and Visualforce to mobile applications and alternative cloud platforms.

The first event will take place on the 31st May at the Elephant pub in Central Bristol, next to St. Nicholas Market. 

 

More information about the event and group can be found through the FxFW Facebook Page, or by following the FxFW Barman on Twitter.

If you are interested, let us know by registering on our Eventbrite entry, purely so we can get an idea of how many are coming down.

 

Thanks,

 

Christopher Alun Lewis

 

-----------------------------------------------------------------------------------------------------

 

Check out my blog for all things Visualforce & Apex --> http://christopheralunlewis.blogspot.co.uk/