• homer671
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 18
    Replies

I pushed a trigger live a couple of weeks ago and it seemed to be working fine. But in the last two days, I've received 11 emails notifying me of an error. I've tested and can't duplicate the error and I'm not sure what's causing it. I think it must be an automated process that's trying to create an event because none of my users have complained about the error. How can I determine what is causing the error and how can I fix it?

 

Here's the error: 

 

Trigger.EventIndustry: line 28, column 38

Apex script unhandled trigger exception by user/organization: 00560000000m32k/00D600000006nRH

EventIndustry: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

 

Here's the code:

trigger EventIndustry on Event (before insert, before update) {
	if(trigger.isInsert){
        //create a set of all unique WhatIDs and WhoIDs
        set<id> WhoIDs = new Set<id>();
        Set<id> WhatIds= new Set<id>();
        Set<id> AccountIds= new Set<id>();
        
        for (Event t : trigger.new){
        	if (String.valueOf(t.whoId)!= null){
               	WhoIDs.add(t.WhoID); 
        	}else if (String.valueOf(t.WhatID)!= Null){
        		WhatIds.add(t.WhatID);
         	}else if (String.valueOf(t.AccountID)!= Null){
        		AccountIds.add(t.AccountID);
        	}
        }   
        //create a map for a hash table for the industry
       	Map<id, Lead> who = new Map<id, Lead>([SELECT Industry FROM Lead WHERE ID in :WhoIDs]);     
	   	Map<Id, Account> acct = new Map<Id, Account>([Select Industry From Account Where ID in :AccountIds OR ID in: WhatIDs]);
	   	Map<id, Contact> con = new Map<id, Contact>([SELECT Account.Industry from Contact WHERE ID in :WhoIDs]);
	   	Map<id, Opportunity> opp = new Map<id, Opportunity>([Select Account.Industry From Opportunity Where Id in :WhatIDs]);	
		
		// iterate over the list of records being processed in the trigger and set the industry
		for (Event a : Trigger.new){
			if (!who.isEmpty()){
		    	a.Industry__c = who.get(a.WhoId).Industry;
			} else if (!con.isEmpty()){
				a.Industry__c = con.get(a.WhoId).account.Industry;
			} else if (!opp.isEmpty()){
				a.Industry__c = opp.get(a.WhatId).account.Industry;
			} else if (acct != null && !acct.isEmpty()){
					if(acct.ContainsKey(a.whatID)){
						a.Industry__c = acct.get(a.whatID).Industry;
					}else if(acct.ContainsKey(a.AccountId)){
						a.Industry__c = acct.get(a.AccountId).Industry;
					}
			}
		}
	} else {
		if(trigger.isUpdate){
			 //create a set of all unique ids 
	        set<id> WhoIDs = new Set<id>();
	        Set<id> WhatIds= new Set<id>();
	        Set<id> AccountIds= new Set<id>();
			
			for (Event t : Trigger.new){
				if (Trigger.oldMap.get(t.Id).WhoId != Trigger.newMap.get(t.Id).WhoId){
					WhoIDs.add(t.WhoID); 
				}else if (Trigger.oldMap.get(t.Id).WhatID != Trigger.newMap.get(t.Id).WhatID){
					WhatIds.add(t.WhatID);
				}else if (Trigger.oldMap.get(t.Id).AccountID != Trigger.newMap.get(t.Id).AccountID){
					AccountIDs.add(t.AccountID);
				}
			}
			
			//create a map for a hash table for the industry
       		Map<id, Lead> who = new Map<id, Lead>([SELECT Industry FROM Lead WHERE ID in :WhoIDs]);     
	   		Map<Id, Account> acct = new Map<Id, Account>([Select Industry From Account Where ID in :AccountIds OR ID in: WhatIDs]);
	   		Map<id, Contact> con = new Map<id, Contact>([SELECT Account.Industry from Contact WHERE ID in :WhoIDs]);
	   		Map<id, Opportunity> opp = new Map<id, Opportunity>([Select Account.Industry From Opportunity Where Id in :WhatIDs]);	
			
			for (Event a : Trigger.new){
				if (!who.isEmpty()&& who.ContainsKey(a.WhoId)){
			    	a.Industry__c = who.get(a.WhoId).Industry;
				} else if (!con.isEmpty()){
					a.Industry__c = con.get(a.WhoId).account.Industry;
				} else if (!opp.isEmpty()){
					a.Industry__c = opp.get(a.WhatId).account.Industry;
				} else if (acct != null && !acct.isEmpty()){
					if(acct.ContainsKey(a.whatID)){
						a.Industry__c = acct.get(a.whatID).Industry;
					}else if(acct.ContainsKey(a.AccountId)){
						a.Industry__c = acct.get(a.AccountId).Industry;
					}
				}
			}
		}		
	}
}

 

