Hi! I am new to salesforce and I have a requirement to show all the cases related to an Account on Account Page Layout. Can anyone please help me on doing this in Visual Flow.
Case testCase = new Case(Status='New', Origin='Email', Issue_type__c='Customization', Account = acc);
to
Case testCase = new Case(Status='New', Origin='Email', Issue_type__c='Customization', AccountId = acc.Id);
Here is the corrected code with 100% coverage
@isTest
private class countCases_Test {
@isTest static void createAccountwithCase() {
// Create an account
Account acc = new Account();
acc.Name = 'Test123';
insert acc;
// Create a case associated with the test account
Case testCase = new Case(Status='New', Origin='Email', Issue_type__c='Customization', AccountId = acc.Id);
insert testCase;
}
}
That is available Out of Box, if you navigate to any individual Account. it may not be visible though but you can make it visible Edit Page Layout and drag down the Related List.
Why you want to Visual Flow route when it is available on Point and Click?
Sorry I have posted it wrong. I want the total number of cases on the account pagelayout. As case and account object do not have master detail relationship. I would like to use visual flow for it.
Is there any specific scenario that you are looking to see through visual flow. I mean how you want the Account to be chosen with visual flow and you are looking to call through a button passing the accountId. Please little detail on you requirement.
There is a number field count case on account and I want the number of cases on that account to populate on the case count field. If there are 5 cases on the account it should populate as 5 in the case count field
trigger countCases on Case (after insert, after update, after delete, after undelete) {
List<Case> caseList = (trigger.isDelete)? trigger.old : trigger.new;
set<Id> accountIdSet = new set<Id>();
for(Case cs: caseList ){
accountIdSet .add(cs.AccountId);
}
if(accountIdSet.size() > 0){
List<Account> lstAccount = [select id, No_of_Cases__c, (select id from Cases) from Account where id IN: accountIdSet ];
if(lstAccount.size() > 0){
for(Account acc: lstAccount){
acc.No_of_Cases__c = acc.Cases.size();
}
update lstAccount;
}
}
}
The test class for the trigger is
@isTest
private class countCases_Test {
@isTest static void createAccountwithCase() {
// Create an account
Account acc = new Account();
acc.Name = 'Test123';
insert acc;
// Create a case associated with the test account
Case testCase = new Case(Status='New', Origin='Email', Issue_type__c='Customization', Account = acc);
insert testCase;
}
}
But I get code coverage error. Can you please look at the trigger and test class and suggest me the changes.
Case testCase = new Case(Status='New', Origin='Email', Issue_type__c='Customization', Account = acc);
to
Case testCase = new Case(Status='New', Origin='Email', Issue_type__c='Customization', AccountId = acc.Id);
Here is the corrected code with 100% coverage
@isTest
private class countCases_Test {
@isTest static void createAccountwithCase() {
// Create an account
Account acc = new Account();
acc.Name = 'Test123';
insert acc;
// Create a case associated with the test account
Case testCase = new Case(Status='New', Origin='Email', Issue_type__c='Customization', AccountId = acc.Id);
insert testCase;
}
}
Here is the corrected code with 100% coverage
All Answers
Why you want to Visual Flow route when it is available on Point and Click?
Here is the corrected code with 100% coverage