• venkat1
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Code:
trigger Ph1_calculatefieldLead on Lead (after update,after insert) {

//Lead [] le=Trigger.new;

Integer TotalPassToSales=0;
String LeadsViaCamapign='0125000000010WY';
String NonCampaginLeads='0125000000010WT';

for (Lead leLoop:Trigger.new){

 Integer CountCampaignPresent=[Select Count() from CampaignMember where LeadId=:leLoop.Id];
 
 //leLoop.adderror('e'+CountCampaignPresent);
 
 if(CountCampaignPresent==1){
 
  /* Select campaignid of linked Campaign */
  String LeadCampaignId=[Select CampaignId from CampaignMember where LeadId=:leLoop.Id].CampaignId;

  /* Select all LeadIds of Leads linked with a particular campaign */
  //CampaignMember [] LeadCampaignMember=[Select LeadId,CampaignId from CampaignMember where CampaignId=:LeadCampaignId];

  for(CampaignMember LeadCampaignMemberLoop:[Select LeadId,CampaignId from CampaignMember where CampaignId=:LeadCampaignId]){

   /* Check LeadId is not null */
   if(LeadCampaignMemberLoop.LeadId!=null){

    /* Select information about Lead linked with a particular Campaign*/
    Lead LeadCampaignLoop=[Select Status,lead_internal_lead_status_pck__c,RecordTypeid from Lead where id=:LeadCampaignMemberLoop.LeadId];

    /* Calculate Total Pass To Sales Leads */
    if(LeadCampaignLoop.Status=='Open - Passed to Sales' || LeadCampaignLoop.Status=='Closed - Accepted by Sales' || LeadCampaignLoop.Status=='Closed - Rejected by Sales' ){
     TotalPassToSales=TotalPassToSales+1;
     }
                }
}
/* Select campaign for Lead whose status is changed */
    Campaign camp=[select cam_tot_pass_to_sales_lead_num__c from campaign where id=:LeadCampaignId];

    /* Populating values into concerned fields of Campaign */
     camp.cam_tot_pass_to_sales_lead_num__c=TotalPassToSales;
               }
}

 hi all,
 
i tried to import 18 leads through data loader without any information about campaign.
i am getting error too many SOQL queries :21 at line ::::::Integer CountCampaignPresent=[Select Count() from CampaignMember where LeadId=:leLoop.Id] during after update . 
 
it is also saying 'data already exists' but no leads were present before importing.

please help me out.
 
regards,
mahi
  • January 02, 2008
  • Like
  • 0
Hello,

I have a Controller, or in other words simply an Apex method, that has a method that returns a PageReference object with some querystring parameters:

Code:
public PageReference save() {            

 String optyId = ApexPages.currentPage().getParameters().get('id');           

 PageReference opptyPage = new PageReference('/' + optyId + '/e');            

 String contractEndDateString = String.valueOf(getOpportunity().Contract_End_Date__c.month()) + '/' +String.valueOf(getOpportunity().Contract_End_Date__c.day()) + '/' + String.valueOf(getOpportunity().Contract_End_Date__c.year());
 opptyPage.getParameters().put('opp9', contractEndDateString);

 opptyPage.setRedirect(true);

 return opptyPage;
}

A date format in Apex is 'yyyy-MM-dd', so I manually convert it to 'MM/dd/yyyy' in order to prepopulate a 'close date' field (opp9) on Opportunity in edit mode:

Code:
String contractEndDateString = String.valueOf(getOpportunity().Contract_End_Date__c.month()) + '/' +String.valueOf(getOpportunity().Contract_End_Date__c.day()) + '/' + String.valueOf(getOpportunity().Contract_End_Date__c.year());
opptyPage.getParameters().put('opp9', contractEndDateString);

The problem is that 'MM/dd/yyyy' is a US standard of a date, so this prepopulation would fail for a date format, say, 'dd/MM/yyyy'.
How can this code be generic enough to handle this problem?


P.S. I tried to use the UserInfo.getLocale() method - but it doesnt' seem to be useful.

Thanks for your future replies!
Shamil
  • September 15, 2008
  • Like
  • 0
Code:
trigger Ph1_calculatefieldLead on Lead (after update,after insert) {

//Lead [] le=Trigger.new;

Integer TotalPassToSales=0;
String LeadsViaCamapign='0125000000010WY';
String NonCampaginLeads='0125000000010WT';

for (Lead leLoop:Trigger.new){

 Integer CountCampaignPresent=[Select Count() from CampaignMember where LeadId=:leLoop.Id];
 
 //leLoop.adderror('e'+CountCampaignPresent);
 
 if(CountCampaignPresent==1){
 
  /* Select campaignid of linked Campaign */
  String LeadCampaignId=[Select CampaignId from CampaignMember where LeadId=:leLoop.Id].CampaignId;

  /* Select all LeadIds of Leads linked with a particular campaign */
  //CampaignMember [] LeadCampaignMember=[Select LeadId,CampaignId from CampaignMember where CampaignId=:LeadCampaignId];

  for(CampaignMember LeadCampaignMemberLoop:[Select LeadId,CampaignId from CampaignMember where CampaignId=:LeadCampaignId]){

   /* Check LeadId is not null */
   if(LeadCampaignMemberLoop.LeadId!=null){

    /* Select information about Lead linked with a particular Campaign*/
    Lead LeadCampaignLoop=[Select Status,lead_internal_lead_status_pck__c,RecordTypeid from Lead where id=:LeadCampaignMemberLoop.LeadId];

    /* Calculate Total Pass To Sales Leads */
    if(LeadCampaignLoop.Status=='Open - Passed to Sales' || LeadCampaignLoop.Status=='Closed - Accepted by Sales' || LeadCampaignLoop.Status=='Closed - Rejected by Sales' ){
     TotalPassToSales=TotalPassToSales+1;
     }
                }
}
/* Select campaign for Lead whose status is changed */
    Campaign camp=[select cam_tot_pass_to_sales_lead_num__c from campaign where id=:LeadCampaignId];

    /* Populating values into concerned fields of Campaign */
     camp.cam_tot_pass_to_sales_lead_num__c=TotalPassToSales;
               }
}

 hi all,
 
i tried to import 18 leads through data loader without any information about campaign.
i am getting error too many SOQL queries :21 at line ::::::Integer CountCampaignPresent=[Select Count() from CampaignMember where LeadId=:leLoop.Id] during after update . 
 
it is also saying 'data already exists' but no leads were present before importing.

please help me out.
 
regards,
mahi
  • January 02, 2008
  • Like
  • 0