You need to sign in to do that
Don't have an account?
Drew Gehman 18
Assistance with Compile Error: Illegal assignment from List<Task> to String
Bet this is easy for someone, but I am so raw I am just cut and pasting... I have created my first trigger which simply takes the account number of an account, and assigns it to a custom task field AccountBannerID__C. I have tested it in my sandbox and it works. I am now creating my test.
Here is the test code (I think the trigger code in not applicable though I can load it if necessary)
Thank you for your assistance, and I will try to pay it forward by posting the trigger and the successful test to the forums
It doesn't like this line
String t = [Select AccountBannerID__c from Task where id = :t1.id];
I get this Compile Error: Illegal assignment from List<Task> to String
@isTest
private class TaskRelatedToACCTriggerTestClass {
static testMethod void myUnitTest() {
// Run test of code
//HERE, WE CREATE AN ACCOUNT RECORD PUTTING A VALUE IN THE FIELD THAT YOU CALL IN YOUR TRIGGER
//WE WANT TO TEST THE COMPLETE FUNCTIONALITY OF YOUR TRIGGER SO IT IS IMPORTANT TO VALIDATE, VIA THE TEST CLASS
//THAT YOUR TRIGGER ACHIEVES THE DESIRED RESULTS.. ...UPDATING A FIELD ON A TASK WITH A VALUE FROM AN ACCOUNT
Account aDS = new Account(name='jbailer', AccountNumber='123');
insert aDS;
//NOW, CREATE A TASK ASSIGNED TO THE ACCOUNT
Task t1 = new Task(subject='test', WhatId = aDS.id, description = 'test description');
insert t1;
//NOW, THE CRITICAL PART, WE WILL RUN AN ASSERT CALL TO MAKE SURE THAT THE CUSTOM FIELD ON THE TASK HAS THE VALUE FROM THE OPP
//THIS IS WHAT TESTS THE FUNCTIONALITY OF YOUR TRIGGER
String t = [Select AccountBannerID__c from Task where id = :t1.id];
system.AssertEquals('123', t);
}
}
Here is the test code (I think the trigger code in not applicable though I can load it if necessary)
Thank you for your assistance, and I will try to pay it forward by posting the trigger and the successful test to the forums
It doesn't like this line
String t = [Select AccountBannerID__c from Task where id = :t1.id];
I get this Compile Error: Illegal assignment from List<Task> to String
@isTest
private class TaskRelatedToACCTriggerTestClass {
static testMethod void myUnitTest() {
// Run test of code
//HERE, WE CREATE AN ACCOUNT RECORD PUTTING A VALUE IN THE FIELD THAT YOU CALL IN YOUR TRIGGER
//WE WANT TO TEST THE COMPLETE FUNCTIONALITY OF YOUR TRIGGER SO IT IS IMPORTANT TO VALIDATE, VIA THE TEST CLASS
//THAT YOUR TRIGGER ACHIEVES THE DESIRED RESULTS.. ...UPDATING A FIELD ON A TASK WITH A VALUE FROM AN ACCOUNT
Account aDS = new Account(name='jbailer', AccountNumber='123');
insert aDS;
//NOW, CREATE A TASK ASSIGNED TO THE ACCOUNT
Task t1 = new Task(subject='test', WhatId = aDS.id, description = 'test description');
insert t1;
//NOW, THE CRITICAL PART, WE WILL RUN AN ASSERT CALL TO MAKE SURE THAT THE CUSTOM FIELD ON THE TASK HAS THE VALUE FROM THE OPP
//THIS IS WHAT TESTS THE FUNCTIONALITY OF YOUR TRIGGER
String t = [Select AccountBannerID__c from Task where id = :t1.id];
system.AssertEquals('123', t);
}
}
SOQL queries either return an sObject (such as a generic sObject or a Task) or a List of sObjects, and you're attempting to assign it to a String, which is why you're seeing the compile error. Try changing String to task like in my example, and asserting the AccountBannerId__c field instead.
All Answers
SOQL queries either return an sObject (such as a generic sObject or a Task) or a List of sObjects, and you're attempting to assign it to a String, which is why you're seeing the compile error. Try changing String to task like in my example, and asserting the AccountBannerId__c field instead.