• Ranjeet Singh Chouhan
  • NEWBIE
  • 55 Points
  • Member since 2011

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

Hi,

 

I am new to set & map methods. I have written a trigger as below but it throws me an error of Too many SOQL queries:101.

I read somewhere that I can overcome this by using map methods. Can anybody help me with this?

 

 

trigger TrainingShedulerNew on Revenue_Schedule__c (before update) {
List<Training_Schedule__c> Told = new list<Training_Schedule__c>();
List<Revenue_Schedule__c  > RNext = new list<Revenue_Schedule__c  >();
List<double> training = new List<double>();
            List<double> production = new List<double>();    
            integer count,j;
             Training_schedule__c Tn = new Training_Schedule__c();
for(Revenue_Schedule__c  R : trigger.New)
{
    
    Revenue_Schedule__c beforeUpdate = System.Trigger.oldMap.get(R.Id);
    {
        If ((R.No_of_FTE_s_for_Training__c!=beforeUpdate.No_of_FTE_s_for_Training__c)||(R.weeks__c!=beforeUpdate.weeks__c))
     {
    Told = [select id from Training_schedule__c where Related_Revenue_Schedule_Id__c=:R.id];
    if(Told.size()>0)
    delete Told;

    double weeks=R.weeks__c;
 if(weeks!=null)
               {
                  training.clear();
                 if(weeks==1)
                {
                 training.add(0.25);
                 production.add(0.75);
                }
                else if(weeks==2)
                {
                 training.add(0.50);
                 production.add(0.50);
                }
                else if(weeks==3)
                {
                 training.add(0.75);
                 production.add(0.25);
                }
                else if(weeks==4)
                {
                 training.add(1);
                 production.add(0.0);
                }             

    }
    
    Rnext=[select id, price_book_name__r.id,No_of_FTE_s_for_Training__c  from Revenue_Schedule__c where price_book_name__c=:r.price_book_name__c and date__c>=:r.date__c order by date__c limit 1];
     
    for(count=0,j=0; j<Rnext.size(); j++)
    {
if(R.No_of_FTE_s_for_Training__c > 0)
  {
        double tt=0;
        double pp=0;
        double tFee;
        double pFee;
        double fee;
        double feee;
        integer size;
        
        size=training.size();
        if(count<training.size())
         tt =training[count];
        else
         tt=0;        
      
        if(tt<1)
        pp=r.No_of_FTE_s_for_Training__c;
        else
        pp=0;                   
        
         Tn = new Training_Schedule__c(Revenue_Schedule__c= RNext[j].id,
                                                       price_book__c=RNext[j].price_book_name__r.id,
                                                       No_of_FTE_for_Training__c=R.No_of_FTE_s_for_Training__c ,
                                                      training__c=tt,                                                      
                                                        
                                                        Related_Opportunity_Name__c=R.Opportunity_ID__c,
                                                      No_of_FTE_for_Production__c=size,
                                                       production__c=1-tt,
                                                       Related_Revenue_Schedule_Id__c=R.id
                                                      // Date_by_Sales__c=R.Date__c
                                                      );
         insert Tn;
      
        }
       
       
        count=count+1;
   }}
   
}}

 for(Revenue_Schedule__c  Rs : trigger.New)
{
 List<training_schedule__c> ts= new list<training_schedule__c>();
 List<revenue_schedule__c> rs1= new list<revenue_schedule__c>();
 
 ts=[select id, amount__c from training_schedule__c where price_book__c=:rs.price_book_name__c];
 
    integer size=ts.size();
    double amount=0;

    for(integer i=0; i<size;i++)
    {
    amount=amount+ts[i].amount__c;
    }         
    rs.Maximum_amount__c=amount;

}  


}

 

Thanks in advance

 

 

 

 

Hi All, Need one help below I am trying to query the Lastupdated Field and then store it in a variable and then use it in another query to fetch record from another object , below is the query used Datetime Dt = [SELECT LastModifiedDate FROM MigrationDate__c order by LastModifiedDate desc Limit 1].LastModifiedDate; The above query returns something like 2011-12-20 00:33:56 but when I use this in another query it does not work and I guess it expects the date values as 2011-12-20T00:33:56.000Z . Do you know how can I use it in the query or is there any function ? pls let me know Regards Tom

Hi,

 

