• Ben Dunlap
  • NEWBIE
  • 100 Points
  • Member since 2011

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 14
    Replies

I am new to the apex coding. How would i be able to creat a test case for this code.

global static Map<ID, Prospect__c> GetBulkFullProspect(List<ID> prospectIDs)
{
// Ask the database for ALL the prospect fields.
string queryString = URLUtilities.GetFullBaseQuery('i360__Prospect__c');
queryString += ' WHERE ID IN :ProspectIDs ';

List<Prospect__c> FullProspects = (List<Prospect__c>)(database.query(queryString));
Map<Id,Prospect__c> retMap = new Map<ID,Prospect__c>();
for(Prospect__c prospect : FullProspects)
retMap.put(prospect.id,prospect);
return retMap;

My sandbox appears to have been updated to Summer '12 over the weekend and previously-working code is now failing with unknown or Java exceptions -- which makes me suspect internal bugs from the update. Two specific examples I've seen so far:

 

1) A trigger that assembles a singleEmailMessage and calls Messaging.sendEmail() at the end is failing on the sendEmail() with:

 

EXCEPTION_THROWN [65]|System.EmailException: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.lang.Boolean cannot be cast to java.lang.String: []

 2) A very simple VF page, which uses a standard controller, now fails to render. I get this error in lieu of the page:

 

java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.util.Date 

In this case the logs in the developer console don't even show the error so it seems like the problem occurs after all Apex code has executed (there is a small VF component involved that has a custom controller).

 

That's what I've seen so far today. On a related note: was there an announcement of the sandbox upgrade that I just missed or ignored? Should I be watching a feed that I'm not watching? I don't see anything on Twitter, in the developer.force.com blogs, or here in the forums (other than other users posting about their own difficulties)

 

I'm trying to use Messaging.sendEmail() in my sandbox and all indications are that it is working:

 

  • Messaging.SendEmailResult.isSuccess() returns TRUE
  • Messaging.SendEmailResult.getErrors() returns an empty list
  • Before/after calls to Limits.getEmailInvocations() indicate that one invocation is being consumed
  • Logs in the Developer Console show what I would expect to see -- the sendEmail() call followed by the body of the message

But the emails just aren't getting to their destination. I have another bit of code that has been around for a while and is quite similar, and it's working just fine -- I test it and an email arrives in my Inbox almost instantly.

 

What can I do to troubleshoot this further? Also, just to fill in some details, the basic architecture of the process I'm trying to automate here is as follows:

 

  • VisualForce email template called E
  • VisualForce page called P
  • code that invokes Messaging.sendEmail() is in the controller associated with P (in the constructor method)

When page P is loaded, the controller's constructor executes and sends an email using the email template E to a test Contact record. At first I was trying to attach a PDF generated by yet another VisualForce page but I commented out this functionality just to see if simplifying things would eliminate the problem. Still no emails in my Inbox.

 

I've also added a call to setBccAddresses() and passed it two additional email addresses of mine, on different domains and hosted by different services from the email address associated with the test Contact -- and the emails don't arrive in those mailboxes, either. All three email vendors provide very straightforward spam control so I have no reason to suspect that the emails are getting blocked -- it just seems like, somehow or other, Salesforce is failing to send these emails /after/ they leave the purview of Apex.

 

What can I do to troubleshoot this problem further?

I am trying to deploy a change set from my sandbox to my production environment. The sandbox reports that the change set was uploaded succesfully, and I get the corresponding confirmation email. But the change set never shows up in my production environment under "Inbound Change Sets".

 

The problem seems to be related to the change set itself -- I tried uploading it a couple of times with no luck, but then uploaded another very simple change set and it came right through on the inbound side.

 

I've been deploying from this particular sandbox to this particular production environment multiple times a week for months and this is the first time this has happened. Is there any way for me to troubleshoot it further or do I just need to go straight to SF support?

My Apex unit tests, which were all working in v23.0, are now failing in my v24.0 sandbox because there are no Pricebook2 records in the test database. I'm not sure how to fix this -- I've tried inserting my own Pricebook2 record but it doesn't make any difference, because it's not the Standard Price Book.

 

Here's my code, abbreviated:

 

Product2 newProd = new Product2(Name = 'test product', family = 'test family');
insert newProd;

PriceBookEntry pbEntry = new PriceBookEntry(
    UnitPrice = 300,
    PriceBook2Id = [select id from PriceBook2 where isStandard = true].Id,
    Product2Id = newProd.Id
);

 The query on line 6 fails with "List has no rows". But if I try this instead:

 

Product2 newProd = new Product2(Name = 'test product', family = 'test family');
insert newProd;

PriceBook2 pb = new PriceBook2(Name = 'test price book');
insert pb;

