• MJ09
  • NEWBIE
  • 220 Points
  • Member since 2008

  • Chatter
    Feed
  • 7
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 55
    Questions
  • 129
    Replies

The Apex Language Reference says the "Total number of classes that can be scheduled concurrently" is 25. 

 

The wording is a little difficult to parse. Which of the following (if any) does this mean?

 

  • I can have at most 25 Schedulable Apex jobs scheduled, even if they're scheduled to run at a wide variety of times that don't overlap
  • I can have at most 25 Schedulable Apex jobs actually running at any one point in time, 

Thanks!

 

Hi,

 

I am inserting rates on daily basis. For this, I have scheduled apex class using following code:

 

scheduledGenerateRates m = new scheduledGenerateRates(); 
cronId = system.schedule('Update Rate Schedule', '0 0 * * 1-12 ? *', m);

 Afterthat, if some error occured while inserting records, I want to delete existing scheduled job. ISo, i have used abortjob function to do this:

 

List<CronTrigger> cron = [SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :scheduledJobId];
for(CronTrigger CT:cron)
{ 
   try
   {
       System.abortjob(CT.id); 
   }catch(Exception e1)
   {
       System.debug('--- Unable to delete scheduled job with Scheduled_Geocoder_Job_Id = ' + CT.id + ' because ' + e1.getMessage());
    }
}

 And in the debug log, i am getting:

Aggregations:0|SELECT id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :scheduledJobId
07:00:03.778 (2778266000)|SOQL_EXECUTE_END|[170]|Rows:1
07:00:03.778 (2778504000)|SYSTEM_METHOD_ENTRY|[175]|System.abortJob(String)

 But, still in the list of Setup - > Monitoring ->Scheduled Jobs, I am able to see that job.

 

Please suggest me some solution to delete scheduled job from here.

 

Thanks.

I have a managed package that defines an object whose Name is an Auto Number field. A customer who has the managed package wants to import some data from another org into his current org, and maintain the Auto Number values that he had in his original org, instead of having new Auto Number values assigned. 

 

I know you can ask Salesforce to allow you to use the Data Loader to write to the CreatedDate and LastModifiedDate fields. Will they also allow us to write to an Auto Number field?

 

