You need to sign in to do that
Don't have an account?
Yogesh Kumar 35
Account to case update : Trigger
Hi All,
I am new to Salesforce and trying to write a trigger and test class so that I can create a trigger that fires when the Active__c field on the Account object is updated to ‘No’. This trigger should find all related Case records and update their Status fields to ‘Closed’.
This trigger should create at least 150 Accounts and at least 10 Cases for each Account. I need to use assert statements to validate that my trigger is working.
I have written the below code and getting 3 errors:
Trigger:
trigger AccountTrigger on Account ( after update ) {
Account.CaseUpdate(Trigger.new);
}
or
trigger AccountTrigger on Account ( after update ) {
CaseUpdate update = new CaseUpdate();
if (Trigger.isAfter && Trigger.isUpdate){
update.CaseUpdate(Trigger.new);
}
}
=========================================================================
Class:
public class CaseUpdate {
set <Account> accId = new Set <Id>();
set <Cases> caseId = new Set <Id>();
for (Case c : Trigger.new); {
List<Case> opencase = [SELECT Id, Status, Account Id from Case where Id = :accId.Id];
if (a.Active__c = 'No')
{
c.Status = 'Closed';
update opencase;
}
}
}
======================================================================
Testclass:
@isTest
public class AccountTriggerTest {
public static testMethod void doTest () {
Account acc = new Account(
Name = 'Test Account',
Active__c = 'None'
);
insert acc;
Case c = new Case(
Account = acc.Id,
Status = 'None';
);
insert c;
Account accTest = [SELECT Id, Active__c FROM Account WHERE Id = :acc.id];
System.assertEquals(accTest.Active__c, 'Yes');
c.Status = 'Closed';
update c;
accTest = [SELECT Id, Active__C FROM Account WHERE Id = :acc.id];
System.assertEquals(accTest.Status, 'Closed');
}
}
}
Any suggestions and guidance would really help me. Thanks in advance.
I am new to Salesforce and trying to write a trigger and test class so that I can create a trigger that fires when the Active__c field on the Account object is updated to ‘No’. This trigger should find all related Case records and update their Status fields to ‘Closed’.
This trigger should create at least 150 Accounts and at least 10 Cases for each Account. I need to use assert statements to validate that my trigger is working.
I have written the below code and getting 3 errors:
Trigger:
trigger AccountTrigger on Account ( after update ) {
Account.CaseUpdate(Trigger.new);
}
or
trigger AccountTrigger on Account ( after update ) {
CaseUpdate update = new CaseUpdate();
if (Trigger.isAfter && Trigger.isUpdate){
update.CaseUpdate(Trigger.new);
}
}
=========================================================================
Class:
public class CaseUpdate {
set <Account> accId = new Set <Id>();
set <Cases> caseId = new Set <Id>();
for (Case c : Trigger.new); {
List<Case> opencase = [SELECT Id, Status, Account Id from Case where Id = :accId.Id];
if (a.Active__c = 'No')
{
c.Status = 'Closed';
update opencase;
}
}
}
======================================================================
Testclass:
@isTest
public class AccountTriggerTest {
public static testMethod void doTest () {
Account acc = new Account(
Name = 'Test Account',
Active__c = 'None'
);
insert acc;
Case c = new Case(
Account = acc.Id,
Status = 'None';
);
insert c;
Account accTest = [SELECT Id, Active__c FROM Account WHERE Id = :acc.id];
System.assertEquals(accTest.Active__c, 'Yes');
c.Status = 'Closed';
update c;
accTest = [SELECT Id, Active__C FROM Account WHERE Id = :acc.id];
System.assertEquals(accTest.Status, 'Closed');
}
}
}
Any suggestions and guidance would really help me. Thanks in advance.
try below code for update case status field when account field Active__c is true
class
note-: make sure in your status picklist on case object, you have "Closed" value in your picklist test class (100% code cover)
thanks
let me inform if it helps you
and mark it best answer if it helps you so it make proper solution for others in future :)
All Answers
try below code for update case status field when account field Active__c is true
class
note-: make sure in your status picklist on case object, you have "Closed" value in your picklist test class (100% code cover)
thanks
let me inform if it helps you
and mark it best answer if it helps you so it make proper solution for others in future :)
I still get 3 errors while running test class saying:
1. CaseUpdate - Comparision arguments must be compatible types, String:Boolean (if (acc.Active__c == true))
2. AccountTrigger- Dependent class is invalid and needs recompilation (CaseUpdate oupdate = new CaseUpdate();)
3. AccountTriggerTest - Illegal assignment from Boolean to String do not know why. ( acc.Active__c = true;)
It would be great if you could help.