• alx
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 23
    Replies

Hey everyone,

 

Having a bit of trouble getting coverage for a trigger i wrote on Lead Conversion. I think a big problem i'm facing is that i don't completely understand test coverage conceptually.

 

 

Here's my trigger, it's working in Sandbox 100%. It basically fills in some fields in the resulting opportunity during lead conversion and inserts a partner as well.

trigger ResellerLeadConvert on Lead (after update) {
 
  // no bulk processing; will only run from the UI
  if (Trigger.new.size() == 1) {
 
    if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true && (Trigger.old[0].LeadSource == 'ADPResellerDeal' || Trigger.old[0].LeadSource == 'ResellerDeal' || Trigger.old[0].LeadSource == 'ADPPartnerReferral')) {
 
      // if a new opportunity was created
      if (Trigger.new[0].ConvertedOpportunityId != NULL) {
 
        // update the converted opportunity with some text from the lead
        Opportunity opp = [Select o.Id, o.LeadSource, o.CloseDate, o.ADP_Deal__c, o.NextStep, o.Portal_Status__c from Opportunity o Where o.Id = :Trigger.new[0].ConvertedOpportunityId];
        opp.LeadSource = Trigger.old[0].LeadSource;
        opp.ADP_Deal__c = 'No';
        if(Trigger.old[0].LeadSource == 'ADPPartnerReferral' || Trigger.old[0].LeadSource == 'ADPResellerDeal'){
            opp.ADP_Deal__c = 'Yes';
        }

        opp.NextStep = 'Rep to qualify';
        opp.Portal_Status__c = 'This Oppty is a new sale / will create a new portal';
        
        date fwdCloseDate = date.today();
        opp.CloseDate = fwdCloseDate.addDays(60);
        update opp; 
      
      // gather Campaign information from lead   
  List<CampaignMember> ResellerMembers = new List<CampaignMember>();
        ResellerMembers = [Select LeadId, z_CoSponsorAccID__c from CampaignMember where LeadId = :Trigger.old[0].Id];
        Map<Id, Id> mapCampaignMember = new Map<Id, Id>();
        
        for(CampaignMember m : ResellerMembers){
            mapCampaignMember.put(m.LeadId, m.z_CoSponsorAccID__c);
        }
        
      // if lead has a campaign and campaign is tied to a co-sponosor account, a partner will be created  
    if(mapCampaignMember.get(Trigger.new[0].Id)!= NULL){
    Partner newPart = new Partner();
        newPart.AccountToId = mapCampaignMember.get(Trigger.new[0].Id);
        newPart.OpportunityId = opp.Id;
        newPart.IsPrimary = true;
        newPart.Role = 'VARS/Reseller';
        if(Trigger.old[0].LeadSource == 'ADPPartnerReferral'){
            newPart.Role = 'Referral Partner - Sourced';
        }
        insert newPart;
    }
       
 
      }         
 
    }
 
  }     
 
}

 

Here's my test class. I got as far as creating the elements that the trigger covers (Lead, Campaign, CampaignMember, the Campaign's Account) but i'm unclear as to how to 'test' the lead conversion part.

 

@isTest
private class testResellerLeadConvert {
    static testMethod void testConversion() {

    
        Lead L = new Lead(Company ='ABC Co', Email = '123@123.com', LastName = 'Freeman', LeadSource = 'ADPPartnerReferral', NumberOfEmployees = 100, Phone = '1234567', 
            Partner_Salesperson_Email_Address__c = '123@123.com',
            Partner_Salesperson_Contact_Details__c ='x',
            Opportunity_Pain_Compelling_Event__c = 'x',
            Opportunity_Timeline__c = 'x',
            Opportunity_Executive_Sponsor_s__c= 'x',
            IsConverted = TRUE);
        insert L;

        Account ResellerAcc = new Account(Name= 'BlackMesa');
        insert ResellerAcc;
        
        Campaign C = new Campaign(Name ='BMCampaign', Co_Sponsoring_Account__c = ResellerAcc.Id,
            Campaign_Vendor__c = 'ADP',
            Type = 'Referral Program (Opportunity Leads)',
            Topic__c = 'test topic',
            Campaign_Country__c = 'USA');
        insert C;
        
        CampaignMember CMember = new CampaignMember(LeadId = L.Id, Campaign = C, CampaignId = C.Id);
        insert CMember;
        
        
        Test.startTest();
        
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(L.Id);
        
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());