Thanks,

 

Wendy

I have a simple trigger on Leads that needs to know if the Owner is a User or a Queue.

 

Can anyone show me the (proably very) simple solution to this? My code is below, with the 'real world' question if Owner = Queue.

 

 

 Set<id> ownerIds = new Set<id>();
    for (Lead l : Trigger.new)
        ownerIds.add(l.OwnerId);
        
    Map<id, User> owners = new Map<id, User>([Select Id from User Where Id in :ownerIds]);      
    
    for (Lead l : Trigger.new)
        if(l.Owner = queue){
        //l.Owner_Usable__c = null;
        } else {
        //l.Owner_Usable__c  = owners.get(l.OwnerId).Id;
        }

 

 

 

Hi,

 

I am a little bit confused with sandbox login. We are using Free Edition that has 1 sandbox limit and after creating sandbox, only that person who created sandbox is able to log in there. Other users cannot log in even they see it under Setup-> data monitoring.

 

Is this how it works or is there any settings that needs to be changed in order allow other users to log in?

  • March 15, 2011
  • Like
  • 0

Can CONTAINS or BEGINS used to reference a lookup field, or does it have to be text?  The following formula for a lead assignment rule is not working. I figured it most be how I'm using CONTAINS and/or BEGINS. 

 

ISPICKVAL(Geography__c, "EMEA") && CONTAINS (Product_Interest__c, "Alliance") &&

BEGINS (Product_Interest__c, "GA")
If I can't use functions CONTAINS or BEGINS, what would I use to make sure a person was assigned a lead when the Geography is EMA, Product Interest begins with "GA" and Product Interest contains "Alliances".  I have to go with creating this rule in a formula because I can't reference the Product Interest field in the via the standard lead assignment UI because the Product Interest field is a lookup field.
thanks in advance for your help.

Hi,

 

I have a trigger and a test class... the code coverage for trigger is 100% in sandbox.. but when i tried deploying it to production.. it gives an error saying that minimum 1% code coverage for the trigger??? I am noty able to understand why is it so...

 

 

Although i tried deploying test class first but it says that the custom object is missing???

 

I am using Eclipse as well as Setup -> Deploy... for deployment.

  • September 12, 2010
  • Like
  • 0

Hi,

 

I have some very simple trigger in sandbox. Something like to update a particular field value to another value for custom objects.

 

Now, i want to deploy my custom object to production.. but it is giving me an error saying that "Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required"

 

I am not able to understand why is it coming up??Since my trigger is working fine in sandbox.

 

what to do in that case?? please help.

 

If i need to write an some apex class and all.. then i am not totally aware of how to go about and it and where and what has to be written in that class. Please see the following trigger:

 

trigger updaterequestowner on Pre_Sales_Request__c (before insert)
{
        Profile auth_profile = [select id from profile where name='HS_StandardUser_Presales'];         
        Id v_User = UserInfo.GetProfileId();   
    for(Pre_Sales_Request__c ob : Trigger.new)
        {   
            if(v_User !=  auth_profile.Id)      
                {   
                   ob.Request_Owner__c =  Userinfo.getUserId();  
                }  
        }                
}

can somebody please help in this....

  • September 08, 2010
  • Like
  • 0

Hi All,

