-
ChatterFeed
-
2Best Answers
-
0Likes Received
-
0Likes Given
-
8Questions
-
8Replies
Illegal assignment from LIST<string> to String
Any suggestions, what I can do to overcome this error? thanks.
for(BulkLoadDataHolder bldhrec : dataHolderList){
Student_Tracking__c strec = new Supplier_Tracking__c();
strec.Program__c = this.blRec.Program__c;
strec.Email_Address__c = bldhrec.Email_Address;
string s = bldhrec.Email_Address.split('@',2); // Illegal assignment from LIST<string> to String
strec.D_Name = s;
system.debug('DomainName is' +strec.Domain_Name__c );
......
}
-
- Sabrent
- October 15, 2012
- Like
- 0
- Continue reading or reply
Setting business hours on case
I want to set the business hours on a Case in Apex, but am having trouble doing it - it appears that Apex lets me say, for example:
case.BusinessHours = businessHoursObject;
But it doesn't look like it's refelected on the case. Also, I can't see any references to the BusinessHours field of a Case in the docs, yet it's available in the UI.
Has anyone done this?
-
- Clap Master
- March 27, 2013
- Like
- 0
- Continue reading or reply
Creating entitlement, entitlement process, and milestones in test code
I need to create test classes to do some stuff on cases, entitlements, entitlement processes, and milestones. I understand that my case will map to an entitlement, and my entitlement maps to an entitlement process (SlaProcess), but I can't figure out how milestones connect to my entitlement process. My cases get CaseMilestones based on entering the entitlement process, but where are the generic defined milestones that are supposed to be attached to the entitlement process?
Anyone know?
-
- Clap Master
- January 09, 2013
- Like
- 0
- Continue reading or reply
Make copy of history object to use for testing
As many of you already know, history object are not editable. This presents a unique issue when you have Apex classes that deal with histories, as you need to acheive 75% code coverage in your tests. In my case, I'm dealing with Cases and CaseHistories. The cleanest way I can come up with to test this is to (if possible) make a copy of the CaseHistory object (and call it something like TestCaseHistory) and then manually populate that along with Cases in my test code, and then run my classes against that test data.
The key to this, though is Can you make a copy of 'History' objects to use elsewhere?
-
- Clap Master
- October 17, 2012
- Like
- 0
- Continue reading or reply
Create CaseHistory entry through Apex
I'm creating cases in a test class to do unit testing, and I need to have the test cases also have some case history items. When you edit a case through the UI, we have 'Status' as a tracked field, so any cahnges are tracked in the CaseHistory table. When I cahnge the 'Status' programatically however, through Apex, it does not create an extry in the CaseHistory table.
Does anyone know how to accomplish this?
-
- Clap Master
- October 15, 2012
- Like
- 0
- Continue reading or reply
Test.LoadData() returning void?
I'm trying to implement the new Test.LoadData() method (page 174 -> https://na7.salesforce.com/help/doc/en/salesforce_winter13_release_notes.pdf) and the force IDE is telling me that Test.LoadData() returns void, not a List of sObjects.
What gives?
-
- Clap Master
- October 04, 2012
- Like
- 0
- Continue reading or reply
Accessing static fields from a test class
I'm trying to access static fields of a class from within a test class, with a statement like this:
genericObject.genericField = outerClass.staticVariable;
And the Force IDE is telling me 'Variable does not exist' when I try and execute the test. I'm not able to find anything about special considerations when accessing static class members within tests. Am I doing something fundamentally wrong here?
-
- Clap Master
- October 04, 2012
- Like
- 0
- Continue reading or reply
Never receiving mail sent with Messaging class
I'm making a simple class to send emails out, but I never receive any of the emails my class sends. I'm in a sandbox, and executing the class via a test class (annotated with
(seeAllData=true)). Messaging.sendEmail() is returning 'true'.
Messaging.reserveSingleEmailCapacity(2); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {c.contact.Email}; mail.setToAddresses(toAddresses); mail.setReplyTo('support@mysite.com'); mail.setSenderDisplayName('MySite Support'); mail.setSubject('Case #' + c.CaseNumber + ' is awaiting an update from you'); mail.setHtmlBody('Hi ' + c.contact.FirstName + ' - ' + '<br><br>' + 'The above referenced case number is open and we are awaiting an update from you. ' + 'Please either reply to the original email thread for this case or update your case by logging in to the ' + '<a href=http://support.mysite.com/>MySite Support Portal</a> ' + 'and let us know how things are going.' + '<br><br>' + 'Regards,<br>MySite Support'); List<Messaging.SendEmailResult> result = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); System.debug('result -> ' + result.get(0).isSuccess());
I changed the compant name to mysite. Also, in the debug, I see that the recipient email address is in the EMAIL_QUEUE line, and it still fails even if I hard code a recipient email address.
Any ideas?
-
- Clap Master
- October 01, 2012
- Like
- 0
- Continue reading or reply
SOQL query returning results in Force.com Explorer, but nothing in actual class
I'm usinf a sandbox trying to run a query to get back all open cases that I will then iterate through and do some work on. Here's my query:
SELECT CaseNumber, Status, IsClosed, IsDeleted, Owner.name, LastModifiedDate, Contact.name, Contact.Email FROM Case
In the Force.com Explorer, I get all the cases back, but when I run this in a class in my sandbox, I get no results (from the log output, that is). The below example was a test with pulling from the Account table:
09:59:09.617 (1617692000)|SOQL_EXECUTE_BEGIN|[10]|Aggregations:0|select Name from Account
09:59:09.621 (1621556000)|SOQL_EXECUTE_END|[10]|Rows:0
I'm pretty sure I'm hitting the same database, and I seem to see this behavior all tables that I've spot checked.
Any ideas?
-
- Clap Master
- September 24, 2012
- Like
- 0
- Continue reading or reply
Creating entitlement, entitlement process, and milestones in test code
I need to create test classes to do some stuff on cases, entitlements, entitlement processes, and milestones. I understand that my case will map to an entitlement, and my entitlement maps to an entitlement process (SlaProcess), but I can't figure out how milestones connect to my entitlement process. My cases get CaseMilestones based on entering the entitlement process, but where are the generic defined milestones that are supposed to be attached to the entitlement process?
Anyone know?
- Clap Master
- January 09, 2013
- Like
- 0
- Continue reading or reply
Need help with test code for Apex trigger
Hello,
I'm really new to Apex and to code in general, so please try to not laugh at my pathetic test code. The code itself works (I tested manually) and it's a really basic trigger; the test code fails, though, and I can't figure out why. Can anyone help me figure out what's going on? Thank you!!
Trigger:
trigger SpouseTrigger on Contact (before insert) { List<Contact> cons = new List<Contact>(); List<Contact> consToInsert = new List<Contact>(); for(Contact c:trigger.new){ if(c.Sig_Other_First_Name__c != null && c.Sig_Other_Last_Name__c != null){ cons.add(c); } } for(Contact c: cons){ Contact newCon = new Contact(); newCon.FirstName = c.Sig_Other_First_Name__c; newCon.LastName = c.Sig_Other_Last_Name__c; newCon.AccountId = c.AccountId; consToInsert.add(newCon); } insert consToInsert; }
Here's the test code, where something isn't working:
@istest private class SpouseTriggerTest { static TestMethod void Test1_TestInsertContact() { Account acc = new Account(Name = 'My Account', RecordTypeid = '012A0000000dlDz'); insert acc; Contact testC1 = new Contact(LastName='Test1 Contact', Sig_Other_First_Name__c='John', Sig_Other_Last_Name__c='Smith', AccountId = acc.Id); insert testC1; //pull the account info for that contact Contact SecContact1 = [SELECT FirstName, LastName, AccountId FROM Contact WHERE Id = :testC1.id]; //verify that the insert updated by creating another contact as in the trigger System.assert(SecContact1.Id != null); System.assertEquals(SecContact1.FirstName, testC1.Sig_Other_First_Name__c); System.assertEquals(SecContact1.LastName, testC1.Sig_Other_Last_Name__c); System.assertEquals(SecContact1.AccountId, testC1.AccountId); Contact testC2 = new Contact(LastName='Test1 Contact', Sig_Other_First_Name__c=null, Sig_Other_Last_Name__c='Smith', AccountId = acc.Id); insert testC2; //pull the account info for that contact Contact SecContact2 = [SELECT FirstName, LastName, AccountId FROM Contact WHERE Id = :testC2.id]; //verify that the insert updated by creating another contact as in the trigger System.assert(SecContact2.Id != null); System.assertNotEquals(SecContact2.FirstName, testC2.Sig_Other_First_Name__c); System.assertNotEquals(SecContact2.LastName, testC2.Sig_Other_Last_Name__c); System.assertNotEquals(SecContact2.AccountId, testC2.AccountId); Contact testC3 = new Contact(LastName='Test1 Contact', Sig_Other_First_Name__c='John', Sig_Other_Last_Name__c=null, AccountId = acc.Id); insert testC3; //pull the account info for that contact Contact SecContact3 = [SELECT FirstName, LastName, AccountId FROM Contact WHERE Id = :testC3.id]; //verify that the insert updated by creating another contact as in the trigger System.assert(SecContact3.Id != null); System.assertNotEquals(SecContact3.FirstName, testC3.Sig_Other_First_Name__c); System.assertNotEquals(SecContact3.LastName, testC3.Sig_Other_Last_Name__c); System.assertNotEquals(SecContact3.AccountId, testC3.AccountId); Contact testC4 = new Contact(LastName='Test1 Contact', Sig_Other_First_Name__c=null, Sig_Other_Last_Name__c=null, AccountId = acc.Id); insert testC4; //pull the account info for that contact Contact SecContact4 = [SELECT FirstName, LastName, AccountId FROM Contact WHERE Id = :testC4.id]; //verify that the insert updated by creating another contact as in the trigger System.assert(SecContact4.Id != null); System.assertNotEquals(SecContact4.FirstName, testC4.Sig_Other_First_Name__c); System.assertNotEquals(SecContact4.LastName, testC4.Sig_Other_Last_Name__c); System.assertNotEquals(SecContact4.AccountId, testC4.AccountId); } }
Here's the error message I receive:
Class | SpouseTriggerTest |
Method Name | Test1_TestInsertContact |
Pass/Fail | Fail |
Error Message | System.AssertException: Assertion Failed: Expected: null, Actual: John |
Stack Trace | Class.SpouseTriggerTest.Test1_TestInsertContact: line 16, column 1 |
- Ali Meyer
- January 09, 2013
- Like
- 0
- Continue reading or reply
Illegal assignment from LIST<string> to String
Any suggestions, what I can do to overcome this error? thanks.
for(BulkLoadDataHolder bldhrec : dataHolderList){
Student_Tracking__c strec = new Supplier_Tracking__c();
strec.Program__c = this.blRec.Program__c;
strec.Email_Address__c = bldhrec.Email_Address;
string s = bldhrec.Email_Address.split('@',2); // Illegal assignment from LIST<string> to String
strec.D_Name = s;
system.debug('DomainName is' +strec.Domain_Name__c );
......
}
- Sabrent
- October 15, 2012
- Like
- 0
- Continue reading or reply
Accessing static fields from a test class
I'm trying to access static fields of a class from within a test class, with a statement like this:
genericObject.genericField = outerClass.staticVariable;
And the Force IDE is telling me 'Variable does not exist' when I try and execute the test. I'm not able to find anything about special considerations when accessing static class members within tests. Am I doing something fundamentally wrong here?
- Clap Master
- October 04, 2012
- Like
- 0
- Continue reading or reply
Never receiving mail sent with Messaging class
I'm making a simple class to send emails out, but I never receive any of the emails my class sends. I'm in a sandbox, and executing the class via a test class (annotated with
(seeAllData=true)). Messaging.sendEmail() is returning 'true'.
Messaging.reserveSingleEmailCapacity(2); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {c.contact.Email}; mail.setToAddresses(toAddresses); mail.setReplyTo('support@mysite.com'); mail.setSenderDisplayName('MySite Support'); mail.setSubject('Case #' + c.CaseNumber + ' is awaiting an update from you'); mail.setHtmlBody('Hi ' + c.contact.FirstName + ' - ' + '<br><br>' + 'The above referenced case number is open and we are awaiting an update from you. ' + 'Please either reply to the original email thread for this case or update your case by logging in to the ' + '<a href=http://support.mysite.com/>MySite Support Portal</a> ' + 'and let us know how things are going.' + '<br><br>' + 'Regards,<br>MySite Support'); List<Messaging.SendEmailResult> result = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); System.debug('result -> ' + result.get(0).isSuccess());
I changed the compant name to mysite. Also, in the debug, I see that the recipient email address is in the EMAIL_QUEUE line, and it still fails even if I hard code a recipient email address.
Any ideas?
- Clap Master
- October 01, 2012
- Like
- 0
- Continue reading or reply
SOQL query returning results in Force.com Explorer, but nothing in actual class
I'm usinf a sandbox trying to run a query to get back all open cases that I will then iterate through and do some work on. Here's my query:
SELECT CaseNumber, Status, IsClosed, IsDeleted, Owner.name, LastModifiedDate, Contact.name, Contact.Email FROM Case
In the Force.com Explorer, I get all the cases back, but when I run this in a class in my sandbox, I get no results (from the log output, that is). The below example was a test with pulling from the Account table:
09:59:09.617 (1617692000)|SOQL_EXECUTE_BEGIN|[10]|Aggregations:0|select Name from Account
09:59:09.621 (1621556000)|SOQL_EXECUTE_END|[10]|Rows:0
I'm pretty sure I'm hitting the same database, and I seem to see this behavior all tables that I've spot checked.
Any ideas?
- Clap Master
- September 24, 2012
- Like
- 0
- Continue reading or reply