• snakeroot
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 5
    Questions
  • 11
    Replies
I'm getting the following error intermittently when running a scheduled batch class:  Attempted to schedule too many concurrent batch jobs in this org (limit is 5). 

I found out why I'm gettting this error and the code to use to maneuver around this limitation in this KB article (https://help.salesforce.com/apex/HTViewSolution?id=000182449" target="_blank).  I'm able to test for the code in the if part of the if/else statement to get code coverage, but I can't figure out how to test the else part of the statement.  If anyone could help me out with this, I'd appreciate it.  Here's the code and the test coverage code: 

Schedulable Class: 
global void execute(SchedulableContext sc) {

	try{	
    	//check if there are 5 active batch jobs
		//In some cases, might need to add "Status='Queued' " to the criteria
		if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')] < 5){ 
	    	CatchOfTheDayBatch controller = new CatchOfTheDayBatch('SELECT Id,Name,Retention_Target_Name_LOST__c,Retention_Target_ID_LOST__c, Retention_Target_Email_Date_LOST__c,Authorization_Signature__r.Id FROM Account	WHERE RecordType.Name = \'RR Companies\' AND Retention_Target_ID_LOST__c != null ORDER BY Retention_Target_ID_LOST__c DESC');
			Integer batchSize = 10;
			database.executebatch(controller , batchSize);	
		} else {
			//schedule this same schedulable class again in 30 mins
			CatchOfTheDay scheduledClass = new CatchOfTheDay();
			Datetime dt = Datetime.now() + (0.024305); // i.e. 30 mins
   			String timeForScheduler = dt.format('s m H d M \'?\' yyyy');
   			Id schedId = System.Schedule('MatrixRetry'+timeForScheduler,timeForScheduler,scheduledCLass);	
		}
	}
	catch (System.EmailException e) { System.debug('An error has occurred: '+e); }
	} 	

}

Test Code: 
@isTest
                                
private class Test_CatchOfTheDay {


   public static String CRON_EXP = '0 0 0 15 3 ? 2022';

   static testmethod void test() {
      Test.startTest();


      String jobId = System.schedule('CatchOfTheDay',
                        CRON_EXP, 
                        new CatchOfTheDay());
         

      CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, 
         NextFireTime
         FROM CronTrigger WHERE id = :jobId];


      System.assertEquals(CRON_EXP, 
         ct.CronExpression);


      System.assertEquals(0, ct.TimesTriggered);


      System.assertEquals('2022-03-15 00:00:00', 
         String.valueOf(ct.NextFireTime));
      Test.stopTest();

   }
}



 

Disclaimer:  I'm a total newb at apex, so forgive my ignorance.  

 

 

What I'm trying to do: 

 

Check that an opportunity is marked paid if the opportunity represents an invoice

or

Check that an opportunity represents a credit memo

 

If either of the above are true, then I want to query the opportunity line items to see if there's an item key called RRR22.  If there is, I want to add a few pieces of information from that opportunity line item and the opportunity to a custom object (nicknamed the vault). 

 

So far, with the code below I can query the opportunities and determine my first two criteria (listed above) and find the ones that have RRR22 as an item key in the line items.  The problem is, in the for loop that looks through the opportunity line items, I seem to have access to all oli's except the one the trigger is firing on.  So if I have 3 invoices InvoiceA, B and I create C, the trigger fires because C is new.  I'm able to find the line item information from A & B, but not C. 

 

Can anyone shed some light on this for me?  

 

 