In the code pasted below, i need to avoid the query in the for loop. My Intention is to pick up one record per id(per each UniqueId). To achieve this i have to place the query in a for loop which will hit the governer limits(max SOQL query 100) if number of accounts are more. So, is there a way of getting one record (already mentioned in query as LIMIT 1) per account id without looping through each account id(eachUniqueId).

Please help me out.

 

Thanks in advance,

Nishanth.

 

Here goes my code:

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

List<Account> updatableAccountList = new List<Account>();

for(Id eachUniqueId:uniqueIdList){

List<Task> tasksPerId = [Select WhatId,Status,ActivityDate from Task where ActivityDate>today and WhatId =: eachUniqueId and Status != 'Completed' ORDER BY ActivityDate ASC NULLS last LIMIT 1];

Account acc = new Account(Id=tasksPerId[0].WhatId);

           acc.whs_task_Status__c = tasksPerId[0].Status;

acc.whs_upcomingTask__c = tasksPerId[0].ActivityDate;

updatableAccountList.add(acc);

}

update updatableAccountList;

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


F

Hi,

 

When I try to modify a field in an object I get this error(which is actually in a trigger).

 

 Update failed. First exception on row 0 with id; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, : execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 2 with id; first error: FIELD_INTEGRITY_EXCEPTION, Value does not exist or does not match filter criteria. Click icon to select a value.: [] 

 

Pls. let me know how to solve this issue and also if you need more details

 

Message Edited by gv on 02-18-2010 08:42 AM
  • February 17, 2010
  • Like
  • 0

Hello,

 

 

I have an issue in Apex triggers can any one help me out: I have a lraedy made two post but didnot get any reply .please help me out as it is very urjent for me.

 

Here is the code of my Apex trigger test class: 

 