        Test.stopTest();
        
    
    
    
    
    
    }
}

 

Any help is greatly appreciated.

  • July 26, 2012
  • Like
  • 0

hey all,

 

Does anyone know if i can deploy classes to live SF without meeting the test class requirement?

 

If not, i need some help getting to 75% coverage on the following batch class:

 

 

global class countRefContacts implements Database.Batchable<sObject>{
	global final String gstrQuery = 'select ID, Number_of_Reference_Contacts__c from Account';
    global Database.QueryLocator start(Database.BatchableContext BC){
		return Database.getQueryLocator(gstrQuery);
    } 
    global void execute(Database.BatchableContext BC, List<sObject> scope){
 		List<Account> listAccount = new List<Account>();
      		for(SObject objSObject : scope){
				Account objAccount = (Account)objSObject;
				Integer intNumberOfRefs = [SELECT count()FROM Contact WHERE AccountID = :objAccount.ID and Email != null and Binary_Reference_Contact__c = 1];
			  	if (intNumberOfRefs <> objAccount.Number_of_Reference_Contacts__c){
			  		objAccount.Number_of_Reference_Contacts__c = intNumberOfRefs;
			  		listAccount.add(objAccount);
			  	}
		    }	         
       if (listAccount.size() > 0 ) {update listAccount;}
    }
    	global void finish(Database.BatchableContext BC){
    }

}

 

 

What i have so far:

 

public class testCountRefContacts{
	static testMethod void testCountRefContacts(){
		
	List<Account> accns = new List<Account>();
	List<Contact> cons = new List<Contact>();
	for (Integer i = 0; i<199; i++){
		Account a = new Account(name = 'test' + i, Id = 'id' + i);
		Contact c = new Contact(LastName = 'testcon', AccountId = 'id' + i);
		accns.add(a);
		cons.add(c);
	}
	
	insert accns;
	insert cons;
	
	Test.StartTest();
	countRefContacts count = new countRefContacts();

	ID batchprocessid = Database.executeBatch(count);
	
	Test.StopTest();
	
	for(Account a : accns){
		System.assertEquals(0, a.Number_of_Reference_Contacts__c);
	}
	}
}

 

help!

 

 

 

  • August 30, 2010
  • Like
  • 0

hey everyone,

 

I am trying to deploy an edited version of a class already scheduled in live salesforce.

 

I am getting the following errors:

errors

 

I have uploaded many small scheduling tasks and triggers into SF without test classes and they've gone through. However, this time i got a Deploy Error. Is there a work around without having to write a ton of test classes?

 

I have done extensive testing in the sandbox for my upload and it has been fine. The edits contained in NDA counter are really small for my the already up and running version in live SF.

 

any help is appreciated. 

  • August 23, 2010
  • Like
  • 0

Hey everyone,

 

The workhorse for my scheduled counter is giving me DML 101 issues. Anyone know how i can bulkify the following code?

 

 

global class countAgreements implements Database.Batchable<sObject>{
	global final String gstrQuery = 'select ID, Number_of_Agreements__c from Opportunity';
    global Database.QueryLocator start(Database.BatchableContext BC){
		return Database.getQueryLocator(gstrQuery);
    } 
	global void execute(Database.BatchableContext BC, List<sObject> scope){
		List<Opportunity> listOpp = new List<Opportunity>();
		for(SObject objSObject : scope){
			Opportunity objOpportunity = (Opportunity)objSObject;
			Integer intNumberOfAgreements = [SELECT count() FROM echosign_dev1__SIGN_Agreement__c WHERE OpportunityID = :objOpportunity.ID and Is_Type_NDA__c = 1];
			if (intNumberOfAgreements <> objOpportunity.Number_of_Agreements__c){
				objOpportunity.Number_of_Agreements__c = intNumberOfAgreements;
				listOpp.add(objOpportunity);
			}
		if (listOpp.size()>0) {update listOpp;}
		}
	}
	global void finish(Database.BatchableContext BC){
	}
}

 

 

 

any help is greatly appreciated.

  • August 12, 2010
  • Like
  • 0

Hey everyone,

 

This trigger query is killing me.

 

I am writing a trigger to sum up custom field Scores in Contact.

 

I want to display the sum in Account.

 

I want to query the database for all the Scores for each Contact in an Account.

 

I guess my fundamental understanding of apex code sucks, nothing i'm doing seems to even compile.

Here's my code:

 

 