PriceBookEntry pbEntry = new PriceBookEntry(
    UnitPrice = 300,
    PriceBook2Id = pb.Id,
    Product2Id = newProd.Id
);

insert pbEntry;

 Then the last line fails with a STANDARD_PRICE_NOT_DEFINED exception.

 

Not sure how to get around this -- my understanding is that this code has stopped working in v24.0 because unit tests no longer have access to real data. How does one test opportunity line items, then?

Hi, I just discovered, after writing a fair amount of code to interact with the REST API, that this interface doesn't support lead conversion:

 

http://boards.developerforce.com/t5/REST-API-Integration/Convert-a-Lead-to-Account-via-REST/m-p/287373#M546

 

Since lead-conversion is a somewhat important part of our business process, I'm a little bit frustrated. I'll figure out a way to work around this gap but I'm wondering if there's a SOAP vs. REST comparison chart somewhere that I should have had a look at first?

 

If I had known that I needed to use the SOAP API in order to automate lead-conversion, I probably wouldn't have thought twice about using REST.

 

Also wondering if more advanced features like this (beyond basic CRUD operations)  are on the roadmap for the REST API?

My sandbox appears to have been updated to Summer '12 over the weekend and previously-working code is now failing with unknown or Java exceptions -- which makes me suspect internal bugs from the update. Two specific examples I've seen so far:

 

1) A trigger that assembles a singleEmailMessage and calls Messaging.sendEmail() at the end is failing on the sendEmail() with:

 

EXCEPTION_THROWN [65]|System.EmailException: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.lang.Boolean cannot be cast to java.lang.String: []

 2) A very simple VF page, which uses a standard controller, now fails to render. I get this error in lieu of the page:

 

java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.util.Date 

In this case the logs in the developer console don't even show the error so it seems like the problem occurs after all Apex code has executed (there is a small VF component involved that has a custom controller).

 

That's what I've seen so far today. On a related note: was there an announcement of the sandbox upgrade that I just missed or ignored? Should I be watching a feed that I'm not watching? I don't see anything on Twitter, in the developer.force.com blogs, or here in the forums (other than other users posting about their own difficulties)

 

Hello,

 

I'm having a problem sending an email message from the developer console or execute anonymous or final batch statments from within the sandbox.

 

I have successfully sent the email from the developer console in the production org, but i cannot do the same in the sandbox.

 

Does anyone know why i would not be able to send from the sandbox?

 

Here is the code:

 

Messaging.reserveSingleEmailCapacity(2);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'email@domain.com'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('email@domain.com');
mail.setSenderDisplayName('Salesforce Support');
mail.setSubject('New Case Created ');
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setPlainTextBody('Your Case: has been created.');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

Thanks for your help.

I'm trying to use Messaging.sendEmail() in my sandbox and all indications are that it is working:

 

  • Messaging.SendEmailResult.isSuccess() returns TRUE
  • Messaging.SendEmailResult.getErrors() returns an empty list
  • Before/after calls to Limits.getEmailInvocations() indicate that one invocation is being consumed
  • Logs in the Developer Console show what I would expect to see -- the sendEmail() call followed by the body of the message

But the emails just aren't getting to their destination. I have another bit of code that has been around for a while and is quite similar, and it's working just fine -- I test it and an email arrives in my Inbox almost instantly.

 

What can I do to troubleshoot this further? Also, just to fill in some details, the basic architecture of the process I'm trying to automate here is as follows:

 

  • VisualForce email template called E
  • VisualForce page called P
  • code that invokes Messaging.sendEmail() is in the controller associated with P (in the constructor method)

When page P is loaded, the controller's constructor executes and sends an email using the email template E to a test Contact record. At first I was trying to attach a PDF generated by yet another VisualForce page but I commented out this functionality just to see if simplifying things would eliminate the problem. Still no emails in my Inbox.

 

I've also added a call to setBccAddresses() and passed it two additional email addresses of mine, on different domains and hosted by different services from the email address associated with the test Contact -- and the emails don't arrive in those mailboxes, either. All three email vendors provide very straightforward spam control so I have no reason to suspect that the emails are getting blocked -- it just seems like, somehow or other, Salesforce is failing to send these emails /after/ they leave the purview of Apex.

 

What can I do to troubleshoot this problem further?

I am trying to deploy a change set from my sandbox to my production environment. The sandbox reports that the change set was uploaded succesfully, and I get the corresponding confirmation email. But the change set never shows up in my production environment under "Inbound Change Sets".

 

The problem seems to be related to the change set itself -- I tried uploading it a couple of times with no luck, but then uploaded another very simple change set and it came right through on the inbound side.

 

I've been deploying from this particular sandbox to this particular production environment multiple times a week for months and this is the first time this has happened. Is there any way for me to troubleshoot it further or do I just need to go straight to SF support?