public class sampleTest{

static testMethod void WCSFTrigger(){

    Map<String, Individual_Email_Results__c> lgaMap = new Map<String, Individual_Email_Results__c>();

    Individual_Email_Results__c objInsert = new Individual_Email_Results__c();

    objInsert .Hard_Bounce__c = 1; 

    objInsert .Abuse__c = '1';

    objInsert .GlobalUnsubscribe__c = '1';

    objInsert .UniversalUnsubscribe__c = '1';

    objInsert .Unsubscribe__c = '1';

    objInsert .Lead__c = '00Q90000001S4fL';

    objInsert .Contact__c = '00390000001bZ1V';

   

    insert objInsert ;

 

//Here the triggers fires on updation 

    objInsert . Unsubscribe__c = '3'; 

    update objInsert;

 

    Decimal newValue = objInsert .Hard_Bounce__c;//obj.Hard_Bounce__c;

    Decimal oldValue = 2; 

    String contactID = objInsert.Contact__c;//'00390000001bZ1V';

    String leadID = objInsert.Lead__c; 

    

    system.debug(objInsert.Contact__c);

    if(newValue != oldValue)

    {

    

     system.debug(contactID);

    

    if(contactID  != null)

    {

    

         Contact contact = [Select Id, HasOptedOutOfEmail from contact WHERE Id=: contactID ];

         system.debug(contact);

         system.debug(contact.HasOptedOutOfEmail);

         if(contact.HasOptedOutOfEmail == true)

               {

                contact.HasOptedOutOfEmail = false;

                   //system.assertEquals(contact.HasOptedOutOfEmail , false); 

               }

               else

               {

                contact.HasOptedOutOfEmail = true;

                   //system.assertEquals(contact.HasOptedOutOfEmail , true);

               }

               update contact;

    }

    

    if(objInsert.Lead__c!= null)

    {

        Lead lead = [Select Id, HasOptedOutOfEmail from lead WHERE Id=:objInsert.Lead__c];

         if(lead .HasOptedOutOfEmail == true)

               {

                 system.assertEquals(lead .HasOptedOutOfEmail , true); 

               }

               else

               {

                  system.assertEquals(lead .HasOptedOutOfEmail , true); 


               }

               update lead ;

    }

    

     if( (objInsert.Abuse__c != '2') || (objInsert.GlobalUnsubscribe__c != '2') || (objInsert.UniversalUnsubscribe__c != '2') || (objInsert.Unsubscribe__c != '2'))

        {

            if(objInsert.Contact__c!= null)

            {  

               Contact contact = [Select Id, EmailBouncedDate , EmailBouncedReason from contact WHERE Id=:objInsert.Contact__c];

               system.assertEquals( contact.EmailBouncedReason , 'WhatCounts Hard Bounce'); 

                

               update contact;

                   

            }

            if(objInsert.Lead__c!= null)

            {              

               Lead lead= [Select Id, EmailBouncedDate , EmailBouncedReason from lead WHERE Id=:objInsert.Lead__c];

               system.assertEquals( lead.EmailBouncedReason , 'WhatCounts Hard Bounce'); 

               

               update lead;

            }

         

        }

 

 

I have a problem in writing test class for  code which has bold font .Please let me know if there is any issue.

 

 

 

The trigger is:

 

trigger WCSFTrigger on Individual_Email_Results__c (after update) {

Map<String, Individual_Email_Results__c> lgaMap = new Map<String, Individual_Email_Results__c>();

       for (Individual_Email_Results__c objUpdate: System.Trigger.New) {

       

        Individual_Email_Results__c obj= [Select id,Contact__c,Lead__c,Hard_Bounce__c,Abuse__c,GlobalUnsubscribe__c,UniversalUnsubscribe__c,Unsubscribe__c,Hard_Bounce_Event_Date__c  from Individual_Email_Results__c where id= :objUpdate.Id];

        string contactID = obj.Contact__c;

        string leadID = obj.Lead__c;

        Decimal newValue = trigger.new[0].Hard_Bounce__c;

        Decimal oldValue = trigger.old[0].Hard_Bounce__c;

       

        if(newValue != oldValue )

        {

            if(contactID != null)

            {  

               Contact contact = [Select Id, HasOptedOutOfEmail from contact WHERE Id=:contactID ];

               if(contact.HasOptedOutOfEmail == true)

               {

                  contact.HasOptedOutOfEmail = false;

               }

               else

               {

                  contact.HasOptedOutOfEmail = true;

               }

               update contact;

                   

            }

            if(leadId != null)

            {              

               Lead lead = [Select Id, HasOptedOutOfEmail from lead WHERE Id=: leadId];

               if(lead.HasOptedOutOfEmail == true)

               {

                  lead.HasOptedOutOfEmail = false;

               }

               else

               {

                   lead.HasOptedOutOfEmail = true;

               }

               update lead;

            }

             

        }        

        if( (trigger.new[0].Abuse__c != trigger.old[0].Abuse__c) || (trigger.new[0].GlobalUnsubscribe__c != trigger.old[0].GlobalUnsubscribe__c) || (trigger.new[0].UniversalUnsubscribe__c != trigger.old[0].UniversalUnsubscribe__c) || (trigger.new[0].Unsubscribe__c != trigger.old[0].Unsubscribe__c))

        {

            if(contactID != null)

            {  

               Contact contact = [Select Id, EmailBouncedDate , EmailBouncedReason from contact WHERE Id=:contactID ];

               contact.EmailBouncedReason = 'WhatCounts Hard Bounce';

               contact.EmailBouncedDate = datetime.valueOf(obj.Hard_Bounce_Event_Date__c);

               update contact;

                   

            }

            if(leadId != null)

            {              

               Lead lead= [Select Id, EmailBouncedDate , EmailBouncedReason from lead WHERE Id=:leadID ];

               lead.EmailBouncedReason = 'WhatCounts Hard Bounce';

               lead.EmailBouncedDate =  datetime.valueOf(obj.Hard_Bounce_Event_Date__c);

               update lead;

            }

         

        }

        }

       

 

 

Please let me know if any changes has to be done.

I have followed the APEX DOCS TO WRITE THE CODE. I have already made two posts regarding this issue but didnot get any reply.

 

Thanks

 

  • December 12, 2009
  • Like
  • 0
I'd like to remove the [New] button from the Opportunity tab (screen).  But I don't want to alter the Opportunity [New] functionality elsewhere.
 
How do I do this? 
  • April 18, 2008
  • Like
  • 0