trigger sumContactScore on Account (after insert, after update) {
	
	Set<Id> accIDs = new Set<Id>();
	for(Account a: Trigger.new){
		accIDs.add(a.Id);
	}
	
	for(Account a : Trigger.new){
		
		Double sum = 0;

		List<Contact> scoreList = new List<Contact>();

		scoreList = [SELECT LS_Implicit_Contact_Score__c FROM Contact WHERE Email != null and Contact.AccountId in :accIDs];
		
		for(Contact i : scoreList){
			sum += i.LS_Implicit_Contact_Score__c;
		}
		
		a.Sum_of_Implicit_Behavior_Scores__c = sum;	
	}

}

 

 

 

Help.

  • July 22, 2010
  • Like
  • 0

Hey everyone,

 

I need to count the number of Agreements in each Opp, then post that number in a custom field in Opportunity.

 

I was thinking i would use batch update counting for the task.

 

At the same time, I know that Agreements is an EchoSign component.. but i need to link it with Salesforce API in the Opportunity.

 

Does anyone have any ideas as to how i should approach this?

 

  • July 14, 2010
  • Like
  • 0

Hey guys,

 

I found this wonderful scheduled batch update code on the forums:

 

global class countContacts implements Database.Batchable<sObject>{
	global final String gstrQuery = 'select ID, Number_of_Contacts_w_Email__c from Account';
    global Database.QueryLocator start(Database.BatchableContext BC){
		return Database.getQueryLocator(gstrQuery);
    } 
    global void execute(Database.BatchableContext BC, List<sObject> scope){
 		List<Account> listAccount = new List<Account>();
      		for(SObject objSObject : scope){
				Account objAccount = (Account)objSObject;
      			Integer intNumberOfContacts = [SELECT count()FROM Contact WHERE AccountID = :objAccount.ID];   
				if (intNumberOfContacts <> objAccount.Number_of_Contacts_w_Email__c){
			    	objAccount.Number_of_Contacts_w_Email__c = intNumberOfContacts;
					listAccount.add(objAccount);
			  	 }
		       }	         
       if (listAccount.size() > 0 ) {update listAccount;}
    }
    	global void finish(Database.BatchableContext BC){
    }
}

 

 

 

The field Number_of_Contacts_w_Email__c counts all the contacts in an account. But as the variable name implies, i would like it to count only contacts with an email address. I know that count() can take in a fieldname, but the returned AggregateResult is not an integer?

 

Anyone have any tips on how i can count contacts only under certain conditions like email, or if its a reference contact?

 

Also: Does anyone know how this code would run with like 50k accounts?

 

Thanks!

 

edit: link to my code - http://community.salesforce.com/t5/Apex-Code-Development/Update-Contact-Count-for-Accounts/m-p/173038

  • June 24, 2010
  • Like
  • 0

Hey all,

 

I have a NullPointerException in my trigger. The purpose of the trigger is to use Snapshot to find its parent Opportunity's Owner Id, then apply this Id to Snapshot.

 

 

trigger Insert_RelatedOwnerID_as_SnapShotPipeForecast_by_Opp on SnapShot_Pipe_Forecast_by_Opp__c (before insert) {
		Map<Id, SnapShot_Pipe_Forecast_by_Opp__c> smap = new Map<Id, SnapShot_Pipe_Forecast_by_Opp__c>([select id, Opportunity_lookup__r.OwnerId from SnapShot_Pipe_Forecast_by_Opp__c where id in :Trigger.newMap.keySet()]);
         	
         	for(SnapShot_Pipe_Forecast_by_Opp__c s: Trigger.new){
              s.OwnerId = smap.get(s.Id).Opportunity_lookup__r.OwnerId;
			}
}

 

 

 

The exception is thrown on line 2, column 191. I'm sure it's an easy fix, but I can't see it.

 

Any help is appreciated.

  • June 16, 2010
  • Like
  • 0

Hey all,

 

I'm new to apex coding and i'm have an incredibly hard time understanding something that should be really simple.

 

I have a custom object Reference_Request__c that has a field OftR__c - reference

 

OftR__c in turn is reference to Opportunity.

 

Basically, what i want to do is set Reference_Request__c 's OwnerId to OftR__c's OwnerId.

 

I know that OwnerId is a lookup for OftR__c, but i dont really know what that means or how i should approach something like that.

 

this is what i have so far, but it returns an Exception on line 5.

 