I am new to set & map methods. I have written a trigger as below but it throws me an error of Too many SOQL queries:101.

I read somewhere that I can overcome this by using map methods. Can anybody help me with this?

 

 

trigger TrainingShedulerNew on Revenue_Schedule__c (before update) {
List<Training_Schedule__c> Told = new list<Training_Schedule__c>();
List<Revenue_Schedule__c  > RNext = new list<Revenue_Schedule__c  >();
List<double> training = new List<double>();
            List<double> production = new List<double>();    
            integer count,j;
             Training_schedule__c Tn = new Training_Schedule__c();
for(Revenue_Schedule__c  R : trigger.New)
{
    
    Revenue_Schedule__c beforeUpdate = System.Trigger.oldMap.get(R.Id);
    {
        If ((R.No_of_FTE_s_for_Training__c!=beforeUpdate.No_of_FTE_s_for_Training__c)||(R.weeks__c!=beforeUpdate.weeks__c))
     {
    Told = [select id from Training_schedule__c where Related_Revenue_Schedule_Id__c=:R.id];
    if(Told.size()>0)
    delete Told;

    double weeks=R.weeks__c;
 if(weeks!=null)
               {
                  training.clear();
                 if(weeks==1)
                {
                 training.add(0.25);
                 production.add(0.75);
                }
                else if(weeks==2)
                {
                 training.add(0.50);
                 production.add(0.50);
                }
                else if(weeks==3)
                {
                 training.add(0.75);
                 production.add(0.25);
                }
                else if(weeks==4)
                {
                 training.add(1);
                 production.add(0.0);
                }             

    }
    
    Rnext=[select id, price_book_name__r.id,No_of_FTE_s_for_Training__c  from Revenue_Schedule__c where price_book_name__c=:r.price_book_name__c and date__c>=:r.date__c order by date__c limit 1];
     
    for(count=0,j=0; j<Rnext.size(); j++)
    {
if(R.No_of_FTE_s_for_Training__c > 0)
  {
        double tt=0;
        double pp=0;
        double tFee;
        double pFee;
        double fee;
        double feee;
        integer size;
        
        size=training.size();
        if(count<training.size())
         tt =training[count];
        else
         tt=0;        
      
        if(tt<1)
        pp=r.No_of_FTE_s_for_Training__c;
        else
        pp=0;                   
        
         Tn = new Training_Schedule__c(Revenue_Schedule__c= RNext[j].id,
                                                       price_book__c=RNext[j].price_book_name__r.id,
                                                       No_of_FTE_for_Training__c=R.No_of_FTE_s_for_Training__c ,
                                                      training__c=tt,                                                      
                                                        
                                                        Related_Opportunity_Name__c=R.Opportunity_ID__c,
                                                      No_of_FTE_for_Production__c=size,
                                                       production__c=1-tt,
                                                       Related_Revenue_Schedule_Id__c=R.id
                                                      // Date_by_Sales__c=R.Date__c
                                                      );
         insert Tn;
      
        }
       
       
        count=count+1;
   }}
   
}}

 for(Revenue_Schedule__c  Rs : trigger.New)
{
 List<training_schedule__c> ts= new list<training_schedule__c>();
 List<revenue_schedule__c> rs1= new list<revenue_schedule__c>();
 
 ts=[select id, amount__c from training_schedule__c where price_book__c=:rs.price_book_name__c];
 
    integer size=ts.size();
    double amount=0;

    for(integer i=0; i<size;i++)
    {
    amount=amount+ts[i].amount__c;
    }         
    rs.Maximum_amount__c=amount;

}  


}

 

Thanks in advance

 

 

 

 

I have an application(custom object).I want to create a custom button named "submit" on application which when clicked change the record type of application.Please help

  • December 20, 2011
  • Like
  • 0
Hi All, Need one help below I am trying to query the Lastupdated Field and then store it in a variable and then use it in another query to fetch record from another object , below is the query used Datetime Dt = [SELECT LastModifiedDate FROM MigrationDate__c order by LastModifiedDate desc Limit 1].LastModifiedDate; The above query returns something like 2011-12-20 00:33:56 but when I use this in another query it does not work and I guess it expects the date values as 2011-12-20T00:33:56.000Z . Do you know how can I use it in the query or is there any function ? pls let me know Regards Tom