• ErikOSnet0
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 17
    Replies
Is there an online HTML reference for Apex code? The Force.com Developer Guide is incomplete (cannot find documentation on String.split), is quickly dated, and cumbersome to use. We need an HTML reference that is always up-to-date and by reference I mean complete documentation on the language comparable to Java API specification (http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/api/index.html).

Can someone please share tips on the best way to target multiple production instances for development where one has multi-currency enabled, and another does not. 

 

They share a lot of code, so I have thus far kept them together, but only deploy shared classes to both.  Some classes are instance specific.   These classes tend to extend the shared classes. 

 

I'm just concerned about potential unintended consequences of continuing to target both instances where they don't both have multi-currency enabled, particularly if I begin to write re-usable code to support creating data in a specific currency.  I could use two development instances, but don't know if that is realistic or benefical due to the need to share most of the code.  

 

 

I need to split a string using the backslash as a delimeter. Here is the code:

 

 

public String removePath(String filename) { if (filename == null) return null; List<String> parts = filename.split('\\'); filename = parts[parts.size()-1]; return filename; } static testMethod void testRemovePath() { System.assertEquals('PPDSF100111.csv', EmailUtilities.getInstance().removePath('e:\\processed\\PPDSF100111.csv')); }

 

 

 

When you run the unit test, it errors on the line with split saying "System.StringException: Invalid regex: Unexpected internal error near index 1...".

 

If I try to use one or three backslashes, it returns a compile error: "Save error:  Line breaks not allowed in literal strings."

 

The force.com documentation for String.split references the Java 5 documentation for regular expression.  You are supposed to use two backslashes to effectively escape it to a literal backslash. Is this a bug?  What is the workaround if it is?

 

Erik

 

 

Does Apex support reflection

 

I have a class that does a lot of parsing and, based on the results, invokes different classes that support an interface.  Of course, in order to instantiate the class, it has to create a compile time dependency on the class, which also can create a dependency on custom objects and fields.  

 

Now that I want to reuse and extend this for another project that will be deployed to a different SFDC instance, all these dependencies become an issue, because those custom fields and objects are not in the other SFDC instance.  

 

On top of this, I want it to all become completely configurable with the parsing and invoking to be part of a re-usable framework.  I want to declare which classes to instantiate based on the data being parsed to be configurable (runtime configurable object factory).  

 

This is a common use case for reflection.  Can I do this in SFDC?  Or, are we doomed to not be able to use reusable configurable code?

 

How is everyone purging custom object data? 

 

Please correct me if I'm wrong about these assumptions:

  1. There are no Admin features for mass deleting custom object data.
  2. There isn't a check many items and hit one delete button kind of option for users.
  3. In Apex coding, you have to query records before you can delete them either with delete xyz or Database.Delete.  In other words, you have to do query first instead of executing a DELETE FROM xyz. 
  4. Your unit tests can only query a total of 500 rows from custom objects (seems higher on Account, but still not high enough for a large company with over 5000 customers.)  

Please correct or affirm any assumption, or provide info helping me understand our options.  Right now, I don't understand how you can realistically mass delete custom object data. 

 

A common pattern in Java is to declare an enum, and then use Set to declare subsets of the enum.  The subsets can then be used to validate that they contain a value passed as the enum type.  

 

For instance:

 

 

  public enum Command {INSERTNEW, DELETEOTHERS, CREATERANDOMCONTACTS}

 

// Define commands that only require the AccountNumber to operate
public static Set<MyClass.Command> accountNumberOnlyCommands;

static {
accountNumberOnlyCommands.add(Command.DELETEOTHERS);
accountNumberOnlyCommands.add(Command.CREATERANDOMCONTACTS);
}

 

 

 

would allow you to then do:

 

 