trigger RRR_Opportunity on Opportunity (after insert) {
// Check opportunities for line items that use the RRR22 item key


//Create set of opportunities to be checked.  
Set<Id> oppsToBeChecked = new Set<Id>();
       for (Opportunity o : Trigger.new){
         if(o.QB_Template__c !=''){       //Check that the opportunities is from QB before adding it to the set of opportunities to be checked.
           oppsToBeChecked.add(o.Id);
         }
       }
  

if(!oppsToBeChecked.isEmpty()){
	for(Opportunity o : [SELECT Id, Is_Paid__c, Invoice_Num__c, Credit_Memo_Num__c,AccountId,
			   (SELECT Id, PriceBookEntry.Product2.Name
                FROM OpportunityLineItems
                WHERE PriceBookEntry.Product2.Name = 'RRR22'
                ORDER BY PriceBookEntry.Product2.Name) // little trick to get the ones with RRR22 sorted first
            FROM Opportunity
            WHERE QB_Template__c != '' AND Id IN :oppsToBeChecked]){
    // ONLY insert entry into the Vault if opportunity is an invoice, has RRR22 item(s) and is paid OR
    // if the opportunity is a credit memo and has RRR22 item(s)        	
	if((o.Is_Paid__c == true && o.Invoice_Num__c !='') || (o.Credit_Memo_Num__c !='')){
		//insert line item into the Vault
		//system.debug('An entry would be submitted to the vault at this point.');
		
		for(OpportunityLineItem oli : [SELECT Id,PriceBookEntry.Product2.Id,Opportunity.AccountId,OpportunityId,Quantity
			FROM OpportunityLineItem
			WHERE OpportunityId IN :oppsToBeChecked]){
		system.Debug('oli.OpportunityId =' + oli.OpportunityId + ' / o.Id = ' + o.Id);
			
				
				RRR_Vault__c vaultEntry = new RRR_Vault__c();
				vaultEntry.Date__c = date.today();
				vaultEntry.Refrigerant_Type__c = String.valueOf(PriceBookEntry.Product2.Name);   //FIX ME
				vaultEntry.Account__c = o.AccountId;
				vaultEntry.Transaction_Type__c = 'Withdrawal';  // FIX ME
				vaultEntry.Salesforce_ID__c = o.Id;
		
					// Test to see if this is an invoice or credit memo
					if (o.Invoice_Num__c !='') {
						vaultEntry.Linked_To__c = o.Invoice_Num__c;
					}else{
						vaultEntry.Linked_To__c = o.Credit_Memo_Num__c;
						}
			
					vaultEntry.Refrigerant_Qty__c = oli.Quantity;
						
				insert vaultEntry;
				system.debug('Entry successfully entered into the Vault!');	
		
		}
	}

}

}

}

 

 

 

 

Can anyone help me out with this error?  System.NullPointerException: Attempt to de-reference a null object

 

I think what happened was I deployed an app to my sandbox.  The app requires some custom settings.  So I put in a value for getKey.  When I went to deploy, I deleted the custom setting since it wasn't setup before I deployed to my sandbox.  Now I'm getting the above error.  I'm not sure where to even begin to troubleshoot this.  Anyone have any ideas? 

 

 

I'm a newbie and I'm stumped.  

 

When I run Apex Test Runner in Eclipse, it shows Average test coverage across all Apex Classes and Triggers is 41%.  

   (I read on a different post that if you clear the test history in Eclipse and run again, it will correct.  That didn't work in my case.  It still says 41%)

 

When I run overall code coverage in my developer account of SFDC, it says I'm at 77%.  

 

When I try to deploy from Elipse to my production server, it says Average test coverage across all Apex Classes and Triggers is 71%. 

 

Which one is right?  How can I deploy my project to my production server??

We were setting up our new instance of Salesforce and were really excited to try out Find Nearby.  It's PERFECT for what we want to use it for.  However, after we had it setup and working well, all of a sudden (an update maybe?) the Do Not Map option doesn't work anymore.  Every time we try to mark a contact or account as Do Not Map and then hit save, the field value changes itself back to the default value for that picklist.  It will only let us choose Mailing or Other even Do Not Map is an option in the picklist.  Anyone else finding this to be true?  We've tried uninstalling and reinstalling, but it still doesn't work.  

I'm getting the following error intermittently when running a scheduled batch class:  Attempted to schedule too many concurrent batch jobs in this org (limit is 5). 

I found out why I'm gettting this error and the code to use to maneuver around this limitation in this KB article (https://help.salesforce.com/apex/HTViewSolution?id=000182449" target="_blank).  I'm able to test for the code in the if part of the if/else statement to get code coverage, but I can't figure out how to test the else part of the statement.  If anyone could help me out with this, I'd appreciate it.  Here's the code and the test coverage code: 

Schedulable Class: 
global void execute(SchedulableContext sc) {

	try{	
    	//check if there are 5 active batch jobs
		//In some cases, might need to add "Status='Queued' " to the criteria
		if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')] < 5){ 
	    	CatchOfTheDayBatch controller = new CatchOfTheDayBatch('SELECT Id,Name,Retention_Target_Name_LOST__c,Retention_Target_ID_LOST__c, Retention_Target_Email_Date_LOST__c,Authorization_Signature__r.Id FROM Account	WHERE RecordType.Name = \'RR Companies\' AND Retention_Target_ID_LOST__c != null ORDER BY Retention_Target_ID_LOST__c DESC');
			Integer batchSize = 10;
			database.executebatch(controller , batchSize);	
		} else {
			//schedule this same schedulable class again in 30 mins
			CatchOfTheDay scheduledClass = new CatchOfTheDay();
			Datetime dt = Datetime.now() + (0.024305); // i.e. 30 mins
   			String timeForScheduler = dt.format('s m H d M \'?\' yyyy');
   			Id schedId = System.Schedule('MatrixRetry'+timeForScheduler,timeForScheduler,scheduledCLass);	
		}
	}
	catch (System.EmailException e) { System.debug('An error has occurred: '+e); }
	} 	

}

