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

Trigger and Test Class Help
As a followup to my previous posts (Again, many many thanks) I am still having trouble with the trigger.
The code seems to function and I created a test class and the code itself is 100% covered.
The Trigger will not work, I am getting 0% coverage and I am not sure what I am doing wrong.
Trigger:
trigger FirmwareTrigger on Customer_Asset__c (before update, after update) { FirmwareClass helper = new FirmwareClass(); helper.createCases(Trigger.new); }
Test Class
@isTest private class FirmwareClassTest { private static testMethod void testCreateCases() { //create a new instance of a Customer_Asset__c to use in the test List<Customer_Asset__c> testAssets = new List<Customer_Asset__c> {}; Customer_Asset__c ta = new Customer_Asset__C(); ta.Firmware_Update_Available__c = True; testAssets.add(ta); FirmwareClass helper = new FirmwareClass(); Test.startTest(); helper.createCases(testAssets); Test.stopTest(); // query for cases to see if some were created and do an assertion } Customer_Asset__c[] acctQuery = [SELECT Firmware_Update_Available__c FROM Customer_Asset__c];
Class
public with sharing class FirmwareClass{ public void createCases(List<Customer_Asset__c> assets){ List<Case> casesToCreate = new List<Case>(); for(Customer_Asset__c acc:assets){ if (acc.Firmware_Update_Available__c == TRUE){ Case caseToAdd = new Case(); caseToAdd.AccountId = acc.Account__c; caseToAdd.Subject = 'Software Upgrade Available'; casesToCreate.add(caseToAdd); } } if (casesToCreate.size() > 0) insert casesToCreate; } }
I tried to get fancy and added (what I hoped / thought) would be some sort of validation within the trigger.
Updated Trigger
trigger FirmwareTrigger on Customer_Asset__c (before update) { List<FirmwareUpdate> listfirm = new list<FirmwareUpdate>(); for (Customer_Asset__c ta: trigger.new) { FirmwareUpdate firmup = [SELECT Firmware_Update_Available__c FROM Customer_Asset__c]; if (firmup == 1) { FirmwareClass helper = new FirmwareClass(); for (Customer_Asset__c az: Trigger.new); helper.createCases(Trigger.new); } } }
I receive a compile error with the New Trigger:
Error: Compile Error: Invalid type: FirmwareUpdate at line 3 column 47
The old trigger compiles but is showing a 0 code coverage. At this point I am stuck. I believe my class works, but I can't get past this point.
You are getting that error because the system is looking for an object.
Try this:
trigger FirmwareTrigger on Customer_Asset__c ( after update) {
List<Customer_Asset__c> listfirm = new list<Customer_Asset__c>();
for (Customer_Asset__c ta: trigger.new)
{
List <Customer_Asset__c> firmup = [SELECT Id FROM Customer_Asset__c WHERE Firmware_Update_Available__c = TRUE];
FirmwareClass helper = new FirmwareClass();
for (Customer_Asset__c az: Trigger.new);
helper.createCases(Trigger.new);
}
}
All Answers
I dont think you have anything called firmware upgrade in your org. Instead of firmwareUpgrade it should be Customer_Asset__c
You are getting that error because the system is looking for an object.
Try this:
trigger FirmwareTrigger on Customer_Asset__c ( after update) {
List<Customer_Asset__c> listfirm = new list<Customer_Asset__c>();
for (Customer_Asset__c ta: trigger.new)
{
List <Customer_Asset__c> firmup = [SELECT Id FROM Customer_Asset__c WHERE Firmware_Update_Available__c = TRUE];
FirmwareClass helper = new FirmwareClass();
for (Customer_Asset__c az: Trigger.new);
helper.createCases(Trigger.new);
}
}
Hello everyone,
I have updated the code as you suggested and I am now seeing the trigger firing.
Problem is that while the trigger is firing and the logs show the data being collected, it is not creating the cases.
Any advice?
Trigger:
Test Class
Class
There are some issues though!
While inserting new records make sure
Thank you for your help!
With yours and a few others, I have been able to get this working.
Many thanks!