You need to sign in to do that
Don't have an account?
Sombir Sheoran
Testing TestClasses, for Trigger on Account, I cant find any records created ? How to verify that Test class was executed successfully and it there any method to verify records are created in database or application ?
Hello Everyone,
I have created 1 trigger on Account which opens a case as soon as we create the account.
So, as soon as I have written both the codes and now testing with testClass, it is not creating a new Account record in my salesforce org. and hence also not opening any case.
Is there anything I am missing here. Support is really appreciated.
1. Trigger on Account to open a case
trigger CreateTShirtCaseonAccount on Account (after insert) {
for(Account ListofAllAccount: Trigger.New)
{
Case newTshirtCase = new Case();
newTshirtCase.Subject = 'Congratulations, your account is opened, with free T-Shirt from us';
newTshirtCase.Priority = 'High';
newTshirtCase.AccountId = ListofAllAccount.id;
insert newTshirtCase;
}
}
2. Test Class to test the trigger
@isTest
public class TestAccountTrigger {
static testMethod void accountCreator()
{
Account newAccount = new Account();
newAccount.Name = 'Account Created with TestClass : TestAccountTrigger';
insert newAccount;
}
}
Regards,
Sombir Sheoran
I have created 1 trigger on Account which opens a case as soon as we create the account.
So, as soon as I have written both the codes and now testing with testClass, it is not creating a new Account record in my salesforce org. and hence also not opening any case.
Is there anything I am missing here. Support is really appreciated.
1. Trigger on Account to open a case
trigger CreateTShirtCaseonAccount on Account (after insert) {
for(Account ListofAllAccount: Trigger.New)
{
Case newTshirtCase = new Case();
newTshirtCase.Subject = 'Congratulations, your account is opened, with free T-Shirt from us';
newTshirtCase.Priority = 'High';
newTshirtCase.AccountId = ListofAllAccount.id;
insert newTshirtCase;
}
}
2. Test Class to test the trigger
@isTest
public class TestAccountTrigger {
static testMethod void accountCreator()
{
Account newAccount = new Account();
newAccount.Name = 'Account Created with TestClass : TestAccountTrigger';
insert newAccount;
}
}
Regards,
Sombir Sheoran
My code is to create a case when Account gets inserted. You can create an Account manually under Accounts Tab ==> New and see case is created for it.
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.
All Answers
Case required fields are missing in your trigger. Try below trigger.
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.
Hello, $C0RP!AN K!NG .
I tried to change trigger as to add 2 new required fields as well, however, I can not see any new Account or Case being created.
Is there anything I am missing further.
Appreciate your quick response.
Regards,
Sombir Sheoran
My code is to create a case when Account gets inserted. You can create an Account manually under Accounts Tab ==> New and see case is created for it.
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.
Thank you for your response.
In that case, how do we know whether our trigger/class was executed successfully or not?
Also, how can we know how much percentage of our class/trigger code has been executed in order to complete at least 75% for taking into Prod.
Regards,
Sombir Sheoran
You can execute tests from developer console as well.
More details can be found here -
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_unit_tests_running.htm
https://help.salesforce.com/articleView?id=code_test_execution.htm&type=0
If this answers your query please mark this question as a solved so that it can be filtered out from unsolved questions.
Glad to see your response that says below and hence marking the question as answered.
Appreciate your inputs here in order to clarify my concerns.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_unit_tests_running.htm
https://help.salesforce.com/articleView?id=code_test_execution.htm&type=0
Regards,
Sombir Sheoran