Test Code: 
@isTest
                                
private class Test_CatchOfTheDay {


   public static String CRON_EXP = '0 0 0 15 3 ? 2022';

   static testmethod void test() {
      Test.startTest();


      String jobId = System.schedule('CatchOfTheDay',
                        CRON_EXP, 
                        new CatchOfTheDay());
         

      CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, 
         NextFireTime
         FROM CronTrigger WHERE id = :jobId];


      System.assertEquals(CRON_EXP, 
         ct.CronExpression);


      System.assertEquals(0, ct.TimesTriggered);


      System.assertEquals('2022-03-15 00:00:00', 
         String.valueOf(ct.NextFireTime));
      Test.stopTest();

   }
}



 
Hi There-

We are using Pardot for marketing automation and currrently the sync works from Pardot to Salesforce automatically and from Salesforce to Pardot with a button click that executes a java scrpit that pushes lead basic data to our Pardot instance

**
window.location = 'https://blablabla/email/{!Lead.Email}?lead_id={!Lead.Id}&sessionid={!$Api.Session_ID}&serverurl={!$Api.Partner_Server_URL_90}&redirect_location='+window.location
**
Im requesting for your help to translate this JS to apex which will work every time 1 or more leads are created in salesforce?
Please assist

Maor

Disclaimer:  I'm a total newb at apex, so forgive my ignorance.  

 

 

What I'm trying to do: 

 

Check that an opportunity is marked paid if the opportunity represents an invoice

or

Check that an opportunity represents a credit memo

 

If either of the above are true, then I want to query the opportunity line items to see if there's an item key called RRR22.  If there is, I want to add a few pieces of information from that opportunity line item and the opportunity to a custom object (nicknamed the vault). 

 

So far, with the code below I can query the opportunities and determine my first two criteria (listed above) and find the ones that have RRR22 as an item key in the line items.  The problem is, in the for loop that looks through the opportunity line items, I seem to have access to all oli's except the one the trigger is firing on.  So if I have 3 invoices InvoiceA, B and I create C, the trigger fires because C is new.  I'm able to find the line item information from A & B, but not C. 

 

Can anyone shed some light on this for me?  

 

 

trigger RRR_Opportunity on Opportunity (after insert) {
// Check opportunities for line items that use the RRR22 item key


//Create set of opportunities to be checked.  
Set<Id> oppsToBeChecked = new Set<Id>();
       for (Opportunity o : Trigger.new){
         if(o.QB_Template__c !=''){       //Check that the opportunities is from QB before adding it to the set of opportunities to be checked.
           oppsToBeChecked.add(o.Id);
         }
       }
  

if(!oppsToBeChecked.isEmpty()){
	for(Opportunity o : [SELECT Id, Is_Paid__c, Invoice_Num__c, Credit_Memo_Num__c,AccountId,
			   (SELECT Id, PriceBookEntry.Product2.Name
                FROM OpportunityLineItems
                WHERE PriceBookEntry.Product2.Name = 'RRR22'
                ORDER BY PriceBookEntry.Product2.Name) // little trick to get the ones with RRR22 sorted first
            FROM Opportunity
            WHERE QB_Template__c != '' AND Id IN :oppsToBeChecked]){
    // ONLY insert entry into the Vault if opportunity is an invoice, has RRR22 item(s) and is paid OR
    // if the opportunity is a credit memo and has RRR22 item(s)        	
	if((o.Is_Paid__c == true && o.Invoice_Num__c !='') || (o.Credit_Memo_Num__c !='')){
		//insert line item into the Vault
		//system.debug('An entry would be submitted to the vault at this point.');
		
		for(OpportunityLineItem oli : [SELECT Id,PriceBookEntry.Product2.Id,Opportunity.AccountId,OpportunityId,Quantity
			FROM OpportunityLineItem
			WHERE OpportunityId IN :oppsToBeChecked]){
		system.Debug('oli.OpportunityId =' + oli.OpportunityId + ' / o.Id = ' + o.Id);
			
				
				RRR_Vault__c vaultEntry = new RRR_Vault__c();
				vaultEntry.Date__c = date.today();
				vaultEntry.Refrigerant_Type__c = String.valueOf(PriceBookEntry.Product2.Name);   //FIX ME
				vaultEntry.Account__c = o.AccountId;
				vaultEntry.Transaction_Type__c = 'Withdrawal';  // FIX ME
				vaultEntry.Salesforce_ID__c = o.Id;
		
					// Test to see if this is an invoice or credit memo
					if (o.Invoice_Num__c !='') {
						vaultEntry.Linked_To__c = o.Invoice_Num__c;
					}else{
						vaultEntry.Linked_To__c = o.Credit_Memo_Num__c;
						}
			
					vaultEntry.Refrigerant_Qty__c = oli.Quantity;
						
				insert vaultEntry;
				system.debug('Entry successfully entered into the Vault!');	
		
		}
	}

}

}

}

 

 

 

 