trigger Insert_RelatedOwnerID_as_RefReqOwnerID on Reference_Request__c (before update, before insert) {
	List<Reference_Request__c> l = new List<Reference_Request__c>();
	for(Reference_Request__c req: Trigger.new){
		l = [Select req.OftR__r.Owner_ID__c From Reference_Request__c req limit 1];
		req.OwnerId = l[0].OwnerId;

	
	}
}

 

 

 

 

 

 

While i'm here asking for help, could someone explain the child-parent, parent-child relationship i have here? I read the web api on relationships and i just cant seem to connect the dots.

 

Any help is appreciated

  • June 16, 2010
  • Like
  • 0

Hey everyone,

 

Having a bit of trouble getting coverage for a trigger i wrote on Lead Conversion. I think a big problem i'm facing is that i don't completely understand test coverage conceptually.

 

 

Here's my trigger, it's working in Sandbox 100%. It basically fills in some fields in the resulting opportunity during lead conversion and inserts a partner as well.

trigger ResellerLeadConvert on Lead (after update) {
 
  // no bulk processing; will only run from the UI
  if (Trigger.new.size() == 1) {
 
    if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true && (Trigger.old[0].LeadSource == 'ADPResellerDeal' || Trigger.old[0].LeadSource == 'ResellerDeal' || Trigger.old[0].LeadSource == 'ADPPartnerReferral')) {
 
      // if a new opportunity was created
      if (Trigger.new[0].ConvertedOpportunityId != NULL) {
 
        // update the converted opportunity with some text from the lead
        Opportunity opp = [Select o.Id, o.LeadSource, o.CloseDate, o.ADP_Deal__c, o.NextStep, o.Portal_Status__c from Opportunity o Where o.Id = :Trigger.new[0].ConvertedOpportunityId];
        opp.LeadSource = Trigger.old[0].LeadSource;
        opp.ADP_Deal__c = 'No';
        if(Trigger.old[0].LeadSource == 'ADPPartnerReferral' || Trigger.old[0].LeadSource == 'ADPResellerDeal'){
            opp.ADP_Deal__c = 'Yes';
        }

        opp.NextStep = 'Rep to qualify';
        opp.Portal_Status__c = 'This Oppty is a new sale / will create a new portal';
        
        date fwdCloseDate = date.today();
        opp.CloseDate = fwdCloseDate.addDays(60);
        update opp; 
      
      // gather Campaign information from lead   
  List<CampaignMember> ResellerMembers = new List<CampaignMember>();
        ResellerMembers = [Select LeadId, z_CoSponsorAccID__c from CampaignMember where LeadId = :Trigger.old[0].Id];
        Map<Id, Id> mapCampaignMember = new Map<Id, Id>();
        
        for(CampaignMember m : ResellerMembers){
            mapCampaignMember.put(m.LeadId, m.z_CoSponsorAccID__c);
        }
        
      // if lead has a campaign and campaign is tied to a co-sponosor account, a partner will be created  
    if(mapCampaignMember.get(Trigger.new[0].Id)!= NULL){
    Partner newPart = new Partner();
        newPart.AccountToId = mapCampaignMember.get(Trigger.new[0].Id);
        newPart.OpportunityId = opp.Id;
        newPart.IsPrimary = true;
        newPart.Role = 'VARS/Reseller';
        if(Trigger.old[0].LeadSource == 'ADPPartnerReferral'){
            newPart.Role = 'Referral Partner - Sourced';
        }
        insert newPart;
    }
       
 
      }         
 
    }
 
  }     
 
}

 

Here's my test class. I got as far as creating the elements that the trigger covers (Lead, Campaign, CampaignMember, the Campaign's Account) but i'm unclear as to how to 'test' the lead conversion part.

 

@isTest
private class testResellerLeadConvert {
    static testMethod void testConversion() {

    
        Lead L = new Lead(Company ='ABC Co', Email = '123@123.com', LastName = 'Freeman', LeadSource = 'ADPPartnerReferral', NumberOfEmployees = 100, Phone = '1234567', 
            Partner_Salesperson_Email_Address__c = '123@123.com',
            Partner_Salesperson_Contact_Details__c ='x',
            Opportunity_Pain_Compelling_Event__c = 'x',
            Opportunity_Timeline__c = 'x',
            Opportunity_Executive_Sponsor_s__c= 'x',
            IsConverted = TRUE);
        insert L;

        Account ResellerAcc = new Account(Name= 'BlackMesa');
        insert ResellerAcc;
        
        Campaign C = new Campaign(Name ='BMCampaign', Co_Sponsoring_Account__c = ResellerAcc.Id,
            Campaign_Vendor__c = 'ADP',
            Type = 'Referral Program (Opportunity Leads)',
            Topic__c = 'test topic',
            Campaign_Country__c = 'USA');
        insert C;
        
        CampaignMember CMember = new CampaignMember(LeadId = L.Id, Campaign = C, CampaignId = C.Id);
        insert CMember;
        
        
        Test.startTest();
        
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(L.Id);
        
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());

