• steve456
  • NEWBIE
  • 280 Points
  • Member since 2011

  • Chatter
    Feed
  • 11
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 77
    Questions
  • 251
    Replies

Hello all,

 

I am getting the error below in my Lead trigger

 

Non-selective query against large object type (more than 100000 rows). Consider an indexed filter.

 

I am guessing my SOQL query in the list is returning too many results. It is:

 

List<CampaignMember> listCampaignMember = [Select Id,CampaignId,LeadId From CampaignMember Where LeadId IN:setLeadId];

 

I have read that a solution involves making one of the CampaignMember fields an "External ID" but don't know which one to do this for.

 

Any ideas on how to optimize my SOQL query or what field I should make an External ID on the CampaignMember object?

 

Thanks!

 

 

I need to create an event whenever Opportunity field Probability is greater than 50%

 

I have written the code but it keeps firing on every update.I want it to fire on an insert or if there is any change in probability

 

My code is 

 

********************************

 

trigger AutoEventCreate on Opportunity (after insert , after update) {

List <Event> eventList = new List <Event> ();
Set<Id> oppIds = new Set<Id>();
for(Opportunity opp:Trigger.new){
if(opp.Id!=null &&(Trigger.isInsert || (Trigger.newMap.get(opp.id).Probability != Trigger.oldMap.get(opp.Id).Probability))){

oppIds.add(opp.Id);
}

}

for(Opportunity opp:Trigger.new){
if(opp.Probability !=null && opp.Probability>=25.00){

datetime myDate = datetime.now();



eventList.add (new Event(
Subject = 'Other',
WhatId = opp.Id,
OwnerId = opp.OwnerId,
StartDateTime = DateTime.Now(),
ActivityDateTime=null,
EndDateTime = DateTime.Now(),
DurationInMinutes = Integer.valueOf(Math.Floor( (myDate.getTime() - myDate.getTime()) / (1000.0*60.0)))

));

}
if(eventList.size() > 0)

insert eventList;

}

}

 

 

***************************

 

Can you please correct y code and let me know if any scenarios need to be added

 

Thanks in advance

I have two  fiellds on object   Colors    ,   Rejection Reason

 

Colors is MULTISELECT picklist

 

Rejection Reason  is just a picklist 

 

 

Whenever the colors B,C,D,E,F,G  in any combination are selected  Rejection Reason field is mandatory

 

Whenever the color A is selected Rejection Reason is not mandatory

 

 

Whenever the color A is selected along with B,C,D,E,F,G   (any combination as it is a multi select picklist )  Rejection Reason is not mandatory

 

 

Colors has the following values                                                    

A, B ,C ,D,E,F,G ,H      

 

 

I am able to get through all scenarios except the third  

 

 

Can anybody please be a life saver for me                                                                         

How do i give created date equal to this month in apex

 

if(CreatedDate=THISMONTH)

 

HOw do i give it in Apex

 

Trigger on Order Entry 

 

 

ON CREATE ONLY

 