Can anyone help me out with this error?  System.NullPointerException: Attempt to de-reference a null object

 

I think what happened was I deployed an app to my sandbox.  The app requires some custom settings.  So I put in a value for getKey.  When I went to deploy, I deleted the custom setting since it wasn't setup before I deployed to my sandbox.  Now I'm getting the above error.  I'm not sure where to even begin to troubleshoot this.  Anyone have any ideas? 

 

 

I'm a newbie and I'm stumped.  

 

When I run Apex Test Runner in Eclipse, it shows Average test coverage across all Apex Classes and Triggers is 41%.  

   (I read on a different post that if you clear the test history in Eclipse and run again, it will correct.  That didn't work in my case.  It still says 41%)

 

When I run overall code coverage in my developer account of SFDC, it says I'm at 77%.  

 

When I try to deploy from Elipse to my production server, it says Average test coverage across all Apex Classes and Triggers is 71%. 

 

Which one is right?  How can I deploy my project to my production server??

Any ideas what this error could mean?

 

Problem: testfindnearbymap.tGetSets();
testfindnearbymap.tlocations()

 

Component: Apex Classes(01p30000000ahky)

 

Detail: System.QueryException: List has no rows for assignment to SObject
(FN)
External entry point;
System.QueryException: List has no rows for assignment to SObject
(FN)
External entry point

A user writes: "If I already have latitude/longitude coordinates, can I avoid the Geocoding process in the application?  Is there a way I can pull in the lat/long data I already have (sits in Salesforce) to map all my locations?"

 

Good question!  If you have Long Lat, no need to geocode.  If you have that data someplace else, you can either modify the code to refer to this other location or dataload it to the fields that Find Nearby expects.

  • June 16, 2011
  • Like
  • 0
I have a custom formula field in contacts that is a hyperlink that opens a new event with information about the contact in the description (long story as to why we're doing this - trust me that this is the way to go...).
 
So, all goes well - I've substitituted spaces for + so that the hyperlink will work. My issue comes when I try to use mailing address. My only choice is mailing address and not mailing address 1, mailing address 2, mailing address 3. When there's a carriage return in the mailing address, the hyperlink doesn't get formed properly. So, the answer is to replace the carriage return with %0D. But, how do I specify the carriage return in the URL? I've tried CHAR(10), CHR(10), TEXT(10), BR() to no avail. I've tried calling Salesforce support but I'm told this area is not supported and I should talk to my developer??? (Side note: I love how salesforce keeps using these features as selling points and then refuses to support them when you run into issues).
 
So, does anyone know what I would use here? Here's what the code looks like ("NEED CARRIAGE RETURN HERE" is where I need the carriage return code:
Code:
HYPERLINK("https://na5.salesforce.com/00U/e—&who_id="&Id&"&followup=1&evt5=Meeting&what_id="&AccountId&"&returl=%2F"&Id&"&evt6="&SUBSTITUTE(FirstName," ","+")&"+"&SUBSTITUTE(LastName," ","+")&"%0D"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Phone, "(",""),")","")," ","+")&"%0D"&SUBSTITUTE(SUBSTITUTE(MailingStreet," ","+"),NEED CARRIAGE RETURN CODE HERE,"%0A"), "Book a Meeting")


Message Edited by ghallettkp on 04-01-2008 12:17 PM
Is there a tutorial that explains the variouls parameters that can be passed in a URL?
Hi There-

We are using Pardot for marketing automation and currrently the sync works from Pardot to Salesforce automatically and from Salesforce to Pardot with a button click that executes a java scrpit that pushes lead basic data to our Pardot instance

**
window.location = 'https://blablabla/email/{!Lead.Email}?lead_id={!Lead.Id}&sessionid={!$Api.Session_ID}&serverurl={!$Api.Partner_Server_URL_90}&redirect_location='+window.location
**
Im requesting for your help to translate this JS to apex which will work every time 1 or more leads are created in salesforce?
Please assist

Maor