        Test.stopTest();
        
    
    
    
    
    
    }
}

 

Any help is greatly appreciated.

  • July 26, 2012
  • Like
  • 0

hey all,

 

Does anyone know if i can deploy classes to live SF without meeting the test class requirement?

 

If not, i need some help getting to 75% coverage on the following batch class:

 

 

global class countRefContacts implements Database.Batchable<sObject>{
	global final String gstrQuery = 'select ID, Number_of_Reference_Contacts__c from Account';
    global Database.QueryLocator start(Database.BatchableContext BC){
		return Database.getQueryLocator(gstrQuery);
    } 
    global void execute(Database.BatchableContext BC, List<sObject> scope){
 		List<Account> listAccount = new List<Account>();
      		for(SObject objSObject : scope){
				Account objAccount = (Account)objSObject;
				Integer intNumberOfRefs = [SELECT count()FROM Contact WHERE AccountID = :objAccount.ID and Email != null and Binary_Reference_Contact__c = 1];
			  	if (intNumberOfRefs <> objAccount.Number_of_Reference_Contacts__c){
			  		objAccount.Number_of_Reference_Contacts__c = intNumberOfRefs;
			  		listAccount.add(objAccount);
			  	}
		    }	         
       if (listAccount.size() > 0 ) {update listAccount;}
    }
    	global void finish(Database.BatchableContext BC){
    }

}

 

 

What i have so far:

 

public class testCountRefContacts{
	static testMethod void testCountRefContacts(){
		
	List<Account> accns = new List<Account>();
	List<Contact> cons = new List<Contact>();
	for (Integer i = 0; i<199; i++){
		Account a = new Account(name = 'test' + i, Id = 'id' + i);
		Contact c = new Contact(LastName = 'testcon', AccountId = 'id' + i);
		accns.add(a);
		cons.add(c);
	}
	
	insert accns;
	insert cons;
	
	Test.StartTest();
	countRefContacts count = new countRefContacts();

	ID batchprocessid = Database.executeBatch(count);
	
	Test.StopTest();
	
	for(Account a : accns){
		System.assertEquals(0, a.Number_of_Reference_Contacts__c);
	}
	}
}

 

help!

 

 

 

  • August 30, 2010
  • Like
  • 0

hey everyone,

 

I am trying to deploy an edited version of a class already scheduled in live salesforce.

 

I am getting the following errors:

errors

 

I have uploaded many small scheduling tasks and triggers into SF without test classes and they've gone through. However, this time i got a Deploy Error. Is there a work around without having to write a ton of test classes?

 

I have done extensive testing in the sandbox for my upload and it has been fine. The edits contained in NDA counter are really small for my the already up and running version in live SF.

 

any help is appreciated. 

  • August 23, 2010
  • Like
  • 0

Hey everyone,

 

The workhorse for my scheduled counter is giving me DML 101 issues. Anyone know how i can bulkify the following code?

 

 

global class countAgreements implements Database.Batchable<sObject>{
	global final String gstrQuery = 'select ID, Number_of_Agreements__c from Opportunity';
    global Database.QueryLocator start(Database.BatchableContext BC){
		return Database.getQueryLocator(gstrQuery);
    } 
	global void execute(Database.BatchableContext BC, List<sObject> scope){
		List<Opportunity> listOpp = new List<Opportunity>();
		for(SObject objSObject : scope){
			Opportunity objOpportunity = (Opportunity)objSObject;
			Integer intNumberOfAgreements = [SELECT count() FROM echosign_dev1__SIGN_Agreement__c WHERE OpportunityID = :objOpportunity.ID and Is_Type_NDA__c = 1];
			if (intNumberOfAgreements <> objOpportunity.Number_of_Agreements__c){
				objOpportunity.Number_of_Agreements__c = intNumberOfAgreements;
				listOpp.add(objOpportunity);
			}
		if (listOpp.size()>0) {update listOpp;}
		}
	}
	global void finish(Database.BatchableContext BC){
	}
}

 

 

 

