• blake.tanon
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 10
    Replies
We're running into a performance issue that we would appreciate guidance on:
 
We need to a like query on the Name field in the Account object, something like:
 
[select name from account where name like '%bendoug%' or name like '%gustavo%' or name like '%Ben%' or name like '%wyeth%']
 
This query is taking very long time to process.
 
The business requirement is matching against the account name.
 
Has anybody run into this issue, and solved it?
 
Thanks.
 
-Haroon

I've got a visualforce email template that has a vf component in it that runs off a class as it's controller.  The class gets the current records ID via ApexPages.currentPage().getParameters().get('id').  The issue is that the email sends out perfect in Sandbox but sends as a NULL subject/body in production.  When I change the WHERE clause in the queries that picks the ID to a real record ID instead of getting it from the page it works however.  Is there a better way to get the ID, any idea why this isn't working?  Also the component/class work if I call them from a button to a VF page on the record.

 

This email works in Sandbox - but not Production

 

public class TerritoryDailyReport{

    //Territory record data
    public Territory__c t {get;set;}
    //public id tid {get;set;}
    //Lists
    public static list<territory_rank__c> bd;
    public static list<Contact> reps;
    public static list<Contact> repopps;
    public static list<Contact> repep;

    // method
    public TerritoryDailyReport(){
        
        t = [SELECT id, name, best_mo_sales__c, best_mo__c, current_mo_sales__c, current_mo_pace__c
             FROM territory__c
             WHERE id =: ApexPages.currentPage().getParameters().get('id')];
        
        bd = [SELECT id, name, firm__r.name, firm__c, best_mo__c, best_mo_sales__c, current_mo_sales__c, producers_this_mo__c,
                  producers__c, territory_name__c, total_sales__c
              FROM territory_rank__c
              WHERE territory__c =: ApexPages.currentPage().getParameters().get('id')
              ORDER BY current_mo_sales__c desc];
    
        reps = [SELECT id, name, account.name, opps_this_month__c, best_month__c, best_month_amount__c,
                    current_month__c, next_trade_amount__c, next_trade_date__c, total_reit_sales__c,
                    accountid, mailingstate
                FROM contact
                WHERE xterritory__c =: ApexPages.currentPage().getParameters().get('id') AND current_month__c != null
                    AND current_month__c != 0
                ORDER BY current_month__c desc];
                
        repopps = [SELECT id, name, account.name, opps_this_month__c, best_month__c, best_month_amount__c,
                       current_month__c, next_trade_amount__c, next_trade_date__c, total_reit_sales__c,
                       accountid, mailingstate
                   FROM contact
                   WHERE xterritory__c =: ApexPages.currentPage().getParameters().get('id') AND (current_month__c = null
                       OR current_month__c = 0) AND opps_this_month__c != null AND opps_this_month__c != 0
                   ORDER BY opps_this_month__c desc];
        
        repep = [SELECT id, name, account.name, opps_this_month__c, best_month__c, best_month_amount__c,
                     current_month__c, next_trade_amount__c, next_trade_date__c, total_reit_sales__c,
                     accountid, mailingstate
                 FROM contact
                 WHERE xterritory__c =: ApexPages.currentPage().getParameters().get('id') AND (current_month__c = null
                       OR current_month__c = 0) AND (opps_this_month__c = null OR opps_this_month__c = 0) AND
                       next_trade_amount__c != null AND next_trade_amount__c != 0 AND (next_trade_date__c = THIS_MONTH
                       OR next_trade_date__c = NEXT_n_DAYS:15) AND total_reit_sales__c > 0
                 ORDER BY next_trade_date__c asc];
        
        
    }
    
    public static List<territory_rank__c> getbd() {
        return bd;
    }
    
    public static List<contact> getreps() {
        return reps;
    }
    
    public static List<contact> getrepopps() {
        return repopps;
    }
    
    public static List<contact> getrepep() {
        return repep;
    }
    
    
}

 

 

 