public MyClass(Command thisCommand) {
if (accountNumberOnlyCommands.contains( thisCommand ) )

...

 

 

But, when you try to declare your Set<enum type>, it creates a build error of "Set of <enum type> not allowed".  Why would it not allow this?  After all, an enum, besides being a type declaration, is conceptual a set of unique values. It is only logical to be able to use Set to declare subsets and then the contains method to verify that a value is a member of the subset.  And, like I said, you can do this in Java. 

 

If you change Set to List in the declaration, it allows it, so you can create lists of an enum type.  But, List doesn't have the contains method, so it then errors on the if statement above.  

 

Does anyone know how to resolve this?  

 

Message Edited by ErikOSnet0 on 12-01-2009 10:35 AM

In Eclipse, I right click on a Force.com project and select Force.com's Deploy to Server... option.  It pops up an exception saying "Unable to deploy - no deployable resources found."

 

How do you resolve this? 

 

I have an input field that is appearing too small, making it hard for the user to read its contents (text up to 100 characters). 

 

I'd like to have it span the width of the form, but no matter what, it still only appears in column 1 of 2.  Here is what I tried to no avail:

 

<apex:pageBlockSection title="Email Contents" columns="1"> <apex:inputField value="{!notification.EmailTemplateName__c}"/> </apex:pageBlockSection>

 

You would have thought that columns="1" would have done it.  

 

How do I get this field (including the label) to span the width of the page block section or form instead of leaving the right half blank?  

 

 

SalesForce.com looked like it had some redeemability with regard to the scalability issues created by some of its Governor limits when I learned about the @future annotation, until I read the details.  I have a few questions:

 

1> If I make multiple invocations of a @future method within an Apex request, does each invocation have its own set of governor limits, or do they apply to all the invocations as a sum?  These future invocations are limited to 10 per Apex invocation. 

 

2> "No more than 200 method calls per Salesforce.com license per 24 hours"...  if I understand it correctly, if we have 400 licensed users of SalesForce.com, then this permits 80,000 invocations per 24 hours?  Is this a trailing 24 hours, or a midnight to midnight thing?

 

3> OK, this is where I really struggle with the limits of future:  "The parameters specified must be primitive dataypes, arrays of primitive datatypes, or collections of primitive datatypes" and "Methods with the future

annotation cannot take sObjects or objects as arguments".  This issue here is that the set of data that you want to act on can change given the same where clause.  For instance, if we notify 1600 contacts, I'd like to use a @future to create 1600 entries of this activity.  But, if I have to requery based on the filter for notification, then this could be 1640 contacts by the time this runs, creating a data integrity issue.  On the other hand, if I could pass the SObject that was created anyway containing the contacts, then the data integrity would be intact.  How are other people handling this?

 

 

 

I understand the purpose of the governor limits.  I understand some of the limits themselves, such as heap size.  I do not understand many of them.  One I do not understand is a limit of 1000 for a List. It appears to be an indirect memory limit, which is a duplicate effort since there is already a heap limit, and counterintuitive since one element can be as small as an Integer or as large as a complex blob containing object. 

 

THE QUESTION:  If I need to insert 1600 rows, does this actually mean I have to create two lists, one with 1000 and another with 600 rows, which I then have to execute as two inserts?  Am I understanding this correctly?!?

 

I have a process that sends emails to the Contacts of a set of Accounts (customer notification).  To do this, I create the message for each Account, as it is customized for the Account.  Because of the governer limit of 10 on invoking email send, I accumulate these in an array, then send at once. 

 

Unfortunately, if any of the emails are on a bounce list, then it fails to send any of them.  At any given time you are likely to one or more customer emails bounce, so this is very impractical.  Moreover, although I notify the requester of the exception, it does not include the email address that bounced, so is hard for an end-user to remedy:

 

First exception on row 1; first error: INVALID_EMAIL_ADDRESS, email address has bounced for id : 0037000000RqE7e: []

 

Even if I parse and discover the email address of the contact, there are reasons why an end-user cannot necessarily correct the situation, such as the customer's email server is temporarily unavailable.  

 

How does this conflict with the governer guidelines?  If there wasn't a limit of 10 send requests per HTTP request, I'd send each email individually, permitting all the others to successfully be sent despite the failure.  

 

I have a process that notifies the Contacts of Accounts that match a query.  I created the ability to run in test mode where it scrubs the email address before sending, adding it to the toAddresses.  That works.  But, this needs to use a template. 

 

The template requires a targetObjectId.  Unfortunately, this uses the real email address of the Contact rather than the scrubbed one. Does anyone know of a way to use a supplied email address rather than the email of the Contact record without changing the underlying value in the database?  

 

 

Does anyone know how to parse a String in a predefined format to a Date? Specifically, I'm trying to convert '1-Apr' to a date.  

 

As a Java developer, I can't believe how much time I am spending reinventing the wheel. Why is there no DateFormat, or SimpleDateFormat class? Why on earth didn't they just use Java like Google Apps does?

 

I can currently able to convert the day and year in Apex, ableit with tedious code.  I tried to convert the month from Apr to 4 using an enum (ordinal() returns position), but there doesn't seem to be a way to convert a String to its Enum counterpart like I can do in Java. In fact, ordinal() doesn't even seem to be compiler friendly, despite being documented (perhaps it is new to Apex 17.)

 

Here is what I have so far, with month obviously hard coded:

 

    /**
     * Dates are in the format of d-Mon in the CSV file.  E.g., "1-May" is the first
     * of may.  The year should put it in the future.  Thus, if it is "1-Jan" and it
     * is currently December of 1009, then the year should be 2010. 
     **/
    public Date convertEffectiveDate(String inDate) {
           String[] dateParts = inDate.split('-');
           Integer day = Integer.valueOf(dateParts[0]);
          
           Integer month = 4;
           Date effective = Date.newInstance(Date.today().year(), month, day);
          
           if (effective < Date.today())
               effective.addYears(1);
              
           return effective;
    }

 

 

Hi,

 

From New Spring '10 Apex Dev Guide: 

"Single email messages sent with the sendEmail method count against the sending organization's daily single email limit. When this limit is reached, calls to the sendEmail method using SingleEmailMessage are rejected, and the user receives a SINGLE_EMAIL_LIMIT_EXCEEDED error code. However, single emails sent through the application are allowed."

 

 

  1. If I select a User as the setTargetObjectId does it still count against these limits?
  2. What is the actual daily max # of single emails by org type?

 

Thanks in advance for you help,

Mike 

Is there any way to add an error to an record being updated in a trigger and send an email. The trigger needs to send an email (one per batch). The email works fine if the processing generates no errors and I do not use the addError method. If I use the addError method to pass a message back to the user then the email is not sent.

 

So is there a way to send an email and use addError in the same trigger code? If not is there another mechanism that can be used to pass a message back to the user interface (standard salesforce UI).

 

Thanks

 

Dave

  • December 08, 2009
  • Like
  • 0

Does Apex support reflection

 

I have a class that does a lot of parsing and, based on the results, invokes different classes that support an interface.  Of course, in order to instantiate the class, it has to create a compile time dependency on the class, which also can create a dependency on custom objects and fields.  

 

Now that I want to reuse and extend this for another project that will be deployed to a different SFDC instance, all these dependencies become an issue, because those custom fields and objects are not in the other SFDC instance.  

 

On top of this, I want it to all become completely configurable with the parsing and invoking to be part of a re-usable framework.  I want to declare which classes to instantiate based on the data being parsed to be configurable (runtime configurable object factory).  

 

This is a common use case for reflection.  Can I do this in SFDC?  Or, are we doomed to not be able to use reusable configurable code?

 

In Eclipse, I right click on a Force.com project and select Force.com's Deploy to Server... option.  It pops up an exception saying "Unable to deploy - no deployable resources found."

 

How do you resolve this? 

 

I have an input field that is appearing too small, making it hard for the user to read its contents (text up to 100 characters). 

 

I'd like to have it span the width of the form, but no matter what, it still only appears in column 1 of 2.  Here is what I tried to no avail:

 

<apex:pageBlockSection title="Email Contents" columns="1"> <apex:inputField value="{!notification.EmailTemplateName__c}"/> </apex:pageBlockSection>

 

You would have thought that columns="1" would have done it.  

 

How do I get this field (including the label) to span the width of the page block section or form instead of leaving the right half blank?  

 

 

Currently the finish() method is not called if the query returns no records. I think this is wrong. I think finish() should always be called regardless whether the query returns any records or not. What do you think?

I understand the purpose of the governor limits.  I understand some of the limits themselves, such as heap size.  I do not understand many of them.  One I do not understand is a limit of 1000 for a List. It appears to be an indirect memory limit, which is a duplicate effort since there is already a heap limit, and counterintuitive since one element can be as small as an Integer or as large as a complex blob containing object. 

 

THE QUESTION:  If I need to insert 1600 rows, does this actually mean I have to create two lists, one with 1000 and another with 600 rows, which I then have to execute as two inserts?  Am I understanding this correctly?!?

 

Can we assume anything about the order in which Batch Apex jobs are executed?

 

Imagine a user clicks a button that launches a Batch Apex job that will process 5000 records, in chunks of 500. While this Batch Apex job is chugging away, the user clicks another button that launches a different Batch Apex job that will process 2000 records, 100 per chunk. Can I be certain that all of the chunks for the first job will complete (all of the records will be processed) before the second job's first chunk begins? 

 

Thanks!

  • October 21, 2009
  • Like
  • 0

I have a process that sends emails to the Contacts of a set of Accounts (customer notification).  To do this, I create the message for each Account, as it is customized for the Account.  Because of the governer limit of 10 on invoking email send, I accumulate these in an array, then send at once. 

 

Unfortunately, if any of the emails are on a bounce list, then it fails to send any of them.  At any given time you are likely to one or more customer emails bounce, so this is very impractical.  Moreover, although I notify the requester of the exception, it does not include the email address that bounced, so is hard for an end-user to remedy:

 

First exception on row 1; first error: INVALID_EMAIL_ADDRESS, email address has bounced for id : 0037000000RqE7e: []

 

Even if I parse and discover the email address of the contact, there are reasons why an end-user cannot necessarily correct the situation, such as the customer's email server is temporarily unavailable.  

 

How does this conflict with the governer guidelines?  If there wasn't a limit of 10 send requests per HTTP request, I'd send each email individually, permitting all the others to successfully be sent despite the failure.  

 

I have a process that notifies the Contacts of Accounts that match a query.  I created the ability to run in test mode where it scrubs the email address before sending, adding it to the toAddresses.  That works.  But, this needs to use a template. 

 

The template requires a targetObjectId.  Unfortunately, this uses the real email address of the Contact rather than the scrubbed one. Does anyone know of a way to use a supplied email address rather than the email of the Contact record without changing the underlying value in the database?  

 

 

Does anyone know how to parse a String in a predefined format to a Date? Specifically, I'm trying to convert '1-Apr' to a date.  

 

As a Java developer, I can't believe how much time I am spending reinventing the wheel. Why is there no DateFormat, or SimpleDateFormat class? Why on earth didn't they just use Java like Google Apps does?

 

I can currently able to convert the day and year in Apex, ableit with tedious code.  I tried to convert the month from Apr to 4 using an enum (ordinal() returns position), but there doesn't seem to be a way to convert a String to its Enum counterpart like I can do in Java. In fact, ordinal() doesn't even seem to be compiler friendly, despite being documented (perhaps it is new to Apex 17.)

 

Here is what I have so far, with month obviously hard coded:

 

    /**
     * Dates are in the format of d-Mon in the CSV file.  E.g., "1-May" is the first
     * of may.  The year should put it in the future.  Thus, if it is "1-Jan" and it
     * is currently December of 1009, then the year should be 2010. 
     **/
    public Date convertEffectiveDate(String inDate) {
           String[] dateParts = inDate.split('-');
           Integer day = Integer.valueOf(dateParts[0]);
          
           Integer month = 4;
           Date effective = Date.newInstance(Date.today().year(), month, day);
          
           if (effective < Date.today())
               effective.addYears(1);
              
           return effective;
    }

 

 

Hi,

My understanding is that an org can only send 1000 emails per day.

 

If we have a @future method that execute the sendEmail() method:

 

 

@future public void sendEmailInFuture(){ Messaging.sendEmail(); }

 

And we call this method from other classes. When it reaches the limit, would the remaining messages be sent the next day when the limit is reset?

 

Thanks.

 

 

How many emails can the sendEmail  Apex method send out per day?

 

I went through the documentation, and here is what is says:

a. "All mass email and single email messages sent with the sendEmail method count against the daily mass mail limit of the sending organization."

 

b. "You can send mass email to a maximum of 1000 external email addresses per day based on Greenwich Mean Time (GMT)."

 

Statement 'b', in my opinion means that you can send emails to maximum 1000 distinct email addresses per day, but it says nothing about the number of actual email messages being sent.

 

 

Thanks.

"All mass email and single email messages sent with the sendEmail method count against the daily mass mail limit of the sending organization. When the daily mass mail limit for the organization is reached, all calls to the sendEmail method are rejected, and the user receives a MASS_MAIL_LIMIT_EXCEEDED error code" (in the doc)

This renders the Apex outbound email features USELESS !! What's the point of a sendEmail feature if I'm not sure if the email will be sent or not, depending on how much users would have already done some mass email or not?!!

Everyone: vote at http://ideas.salesforce.com/article/show/10087499?page=last#lastPost .

  • November 25, 2008
  • Like
  • 0