any help is greatly appreciated.

  • August 12, 2010
  • Like
  • 0

Hey everyone,

 

This trigger query is killing me.

 

I am writing a trigger to sum up custom field Scores in Contact.

 

I want to display the sum in Account.

 

I want to query the database for all the Scores for each Contact in an Account.

 

I guess my fundamental understanding of apex code sucks, nothing i'm doing seems to even compile.

Here's my code:

 

 

trigger sumContactScore on Account (after insert, after update) {
	
	Set<Id> accIDs = new Set<Id>();
	for(Account a: Trigger.new){
		accIDs.add(a.Id);
	}
	
	for(Account a : Trigger.new){
		
		Double sum = 0;

		List<Contact> scoreList = new List<Contact>();

		scoreList = [SELECT LS_Implicit_Contact_Score__c FROM Contact WHERE Email != null and Contact.AccountId in :accIDs];
		
		for(Contact i : scoreList){
			sum += i.LS_Implicit_Contact_Score__c;
		}
		
		a.Sum_of_Implicit_Behavior_Scores__c = sum;	
	}

}

 

 

 

Help.

  • July 22, 2010
  • Like
  • 0

Hey everyone,

 

I need to count the number of Agreements in each Opp, then post that number in a custom field in Opportunity.

 

I was thinking i would use batch update counting for the task.

 

At the same time, I know that Agreements is an EchoSign component.. but i need to link it with Salesforce API in the Opportunity.

 

Does anyone have any ideas as to how i should approach this?

 

  • July 14, 2010
  • Like
  • 0

Hey guys,

 

I found this wonderful scheduled batch update code on the forums:

 

global class countContacts implements Database.Batchable<sObject>{
	global final String gstrQuery = 'select ID, Number_of_Contacts_w_Email__c from Account';
    global Database.QueryLocator start(Database.BatchableContext BC){
		return Database.getQueryLocator(gstrQuery);
    } 
    global void execute(Database.BatchableContext BC, List<sObject> scope){
 		List<Account> listAccount = new List<Account>();
      		for(SObject objSObject : scope){
				Account objAccount = (Account)objSObject;
      			Integer intNumberOfContacts = [SELECT count()FROM Contact WHERE AccountID = :objAccount.ID];   
				if (intNumberOfContacts <> objAccount.Number_of_Contacts_w_Email__c){
			    	objAccount.Number_of_Contacts_w_Email__c = intNumberOfContacts;
					listAccount.add(objAccount);
			  	 }
		       }	         
       if (listAccount.size() > 0 ) {update listAccount;}
    }
    	global void finish(Database.BatchableContext BC){
    }
}

 

 

 

The field Number_of_Contacts_w_Email__c counts all the contacts in an account. But as the variable name implies, i would like it to count only contacts with an email address. I know that count() can take in a fieldname, but the returned AggregateResult is not an integer?

 

Anyone have any tips on how i can count contacts only under certain conditions like email, or if its a reference contact?

 

Also: Does anyone know how this code would run with like 50k accounts?

 

Thanks!

 

edit: link to my code - http://community.salesforce.com/t5/Apex-Code-Development/Update-Contact-Count-for-Accounts/m-p/173038

  • June 24, 2010
  • Like
  • 0

Hey all,

 

I have a NullPointerException in my trigger. The purpose of the trigger is to use Snapshot to find its parent Opportunity's Owner Id, then apply this Id to Snapshot.

 

 

trigger Insert_RelatedOwnerID_as_SnapShotPipeForecast_by_Opp on SnapShot_Pipe_Forecast_by_Opp__c (before insert) {
		Map<Id, SnapShot_Pipe_Forecast_by_Opp__c> smap = new Map<Id, SnapShot_Pipe_Forecast_by_Opp__c>([select id, Opportunity_lookup__r.OwnerId from SnapShot_Pipe_Forecast_by_Opp__c where id in :Trigger.newMap.keySet()]);
         	
         	for(SnapShot_Pipe_Forecast_by_Opp__c s: Trigger.new){
              s.OwnerId = smap.get(s.Id).Opportunity_lookup__r.OwnerId;
			}
}

 

 

 

The exception is thrown on line 2, column 191. I'm sure it's an easy fix, but I can't see it.

 

Any help is appreciated.

  • June 16, 2010
  • Like
  • 0