I am new to the apex coding. How would i be able to creat a test case for this code.

global static Map<ID, Prospect__c> GetBulkFullProspect(List<ID> prospectIDs)
{
// Ask the database for ALL the prospect fields.
string queryString = URLUtilities.GetFullBaseQuery('i360__Prospect__c');
queryString += ' WHERE ID IN :ProspectIDs ';

List<Prospect__c> FullProspects = (List<Prospect__c>)(database.query(queryString));
Map<Id,Prospect__c> retMap = new Map<ID,Prospect__c>();
for(Prospect__c prospect : FullProspects)
retMap.put(prospect.id,prospect);
return retMap;

Hi All, and thanks for taking the time to look at my post.

 

I am trying to retrieve a list of contacts modified between two dates (LastModifiedDate >= Date1 AND LastModifiedDate <= Date2). When I query  I receive 0 rows. If I take out ONLY the second part (LastModifiedDate <= Date2) I receive many.

 

Here is my code and the debug log - first with the two dates:

 

DateTime myDate = DateTime.parse('10/05/2011 00:00 AM');
DateTime myLastDate = DateTime.valueOf('2012-02-7 05:04:25');
System.debug('the first date:' + String.valueOf(myDate) + ' and the last date: ' + String.valueOf(myLastDate));
List<Contact> cList = [select id, FirstName, LastName, LastModifiedDate  FROM Contact WHERE Email <> '' AND Email <> null AND LastModifiedDate >= :myDate and lastModifiedDate <= :myLastDate];
system.debug('num cons' + cList.size());

19:19:14.042 (42468000)|USER_DEBUG|[3]|DEBUG|the first date:2011-10-05 00:00:00 and the last date: 2012-02-07 05:04:25
19:19:14.042 (42478000)|SYSTEM_METHOD_EXIT|[3]|System.debug(ANY)
19:19:14.042 (42682000)|SOQL_EXECUTE_BEGIN|[4]|Aggregations:0|select id, FirstName, LastName, LastModifiedDate FROM Contact WHERE  Email <> '' AND Email <> null  AND LastModifiedDate >= :myDate and lastModifiedDate <= :myLastDate
19:19:18.055 (4055043000)|SOQL_EXECUTE_END|[4]|Rows:0

 and now with one date

DateTime myDate = DateTime.parse('10/05/2011 00:00 AM');
DateTime myLastDate = DateTime.valueOf('2012-02-7 05:04:25');
System.debug('the first date:' + String.valueOf(myDate) + ' and the last date: ' + String.valueOf(myLastDate));
List<Contact> cList = [select id, FirstName, LastName, LastModifiedDate  FROM Contact WHERE  Email <> '' AND Email <> null  AND LastModifiedDate >= :myDate ];
system.debug('num cons' + cList.size());
19:20:55.039 (39038000)|USER_DEBUG|[3]|DEBUG|the first date:2011-10-05 00:00:00 and the last date: 2012-02-07 05:04:25
19:20:55.039 (39045000)|SYSTEM_METHOD_EXIT|[3]|System.debug(ANY)
19:20:55.039 (39249000)|SOQL_EXECUTE_BEGIN|[4]|Aggregations:0|select id, FirstName, LastName, LastModifiedDate FROM Contact WHERE  Email <> '' AND Email <> null  AND LastModifiedDate >= :myDate
19:21:06.555 (11555339000)|SOQL_EXECUTE_END|[4]|Rows:21784

 Any suggestions are welcome.

  • February 07, 2012
  • Like
  • 0

My Apex unit tests, which were all working in v23.0, are now failing in my v24.0 sandbox because there are no Pricebook2 records in the test database. I'm not sure how to fix this -- I've tried inserting my own Pricebook2 record but it doesn't make any difference, because it's not the Standard Price Book.

 

Here's my code, abbreviated:

 

Product2 newProd = new Product2(Name = 'test product', family = 'test family');
insert newProd;

PriceBookEntry pbEntry = new PriceBookEntry(
    UnitPrice = 300,
    PriceBook2Id = [select id from PriceBook2 where isStandard = true].Id,
    Product2Id = newProd.Id
);

 The query on line 6 fails with "List has no rows". But if I try this instead:

 

Product2 newProd = new Product2(Name = 'test product', family = 'test family');
insert newProd;

PriceBook2 pb = new PriceBook2(Name = 'test price book');
insert pb;

PriceBookEntry pbEntry = new PriceBookEntry(
    UnitPrice = 300,
    PriceBook2Id = pb.Id,
    Product2Id = newProd.Id
);

insert pbEntry;

 Then the last line fails with a STANDARD_PRICE_NOT_DEFINED exception.

 

Not sure how to get around this -- my understanding is that this code has stopped working in v24.0 because unit tests no longer have access to real data. How does one test opportunity line items, then?