I'm trying to get a list of contact ids out of a list of campaignmembers, to do this i first build the list of campaign members, then attempt to put the contactid into a set.  I'm running into the error at this point and can't figure out out to fix it.

 

 

 

global with sharing class CampaignROI_Reps{

    public static list<CampaignMember> cList;
    public static set<id> contacts;

    public AggregateResult SalesResultsPost30 {get;set;}

    public CampaignROI_Reps(){
        
        //get distribution aggregate data
        cList = [SELECT id, contactid, campaignid, rep_name__c, firm__c,
                     reit_sales__c, reit_tickets__c, calls__c, meetings__c, pipeline__c, 
                     territory__c
                 FROM CampaignMember
                 WHERE Campaignid =:ApexPages.currentPage().getParameters().get('id')];
       
       if(clist.size() > 0){
           for(campaignmember c:clist){
               if(c.contactid != null){
                   contacts.add(c.contactid);
               }
           }
       }
       
       SalesResultsPost30 = [SELECT SUM(Gross_Amount__c) total1
                       FROM Transaction__c 
                       WHERE Rep__c in: contacts AND 
                           trade_date__c >: date.valueof(ApexPages.currentPage().getParameters().get('enddate')) AND
                           trade_date__c <: date.valueof(ApexPages.currentPage().getParameters().get('enddate')) + 30];
       
             
    }
    
    public static list<CampaignMember> getcList(){
        return clist;
    }
    
}

 

Hello,

 

I have a meet to sync, or at least just send events in salesforce to our exchange server to show up in outlook.  The events will be created by an internal sales user for their external counterpart, which is why we can't use the SFDC/Outlook connector - and we don't want to buy an app for this.  I searhed around the web and couldn't find any information on this, any suggestions on where to start?

In regards to the system limitations within apex, are the limits reset for each trigger that i run in a process?  Or do the limits take an aggregate of all triggers run independantly on the object?

 

i.e. If I update an event

Trigger 1 fires & completed without running any other triggers

Trigger 2 fires & completed without running any other triggers

-are these 2 sets of limitations or one?

I'm getting the too many SOQL limit on the start of a trigger, the query isn't in a loop but the set of IDs is retrieved in a loop - maybe that is why?  If so how could I get around this?

 

trigger eventTrigger on Event (before insert, before update) {

    set<ID> owner = new Set<ID>();
        for(event t:trigger.new)
        owner.add(t.ownerid);

    List<User> u = [SELECT Id, UserRole.Name
                           FROM USER
                           WHERE id in: owner
                           LIMIT 1];

//logic below

}

 

Hello,

 

I'm not quite sure how to ask for what I'm looking for so I'll tell you what I'm trying to do.

 

I want to find records laying the middle of a range, for example it is easy to find the first date a sales was made and the last date a sales was made.  I want to find the first, second, third, fourth, fifth and sixth dates that sales were made to a contact record.  With this I want to see how many data points for different activities lay within these ranges.  

 

What would be best approach to doing this be?  Is there a way to effectively number the differen sales records?

Greetings All,

 

I'm working on a process to require our sales reps to ask for a referral every 30 days from each contact.  I'm going to post my thoughts on how to best do this and would like any thoughts.

 

Contact Field: Last Referral Date (Date)

Task Field: Status (Picklist Standard) Not Started - Completed

     Status controls Outcome, is Completed then opens values.

Task Field: Outcome (Picklist) Success - Failure

     This field will control Referral, if Success then picklist opens.

Task Field: Referral (Picklist) Yes - No 

 

Now, I need a write a trigger that will populate Last Referral Date on contact when a task is saved with Status=Completed, Outcome=Success & Referral=(Yes or No).

 

What I'm struggling with is how to validate the task and also display on the task that a referral is required to save it.  I can't write a trigger to populate a field on task because we have recurring tasks and tasks scheduled out over time that won't be updated correctly.  My thought is to have a VF page saying 'Ask for Referral' or something ot that sort where the logic would pull from the Last Referral Date on teh related contact.  How would I go about doing that and then validating it as well?

 

 

 

 

