You need to sign in to do that
Don't have an account?

I wrote one Future metho. In my code i got some errors so I need some assistance with this problem. here is my code along with error notification.
public class CalculateCaseOrigin {
@future
public static void countCasesBasedOnOrigin(List<Id> accIds){
List<Account> accList = [Select Id, Cases_Through_Email__c, Cases_Through_Phone__c, Cases_Through_Web__c'
, (Select Id, Origin From Cases)
From Account where Id IN: accIds];
for (Account acc = accList){
Integer Email=0, Web=0, Phone=0;
for (Case ca : acc.Cases){
if(ca.Origin == 'Phone'){
phone++;
}else if(ca.Origin =='Web'){
Web++;
}else if(ca.Origin == 'Email'){
Email++;
}
}
acc.Cases_Through_Email__c = Email;
acc.Cases_Through_Phone__c = Phone;
acc.Cases_Through_web__c = Web;
}
if(!accList.isEmpty)
update accList;
}
}
errors -
*Missing closing quote character ' on string.
*Unexpected token '\n , (Select Id, Origin From Cases)\n From Account where Id IN: accIds]; \n \n for (Account acc = accList){\n Integer Email=0, Web=0, Phone=0; \n \n for (Case ca : acc.Cases){\n if(ca.Origin == '.
*Expecting 'FROM' but was: '\n , (Select Id, Origin From Cases)\n From Account where Id IN: accIds]; \n \n for (Account acc = accList){\n Integer Email=0, Web=0, Phone=0; \n \n for (Case ca : acc.Cases){\n if(ca.Origin == '
*Missing ';' at '){\n phone++;\n }else if(ca.Origin =='
*Illegal string literal: Line breaks are not allowed in string literals
*Missing ';' at '){\n Web++;\n }else if(ca.Origin == '
*Illegal string literal: Line breaks are not allowed in string literals
*Expecting ';' but was: '<EOF>'
*Method must have a body
@future
public static void countCasesBasedOnOrigin(List<Id> accIds){
List<Account> accList = [Select Id, Cases_Through_Email__c, Cases_Through_Phone__c, Cases_Through_Web__c'
, (Select Id, Origin From Cases)
From Account where Id IN: accIds];
for (Account acc = accList){
Integer Email=0, Web=0, Phone=0;
for (Case ca : acc.Cases){
if(ca.Origin == 'Phone'){
phone++;
}else if(ca.Origin =='Web'){
Web++;
}else if(ca.Origin == 'Email'){
Email++;
}
}
acc.Cases_Through_Email__c = Email;
acc.Cases_Through_Phone__c = Phone;
acc.Cases_Through_web__c = Web;
}
if(!accList.isEmpty)
update accList;
}
}
errors -
*Missing closing quote character ' on string.
*Unexpected token '\n , (Select Id, Origin From Cases)\n From Account where Id IN: accIds]; \n \n for (Account acc = accList){\n Integer Email=0, Web=0, Phone=0; \n \n for (Case ca : acc.Cases){\n if(ca.Origin == '.
*Expecting 'FROM' but was: '\n , (Select Id, Origin From Cases)\n From Account where Id IN: accIds]; \n \n for (Account acc = accList){\n Integer Email=0, Web=0, Phone=0; \n \n for (Case ca : acc.Cases){\n if(ca.Origin == '
*Missing ';' at '){\n phone++;\n }else if(ca.Origin =='
*Illegal string literal: Line breaks are not allowed in string literals
*Missing ';' at '){\n Web++;\n }else if(ca.Origin == '
*Illegal string literal: Line breaks are not allowed in string literals
*Expecting ';' but was: '<EOF>'
*Method must have a body
Can you try the below code.
If this solution helps, please mark it as bst answer.
Thanks,
All Answers
Can you try the below code.
If this solution helps, please mark it as bst answer.
Thanks,
First error: Update failed. First exception on row 1 with id 0015g00000N8j5YAAR; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, For this particular combination we can not create more than one child record: []
This class is updating an account record that has more than 1 contact. But there is some validation that Account cannot have more than one constact because of which the class is failing.
You may need to remove the validation if you wish you don't need it or if validation is needed then it is working as expected.
Thanks,