IF(RecordType.Name == "PG" && Product__r.Group__c == 'Data Plan) THEN

 

IF(LEFT(Order_Number__r.Inventory__r.Product__r.Name__c, 8) == "V-Portal" && Order_Number__r.Date__c >= 2013-02-11) THEN

            Additional_Revenue__c = 15

ELSE

            Additional_Revenue__c = 0

            ENDIF

 

 

******************How do I write a trigger as it has three cross references

 

Field on Order Entry :  Order Number    (Master Detail)

 

Field on OrderNumber : Inventory

 

Field on Inventory : Product

 

Field on Product :Name

 

*************************************************

 

Can you please help me write a trigger for the logic mentioned on top

 

Thanks in advance

Hi ,

I need to Clone a Record and once i clone i need the new record to have all fields carried and input the record Id from which it is cloned  ??

 

 

Please help me out with this very Urgent need

I am getting a null pointer exception.Do not know what mistake am doing 

 

 

CODE

 

 

trigger UpdateTransactRevenue on Order_Entry__c (before insert, before update) {
  Set<Id> productIdList=new Set<Id>();
  Set<Id> orderIdList=new Set<Id>();

  
  //process all records if they are new
  if(Trigger.isInsert)
  {
    for(Order_Entry__c oe:Trigger.new)
    {
      if(oe.Product__c!=null && oe.Order_Number__c!=null)
      {
        productIdList.add(oe.Product__c);
        orderIdList.add(oe.Order_Number__c);
      }
    }
  }
  
  if(Trigger.isUpdate)
  {
    for(Order_Entry__c oe:Trigger.new)
    {
         if(oe.Order_Number__c!=null && oe.Product__c!=null && oe.Product__c!=Trigger.oldMap.get(oe.Id).Product__c)
         {
         
           productIdList.add(oe.Product__c);
           orderIdList.add(oe.Order_Number__c);

           
         }
    }
  }
  
  
  
  if(productIdList.size()>0) 
  {
    //query for employee records
    Map<Id,Product_2020__c> productMap=new map<Id,Product_2020__c>([Select Id,Invoice_Rate_Blend__c , Invoice_Rate_Event__c from Product_2020__c where Id in:productIdList]);
    Map<Id,Order_2020__c>   orderMap = new Map<Id,Order_2020__c>([Select Id , Name , Transact_Kiosk_Category__c from Order_2020__c where Id in:orderIdList]);
    
    String recordtypeid=[Select Id from RecordType where Name='2020RK-VZ' and SobjectType='Order_Entry__c'].Id;
       
    if(orderMap!=null && orderMap.size()>0){
        for(Order_Entry__c oe:Trigger.new)
        {
         if(oe.RecordTypeId==recordtypeid){
           
           
               
               if(orderMap.get(oe.Order_Number__c)!=null && orderMap.get(oe.Order_Number__c).Transact_Kiosk_Category__c=='Event' && productMap!=null && productMap.get(oe.Product__c)!=null && productMap.size()>0 && productMap.get(oe.Product__c).Invoice_Rate_Event__c!=null)
               {
                   oe.Transact_Revenue__c=productMap.get(oe.Product__c).Invoice_Rate_Event__c * oe.Quantity__c; 
               }
               else if(orderMap.get(oe.Order_Number__c)!=null && orderMap.get(oe.Order_Number__c).Transact_Kiosk_Category__c!='Event'&& productMap!=null && productMap.get(oe.Product__c)!=null && productMap.size()>0 && productMap.get(oe.Product__c).Invoice_Rate_Blend__c!=null){
               
                   oe.Transact_Revenue__c=productMap.get(oe.Product__c).Invoice_Rate_Blend__c * oe.Quantity__c; 
               }
           
          }       
        } 
    }       
  } 

 

 

 

 

ERROR

 

 

caused by: System.NullPointerException: Argument 1 cannot be null

Trigger.UpdateTransactRevenue: line 57, column 1(highlighted is line 57)

 

 

 

 

Can any body help me please

I have three custom objects Product , Order ,  Order Entry

 

 

Order Entry has master detail with Order  and a  lookup to Product

 

 

I have a field called Revenue on Order Entry which needs to be  calculated based on  the  Category of Order 

 

 

I mean to say on Order I have a field called  Category  and based on this field I need to calculate the revenue  on Order Entry 

 

************

Trigger should execute upon Order Entry creation and whenever Order__r.Category__c is changed according to the following logic:

 

 

2.       IF(Order__r.Category__c <> "Event", Product__r.Invoice_Rate_Blend__c * Quantity__c, Product__r.Invoice_Rate_Event__c * Quantity__c)

 

 

 

I am struck as how do I do it do it  on an insert as well as an  update  as the Order field  is not changed  on the Order Entry but a particular field on Order is changed .

 

Hi All,

I'm not getting code coverage I need on this class.  Red lines aren't covered.  The test class is at the end of this post..

Any thoughts on how to cover these lines?  Thanks for any help!

 

UpdateMaxReviewDate (Code Covered: 69%)

 

 line source
 1  public with sharing class UpdateMaxReviewDate{
 2  
 3   public void updReviews(){
 4  
 5   Map<Id, Date> MaxDates = new Map<Id, Date>();
 6   List<IMNAccount__c> lstToUpdate = new List<IMNAccount__c>();
 7  
 8   for (AggregateResult ard : [Select imnaccount__c,
 9   Max(Review_Date__c) rd From Report_Review__c
 10   GROUP BY imnaccount__c]) {
 11  
 12   MaxDates.put(String.valueOf(ard.get('imnaccount__c')),(Date) ard.get('rd'));
 13  
 14  }
 15   Set <Id> imnacctSet = new Set<Id>();
 16   imnacctSet = MaxDates.keySet();
 17   for (IMNAccount__c imn : [Select i.Last_Report_Review__c, i.Id,
 18   i.Company__r.PM_Report_Review__c, i.PM_Report_Review_Date__c
 19   From IMNAccount__c i
 20   WHERE i.Id IN : imnacctSet]){
 21   imn.Last_Report_Review__c = MaxDates.get(imn.Id);
 22   imn.PM_Report_Review_Date__c = imn.Company__r.PM_Report_Review__c;
 23   lstToUpdate.add(imn);
 24   }
 25   if(lstToUpdate.size() > 0)
 26   update lstToUpdate;
 27  }

 

Here's my Test Code

 

@isTest
private class UpdateMaxReviewDateTest {

public static testMethod void testReviewDates() {
        
        Date d = Date.today();
        
        //Create Test Account
        Account atest = new Account();
        atest.Name = 'New Test Account';
        atest.PM_Report_Review__c = d;
        Database.insert(atest);
        
        //Create Test imnaccount
        IMNAccount__c itest = new IMNAccount__c();
        itest.Name = 'New Test Imnaccount';
        Database.insert (itest);
        
        //Create Test Report Review
        List<Report_Review__c> rList = new List<Report_Review__c>();
        for (Integer i=0; i<21; i++){
            Report_Review__c rtest = new Report_Review__c();
            rtest.Review_Date__c = d-i;
            rList.add(rtest);
        }
        
        Database.insert(rList);    
        
        Test.startTest();
        
        //instantiate class to be tested and call method
        UpdateMaxReviewDate urd = new UpdateMaxReviewDate();
        urd.updReviews();
        
        
        //validate
        for (IMNAccount__c imn : [Select i.Last_Report_Review__c, i.Id,
                            i.Company__r.PM_Report_Review__c, i.PM_Report_Review_Date__c
                            From IMNAccount__c i]){
                            Date a = imn.Company__r.PM_Report_Review__c;
                            Date b = imn.PM_Report_Review_Date__c;
                            System.assertEquals(a,b);
                                
                            AggregateResult agr = [Select Max(Review_Date__c) rd From Report_Review__c
                                        WHERE imnaccount__c = :imn.Id];
                            Date c = (Date) agr.get('rd');
                            Date e = imn.Last_Report_Review__c;
                            System.assertEquals(c,e);   
           }
           Test.stopTest();
}
}

Hi All,

I am an Apex noob and have never written an Apex trigger. I suspect that is what is required to do this. I am using basic Salesforce Accounts and Activities. I have tried to find a similar post on this board but have not found anything that does what I am trying to do - as simple as it may seem ;).

 

I have a read-only custom field in Accounts called CallCount_c (type number). I have a picklist field in Activities (aka Tasks) called MyActivity_c. I would like the custom field in Accounts to reflect the count of Activity records for this account where the MyActivity_c = "Phone Call". The Activity (Task) has a 'Related To" picklist where I choose 'Account" and then select the account to which this Activity is to be related.

 

Does that make sense?

Thanks in advance for reading, replies...

 

Currencies in our organization are loaded in 2010. Users are complaining about the change in exchange rates. If I update the exchnage rate under manage currencies section manually, will it impact the records created prior to this update?

 

Thank You in advance for the help.

I have a small doubt 
 
 
I have two obj Account and Contacts
 
 
Contact has a lookup to Account
 
 
 
I am trying  to insert  records of Accounts and I am able to do it successfully 
 
 
I am trying to insert records of Contact and I am able to do it successfully without the Account field
 
 
If i want to give the Account field in the Contact object what should i do
 
 
----------->I have only the Account names but not their ids . 
 
How can i do this
 

Hi all,

 

I have a workflow which creates two tasks when ever a record is created. To create a record I have 4 fields.

1)Year

2)Status

3)Project Manager

4)DIrector.

 

Now my question is when ever I create a record, My tasks which would be created should be assigned to the project manager dynamically. 

 

So we are looking at some 100 records where say may be 10 diffrent project managers are owning each 10 records.

 

So example 

 

If the project manager field is filled with the name Thomas then the work flow should trigger creating two tasks assigning them to thomas.

 

Similarly for Robin, kayla etc.

 

So I would insert 100 records with a dataloader and all records should be created with two tasks each assigned to respective PM .

 

If the task is always assigned to a single person, I'm able to do that but dynamically changing is what im faceing trouble.

 

Could some one help me in this. Can it be performed using wokflows or it needs to be coded?