Hello,

I'm a novice programmer at best, i've got a very large trigger that i'm working on for CampaignMembers.  We want to populate fields on the CampaignMember record to show Sales($), Orders(#), Calls(#) & Meetings(#) for the 90 days prior then 90 days post Campaign StartDate.

 

When I wrote this I had 6 different SOQL queries for each set of fields for a total of 24 - which kills the test class.  If I break the code down into 24 different triggers I can get to 77% coverage, but I would rather not do that if there is a better way to do it.

 

I'm sure this is the lest effcient way to write this code but here is a snippet for the first fields which at -30days from start date.  Where the testclass as issues (in this smaller version - the complete it hits SOQL limits and fails with 67%) is in the BLUE highlighted areas 

 

trigger CMTrans3 on CampaignMember(before update)
{

Integer i = 0;

CampaignMember cm = Trigger.new[i];

// Current CampaignMember and Contact ID
String intCm = Trigger.new[i].Id;
CampaignMember cmm = [Select Contact.id, Start_Date__c, Sales_1__c, Meeting_1__c, Calls_1__c, Kits_1__c from CampaignMember where id =: intCm];

//Step 2. Create a list of Transactions who are children of Contact record.
List<Contact> cnt = [Select Contact.id from Contact where Contact.id =: cmm.Contact.id];
List<Transaction__c> tr3 = [Select Transaction__c.Id, Transaction__c.Gross_Amount__c, Transaction__c.Trade_Date__c From Transaction__c WHERE Transaction__c.Rep__c =: cmm.Contact.id AND Transaction__c.Trade_Date__c <: cmm.Start_Date__c AND Transaction__c.Trade_Date__c >: cmm.Start_Date__c - 30];
List<Task> tsk3 = [Select Task.Id, Task.Completed__c From Task WHERE WhoId =: cmm.Contact.id AND Task.ActivityDate <: cmm.Start_Date__c AND Task.ActivityDate >: cmm.Start_Date__c - 30];
List<Event> evt3 = [Select Event.Id, Event.Completed__c From Event WHERE WhoId =: cmm.Contact.id AND Event.ActivityDate <: cmm.Start_Date__c AND Event.ActivityDate >: cmm.Start_Date__c - 30];
List<Order__c> o3 = [Select Order__c.Id, Order__c.Contact__c, Order__c.Number_of_Kits__c, Order__c.Order_Date__c FROM Order__c WHERE Order__c.Contact__c =: cmm.Contact.id AND Order__c.Order_Date__c <: cmm.Start_Date__c AND Order__c.Order_Date__c >: cmm.Start_Date__c - 30]; Double a = 0; // Loop through the filtered Transactions last 30 days and sum up their amounts. for(Transaction__c tr : tr3) { If (tr.Gross_Amount__c != Null) { a += tr.Gross_Amount__c; } } cm.Sales_1__c = a; Double a2 = 0; // Loop through the filtered Task last 30 days and sum up amount. for(Task tski : tsk3) { If (tski.Completed__c != Null) { a2 += tski.Completed__c; } } cm.Calls_1__c = a2; Double a3 = 0; // Loop through the filtered Task last 30 days and sum up amount. for(Event evti : evt3) { If (evti.Completed__c != Null) { a3 += evti.Completed__c; } } cm.Meeting_1__c = a3; Double a4 = 0; // Loop through the filtered Task last 30 days and sum up amount. for(Order__c oi1 : o3) { If (oi1.Number_of_Kits__c != Null) { a4 += oi1.Number_of_Kits__c; } } cm.Kits_1__c = a4; }

 

I've got a visualforce email template that has a vf component in it that runs off a class as it's controller.  The class gets the current records ID via ApexPages.currentPage().getParameters().get('id').  The issue is that the email sends out perfect in Sandbox but sends as a NULL subject/body in production.  When I change the WHERE clause in the queries that picks the ID to a real record ID instead of getting it from the page it works however.  Is there a better way to get the ID, any idea why this isn't working?  Also the component/class work if I call them from a button to a VF page on the record.

 

This email works in Sandbox - but not Production

 

public class TerritoryDailyReport{

    //Territory record data
    public Territory__c t {get;set;}
    //public id tid {get;set;}
    //Lists
    public static list<territory_rank__c> bd;
    public static list<Contact> reps;
    public static list<Contact> repopps;
    public static list<Contact> repep;

    // method
    public TerritoryDailyReport(){
        
        t = [SELECT id, name, best_mo_sales__c, best_mo__c, current_mo_sales__c, current_mo_pace__c
             FROM territory__c
             WHERE id =: ApexPages.currentPage().getParameters().get('id')];
        
        bd = [SELECT id, name, firm__r.name, firm__c, best_mo__c, best_mo_sales__c, current_mo_sales__c, producers_this_mo__c,
                  producers__c, territory_name__c, total_sales__c
              FROM territory_rank__c
              WHERE territory__c =: ApexPages.currentPage().getParameters().get('id')
              ORDER BY current_mo_sales__c desc];
    
        reps = [SELECT id, name, account.name, opps_this_month__c, best_month__c, best_month_amount__c,
                    current_month__c, next_trade_amount__c, next_trade_date__c, total_reit_sales__c,
                    accountid, mailingstate
                FROM contact
                WHERE xterritory__c =: ApexPages.currentPage().getParameters().get('id') AND current_month__c != null
                    AND current_month__c != 0
                ORDER BY current_month__c desc];
                
        repopps = [SELECT id, name, account.name, opps_this_month__c, best_month__c, best_month_amount__c,
                       current_month__c, next_trade_amount__c, next_trade_date__c, total_reit_sales__c,
                       accountid, mailingstate
                   FROM contact
                   WHERE xterritory__c =: ApexPages.currentPage().getParameters().get('id') AND (current_month__c = null
                       OR current_month__c = 0) AND opps_this_month__c != null AND opps_this_month__c != 0
                   ORDER BY opps_this_month__c desc];
        
        repep = [SELECT id, name, account.name, opps_this_month__c, best_month__c, best_month_amount__c,
                     current_month__c, next_trade_amount__c, next_trade_date__c, total_reit_sales__c,
                     accountid, mailingstate
                 FROM contact
                 WHERE xterritory__c =: ApexPages.currentPage().getParameters().get('id') AND (current_month__c = null
                       OR current_month__c = 0) AND (opps_this_month__c = null OR opps_this_month__c = 0) AND
                       next_trade_amount__c != null AND next_trade_amount__c != 0 AND (next_trade_date__c = THIS_MONTH
                       OR next_trade_date__c = NEXT_n_DAYS:15) AND total_reit_sales__c > 0
                 ORDER BY next_trade_date__c asc];
        
        
    }
    
    public static List<territory_rank__c> getbd() {
        return bd;
    }
    
    public static List<contact> getreps() {
        return reps;
    }
    
    public static List<contact> getrepopps() {
        return repopps;
    }
    
    public static List<contact> getrepep() {
        return repep;
    }
    
    
}

 

 

I actually understand what the error is telling me - I just cannot figure out how to fix it.

 

I have this trigger on the Opportunity:  And it works perfectly...

 

trigger OpportunityUpdateAccount on Opportunity( before insert, before update ) {
    List<Account> accsToUpdate = new List<Account>();

    for(Opportunity opp : trigger.new){
        if (opp.Stage_Calc__c != null &&  opp.Amount  >= 50000 && (opp.type.contains('New Business') | (opp.type.contains('Existing Business'))))
            accsToUpdate.add(new Account(Id = opp.AccountId, Active_Opp_over_50kcalc__c = true));
                 else if (opp.Stage_Calc__c == null && (opp.type.contains('New Business') | (opp.type.contains('Existing Business'))))
            accsToUpdate.add(new Account(Id = opp.AccountId, Active_Opp_over_50kcalc__c = false));      
                     
   }
if (accsToUpdate != null)
        update(accsToUpdate);

 However, when I add this trigger: it breaks giving the error below the code...

 

trigger partnerOpClone on Opportunity (after update) {
Opportunity opp = [select Id, closedate from Opportunity where StageName = '09-Win' and type = 'Reseller / Partner Registration' LIMIT 1];  
Opportunity newOpp = opp.clone(false, true);
newOpp.StageName='trainging';
newOpp.amount=null;
newOpp.name=account.name + 'partner';
newOpp.closedate=opp.closedate;
insert newOpp;
}

 Error:Apex trigger partnerOpClone caused an unexpected exception, contact your administrator: partnerOpClone: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityUpdateAccount: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Trigger.OpportunityUpdateAccount: line 12, column 1: []: Trigger.partnerOpClone: line 8, column 1

 

 

I get that the error is telling me there is an issue with the insertion and the other trigger firing - I have tried multiple things to fix it, but I am completely stummped. Any help would be appreciated.

We're running into a performance issue that we would appreciate guidance on:
 
We need to a like query on the Name field in the Account object, something like:
 
[select name from account where name like '%bendoug%' or name like '%gustavo%' or name like '%Ben%' or name like '%wyeth%']
 
This query is taking very long time to process.
 
The business requirement is matching against the account name.
 
Has anybody run into this issue, and solved it?
 
Thanks.
 
-Haroon

I'm getting the too many SOQL limit on the start of a trigger, the query isn't in a loop but the set of IDs is retrieved in a loop - maybe that is why?  If so how could I get around this?

 

trigger eventTrigger on Event (before insert, before update) {

    set<ID> owner = new Set<ID>();
        for(event t:trigger.new)
        owner.add(t.ownerid);

    List<User> u = [SELECT Id, UserRole.Name
                           FROM USER
                           WHERE id in: owner
                           LIMIT 1];

//logic below

}

 

If a roll-up field changing, will be trigger update activity?

 

Thanx,

Krix

  • April 24, 2013
  • Like
  • 0

Hello,

 

I'm not quite sure how to ask for what I'm looking for so I'll tell you what I'm trying to do.

 

I want to find records laying the middle of a range, for example it is easy to find the first date a sales was made and the last date a sales was made.  I want to find the first, second, third, fourth, fifth and sixth dates that sales were made to a contact record.  With this I want to see how many data points for different activities lay within these ranges.  

 

What would be best approach to doing this be?  Is there a way to effectively number the differen sales records?

Images in PDF attachment of a Visualforce email Template are missing in time based workflows or when called from @future method:

 

I have a VF email template which references images from a static resource. This works perfectly, if I send the email from workflow rule, except for, if it is a time based workflow or if the workflow is a result of a change made in a @future apex method.

 

The email is still sent out, but all images are missing and are replaced by the standard VF-icon for missing images.

 

Easy Steps to reproduce:

 

1. create a simple VF email with PDF attachment

 

 

<messaging:emailTemplate subject="BugTest" recipientType="Contact">
<messaging:htmlEmailBody >
Body
</messaging:htmlEmailBody>

<messaging:attachment renderAs="pdf" filename="bugTest.pdf">
<img src="{!URLFOR($Resource.pdfLogo)}"/>
</messaging:attachment>

</messaging:emailTemplate>

 

2. create a method which uses the template (replace the IDs with IDs from your org)

 

 

@Future

public static void sendBuggyMails() {
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setTargetObjectId('003S0000004qO5I');
email.setTemplateId('00XS0000000QN6W');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
}

 

3. Call the @future.method e.g. from execute anonymous

 

==> you receive an email with a PDF attachment but without the image

 

4. Remove the @future annotation and call the method again

 

==>  you receive an email with a PDF attachment including the image

 

 

The same issue happens, when the email is sent from a time based workflow, or from a workflow which was triggered from a @future-method.

 

 

Is this a bug or am I doing something wrong here?

 

 

Ingo

 

 

 

 

 

 

  • November 03, 2009
  • Like
  • 0