(Before you suggest I temporarily change the field type to Text,l please note that the field is defined in a managed package, so I can't change its field type.)

Ok all here is one that I am running into Trouble with. I have a Trigger that is Before insert, before update.

It is validating the address via the postalcodes as well as ensuing a proper grouping for reporting using the County and State returned from the Zip look up.
It works great however I need to Accommodate for passing 2300+ accounts at one time.
Any one do a Bulk/Batch processing before insert, before update? I keep getting a recursive issue.


Hi All,

 

I'm new here, so hopefully I don't say anything too silly/dumb.

 

I am having a problem with testing an undelete trigger I have written.  I am getting an DMLException for de-referenfing a null object when trying to test my undelete trigger.  It may be that I am misunderstanding completely how testing of Apex undeletes should work... 

 

My basic requirements are that I have an order, and I have a field on that order called Needs Attn.  I need to set this field to True whenever the order is updated or when it is undeleted.  

 

My Trigger in JGOrderUpdate.trigger:

 

trigger JGOrderUpdate on JG__Order__c (before update, after undelete) {
	    for(JG__Order__c o : Trigger.new) {
		    JG__Order__c old = Trigger.oldMap.get(o.Id);
		    if(!old.Needs_Attn__c) o.Needs_Attn__c = true;
		}
	}

 

My Test Code JGTriggerTests.cls :

 

    // create a order
    JG__Order__c o = new JG__Order__c();
    o.Needs_Attn__c = false;
    insert o;

    // this kicks off the before update trigger for orders
    update o;

     // Confirms Actual update tests for orders
     JG__Order__c test_o = [Select Id, Needs_Attn__c From JG__Order__c Where Id =: o.Id];
     System.assert(test_o.Needs_Attn__c);

     // now we set the order back to needing attention false
     o.Needs_Attn__c = false;
	
     // now we delete the order so we can undelete it to make sure when we undelete it actually
     // changes to Needs_Attn__c == True
     delete o;
	
     // this kicks off the undelete trigger code
     // HAVING THE PROBLEM ON THE LINE BELOW
     undelete o;

     // did the trigger run properly
     System.assert(test_so.Needs_Attn__c);

 

 

Here's the error i get on the line above with "undelete o;"

 

 

Description Resource Path Location Type
 System.DmlException: Undelete failed. 
 first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete
 caused by: System.NullPointerException: Attempt to de-reference a null object
 Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls
 Description Resource Path Location TypeSystem.DmlException: Undelete failed.  
 first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete
 caused by: System.NullPointerException: Attempt to de-reference a null object
 Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls

Description Resource Path Location Type System.DmlException: Undelete failed.  first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls Description Resource Path Location TypeSystem.DmlException: Undelete failed.   first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, JGOrderUpdate: execution of AfterUndelete caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.JGOrderUpdate: line 3, column 38: [] JGTriggerTests.cls

 

 

 

Any help would be greatly appreciated!

 

Thanks
j

I’m the developer of a package that has a heavy dependence on a scheduled Batch Apex job. The package currently runs in a dozen or so orgs, some of which have fairly large amounts of data. One org in particular has over 3 million records that are processed by the Batch Apex job.

 

Over the past 3 months, we’ve been encountering a lot of stability problems with Batch Apex.  We’ve opened cases for several of these issues, and they’ve been escalated to Tier 3 Support, but it consistently takes 2 weeks or more to get a case escalated, and then it can several more weeks to get a meaningful reply form Tier 3.

 

We really need to talk with the Product Manager responsible for Batch Apex. We asked Tier 3 to make that introduction, but they said they couldn’t. We’re trying to work with Sales to set up a discussion with a Product Manager, but so far, we haven’t had any luck there either. We’re hoping that a Product Manager might see this post and get in touch with us. We need to find out whether Batch Apex is a reliable-enough platform for our application.

 

Here are a few examples of the problems we’ve been having:

 

  • The batch job aborts in the start() method. Tier 3 Support told us that the batch job was occasionally timing out because its initial  query was too complex. We simplified the query (at this point, there are no WHERE or ORDER BY clauses), but we occasionally see timeouts or near timeouts. However, from what we can observe in the Debug Logs, actually executing the query (creating the QueryLocator) takes only a few seconds, but then it can take many minutes for the rest of the start() method to complete. This seems inconsistent with the “query is too complex” timeout scenario that Tier 3 support described.  (Case 04274732.)
  • We get the “Unable to write to ACS Stores” problem. We first saw this error last Fall, and once it was eventually fixed, Support assured us that the situation would be monitored so it couldn’t happen again. Then we saw it happen in January, and once it was eventually fixed, Support assured us (again) that the situation would be monitored so it couldn’t happen again. However, having seen this problem twice, we have no confidence that it won’t arise again. (Case 04788905.)
  • In one run of our job, we got errors that seemed to imply that the execute() method was being called multiple times concurrently. Is that possible? If so, (a) the documentation should say so, and (b) it seems odd that after over 6 months of running this batch job in a dozen different orgs, it suddenly became a problem.

 

  • We just got an error saying, “First error: SQLException [java.sql.SQLException: ORA-00028: your session has been killed. SQLException while executing plsql statement: {?=call cApiCursor.mark_used_auto(?)}(01g3000000HZSMW)] thrown but connection was canceled.” We aborted the job and ran it again, and the error didn’t happen again.
  • We recently got an error saying, “Unable to access query cursor data; too many cursors are in use.” We got the error at a time when the only process running on behalf of that user was the Batch Apex process itself. (Perhaps this is symptomatic of the “concurrent execution” issue, but if the platform is calling our execute() method multiple times at once, shouldn’t it manage cursor usage better?)
  • We have a second Batch Apex job that uses an Iterable rather than a QueryLocator. When Spring 11 was released, that Batch Apex job suddenly began to run without calling the execute() method even once. Apparently, some support for the way we were creating the Iterable changed, and even though we didn’t change the API version of our Apex class, that change caused our Batch Apex job to stop working. (Case 04788905.)
  • We just got a new error, "All attempts to execute message failed, message was put on dead message queue."

 

We really need to talk with a Product Manager responsible for Batch Apex. We need to determine whether Batch Apex is sufficiently stable and reliable for our needs. If not, we’ll have to find a more reliable platform, re-implement our package, and move our dozen or more customers off of Salesforce altogether.

 

If you’re responsible for Batch Apex or you know who is, please send me a private message so we can make contact. Thank you!

 

I know that I can find the number of API requests over the last 24 hours in the UI via Setup | Company Profile | Company Information. However, that doesn't quite give me everything I need:

 

  • Is there any way to monitor the API Call Count programmatically through Apex? For example, can I schedule a process to run every hour, in which some Apex code checks the count, compares it to the organization's 24-hour limit, and emails me if I'm at a certain percentage of the limit?

 

  • Once the 24-hour limit has been reached, is there any way to count the number of API calls that are attempted and rejected?

 

I know that I can get a report of the API call counts over the last 7 days via Reports | Administrative Reports | API Usage Last 7 Days. However, this report only summarizes the API call count per day. Is there any way to get a report at a finer level of granularity, like per hour?

If I issue a SOQL query that includes aggregate functions, I get back a list of AggregateResult objects. From each of those, I can use ar.get('fieldname') to get the various values. But that assumes I know the names of the field. If I do a Dynamic SOQL query from a VF page controller, where the query is based on input from the user, I may not know the field names ahead of time. How can I determine the fieldnames to use when I want to access the contents of an AggregateResult object?

 

Having read that an AggregateResult is a special type of SObject, I tried using Dynamic Apex to discover the fields:

 

List<AggregateResult> lst = database.query('select count(id), grp__c from myobj__c group by grp__c');

Schema.SObjectType sot = lst.getSObjectType();
Schema.DescribeSObjectResult res = sot.getDescribe();
Set<String> setFields = res.fields.getMap().keyset();
System.debug('Fields are: ' + setFields);

But the only field I get back is "id."  

 

Thanks for your help!

Hi,

 

I am implementing a trigger in Accounts. If some conditions becomes true then I need to display an alert message to the user.

 

I searched in the discussion boards?? But I didnt find anything reg this.

 

Is there any way to achieve this?

 

If so then pls give some examples..

 

Thanks,

I'm working with a standard object that's used by a managed package. The managed package includes some software that runs on the package author's own server and that calls into Salesforce using the web services API, to create records for that standard object. Other Salesforce apps also create records for that standard object. I need to write a trigger that can detect if a record is being added by the managed package's code (i.e., as a result of an API call) or by some other means.

 

I have no control over the way the external server calls into Salesforce to create records for this object. I can't modify that software.

 

I have no control over the UI. Because it's a standard object, many apps can create records for it. I can't change all of those apps to make them set some kind of flag that says "I'm not creating this record through the API."

 

Given those limitations, is there any way a trigger can determine whether it's being called as a result of an API call?

 

I've tried various UserInfo methods, without much luck. I thought if I called UserInfo.getUiThemeDisplayed() from a trigger invoked as a result of an API call, it might tell me that there's no UI Theme being displayed, but it doesn't.  

UserInfo.getUserId() doesn't help me because the external server logs into Salesforce using the same login credentials that a browser user would.

  

Is there anything in UserInfo.getSessionId() that might be useful? 

 

Thanks for your help!

I have a VF page that I'm embedding in a standard page layout. I'd like to pass a parameter into the VF page. The VF page's controller will look at the parameter and the current record, then decide what to display on the embedded page.

 

I have the VF page and controller written. But how can I get the standard page layout editor to pass a parameter in to the VF page? Is that even possible? If not, do you have any other suggestions?

 

Thanks!

I'd like to develop a batch file that can export data using the Data Loader command line. I'm starting with a simple process-conf.xml file:

 

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="account"
class="com.salesforce.lexiloader.process.ProcessRunner"
singleton="false">
<description></description>
<property name="name" value="csvAccount"/>
<property name="configOverrideMap">
<map>
<entry key="sfdc.endpoint" value="https://www.salesforce.com"/>
<entry key="sfdc.username" value="my_user_name"/>
<entry key="sfdc.password" value="my_80-char_password_string"/>

<entry key="sfdc.debugMessages" value="false"/>
<entry key="sfdc.debugMessagesFile" value="C:\Export.log" />
<entry key="sfdc.timeoutSecs" value="120"/>
<entry key="sfdc.loadBatchSize" value="200"/>

<entry key="process.operation" value="extract"/>
<entry key="dataAccess.type" value="csvWrite" />
<entry key="dataAccess.writeBatchSize" value="1" />
<entry key="sfdc.extractionRequestSize" value="1" />
<entry key="process.enableExtractSuccessOutput" value="true" />

<entry key="process.outputError" value="C:\ERRORaccount.csv" />

<entry key="dataAccess.name" value="C:\account.csv" />
<entry key="sfdc.entity" value="account"/>
<entry key="sfdc.extractionSOQL" value="select id, phone from account" />
</map>
</property>
</bean>
</beans>

 

When I run this from the command line, I get a bunch of DEBUG and INFO output, followed by:

 

2704 [account] INFO com.salesforce.lexiloader.dao.DataAccessObjectFactory - Instantiating data access object: C:\account.csv of type: csvWrite
2704 [account] INFO com.salesforce.lexiloader.process.ProcessRunner - Checkingthe data access object connection
2704 [account] INFO com.salesforce.lexiloader.process.ProcessRunner - Setting field types
3500 [account] INFO com.salesforce.lexiloader.process.ProcessRunner - Setting object reference types
Exception in thread "main" java.lang.NullPointerException
at com.salesforce.lexiloader.client.PartnerClient.setFieldReferenceDescribes(PartnerClient.java:462)
at com.salesforce.lexiloader.controller.Controller.setReferenceDescribes(Controller.java:140)
at com.salesforce.lexiloader.process.ProcessRunner.run(ProcessRunner.java:129)
at com.salesforce.lexiloader.process.ProcessRunner.main(ProcessRunner.java:228)

 

 It's logging in (if I change the username, I get a different error), and it creates the account.csv file, but it's empty.

 

If I change the sfdc.entity property to "xxx," I get an error indicating that no such SObject exists.

 

If I change the sfdc.extractionSOQL property to select from "xxx" instead of from "account," I get the same null pointer exception.

 

I'm logging in as a System Administrator, so I doubt there's a permission problem.

 

Any ideas?

 

Thanks,

 

MJ.

 

 

 

I'm in the process of packaging some code that includes callouts to Google Maps for geocoding. The code works just fine in my development org, but since the package could be installed on any Salesforce instance, I can't always use a Google Maps API key that's based on my development org's instance. Fortunately, in Google Map in Visualforce Page, I found that I can use a key based on this URL:  http://force.com

 

This seems to work, except now I get G_GEO_TOO_MANY_QUERIES.

 

Is Google's "too many queries" limit based on all requests coming from http://force.com? That would make sense from Google's perspective, but from the perspective of a single org on a single Salesforce instance, it doesn't seem fair that every other instance's org's requests should count against my limit?

 

Is there any way to create a Google Maps API key that's specific to my own org (or an org my package is installed in), so that only requests made from my org count against my limit.

 

For reference, see my post from late 2008: http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=10535

 

Thanks--

I'd like to override the standard Save button for Account objects. I know I can't do that directly, so I thought I'd override the Account Edit page, going to a Visualforce page instead, and then override the standard save action in a controller extension.

 

So I created a new VF page that looks like this:

 

 

<apex:page standardController="Account" extensions="AccountEditController">
<apex:detail subject="{!id}" relatedList="true"/>
</apex:page>

Then I overrode the Account Edit button to go to this page.

 

My first problem is that this page displays in view mode, not edit mode. If I click the Edit button, it (of course) just loads the same page again. How do I get the <apex:detail> component to display in edit mode?

 

My second problem is overriding the standard Save action. I think I can do it with the following in my controller extension:


public class AccountEditController {
private final Account acct;
private ApexPages.StandardController stdController;

public AccountEditController(ApexPages.StandardController stdController) {
this.acct = (Account)stdController.getRecord();
this.stdController = stdController;
}

public PageReference save() {
// Put my own stuff here

// Do the standard save action
return this.stdController.save();
}
}

 

Is that correct?

 

Thanks!

 

MJ.

 

 

 

 

 

 

 

I'd like to add an onChange event handler to the standard Contact page layout, so that when the user changes the Contact's first or last name, some JavaScript code checks to see whether there's already a Contact with that name. I'd like this code to fire when the user changes the Contact's name, and not wait until the user clicks Save.

 

I've read this, so I know how to create an S-control that includes HTML input tags for the Contact's first and last names, and I know how to add the onChange event handler for them. What I don't know is how to get the values of those fields saved as the Contact's first and last names when the user clicks Save.

 

If this can't be done in the standard page, I can write a VisualForce page. But if I go that route, can I use the <apex:detail> tag or do I have re-create the standard page layout manually, using individual inputField tags?

 

Thanks!

 

Hi,
 

We have created a time based workflow (to trigger say 2 days before scheduled date, a custom datetime field). After activating this workflow,  we are not able to convert leads to accounts and the system throws the following error message in the convert lead page:

Error: Unable to convert lead that is in use by workflow"

Is there a way to fix this issue as we need to convert the leads even if the workflow has not been triggerd for a particular lead.

Appreciate all your response.

Thanks