2

I am new to Salesforce and haven't coded in quite awhile, so please forgive my rookie mistake(s).

I am attempting to write a trigger to do the following:

Our company manufactures equipment that occasionally requires software updates. What we want to do is the following:

Intent: Create an automatic process that generates cases based on Customer Asset and Firmware Version.

Current setup:

  • Object named Firmware Version
  • Object named Firmware Update Available
  • E-mail Template - Software Update (includes Update Revision Notes, Update File, Instructions to implement)

Current Workflow:

Checks Object - Firmware Update Available and Verifies current Firmware Version < New Version Number

If True -> E-mail Notification sent out to customer(s) with attachments.

Task Created under Instrument that requests Service open a ticket.

What we need:

Case is created for each separate asset for each customer. E-mail Template that is sent from case includes all relevant information and attachments. Customers then respond to case (via email2case) that update is complete.

Roadblock:

No "Out of the Box" App that can generate a case from workflow, task, or asset.

Help Requested:

Does anyone have a visualforce or javascript they have used that does this? Alternately, can someone point me in the right direction to create this functionality?

Here is the code I have written so far

public with sharing class FirmwareClass{

public void createCases(List<Customer_Asset__c> assets){
  List<Customer_Asset__c> casesToCreate = new List<Customer_Asset__c>();

  for(Customer_Asset__c acc:assets){
        if (Customer_Asset__c.Firmware_Update_Available__c = TRUE){
         Case caseToAdd = new Case();
         caseToAdd.AccountId = acc.Account__c;
         caseToAdd.Customer_Model__c = Customer_Asset__c.Instrument__c;
         caseToAdd.Subject = 'Software Upgrade Available';
            }       
  } 
  insert Case;
}

And this is the Trigger:

 trigger FirmwareTrigger on Customer_Asset__c (after update) {
   FirmwareClass helper = new FirmwareClass();
   if((Trigger.isAfter && Trigger.isInsert) || (Trigger.isAfter && Trigger.isUpdate)){
     // Now call your helper method
     helper.createCaseWhenNeeded(Trigger.new);
    }
  }
5
  • 1
    Welcome to SFSE, Bill. So you need help with how to create a Case from a trigger? Does your createCases() method work?
    – Mike Chale
    Jun 20 '13 at 15:02
  • VisualForce code would only be of use in your customer portal and you'd need a custom controller for it. Obviously, NOT the way to go. I think you're on the right track. Until the object is "touched" by an update, the trigger won't fire to generate the case. If you need the case in place sooner, rethink your logic so an update is still generated.
    – crmprogdev
    Jun 20 '13 at 15:05
  • Hi Mike, No my createCases() method is failing. Jun 20 '13 at 15:47
  • Let me try that again :) FirmwareClass: Variable does not exist: Case Jun 20 '13 at 15:51
  • @crmprogdev - Thanks for the comment! I'm stuck on getting the case to generate. My intent is that once the records are updated, the trigger fires and creates the cases. Then I can use a list view and mass e-mail the update to the users that need the update. Jun 20 '13 at 15:53
3

I think you almost have it. Your FirmwareClass method looks like it needs a few corrections. Try:

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.Customer_Model__c = acc.Instrument__c;
         caseToAdd.Subject = 'Software Upgrade Available';
         casesToCreate.add(caseToAdd);
            }       
  } 
  if (casesToCreate.size() > 0)
      insert casesToCreate;
}

Also, your trigger looks like it is calling the wrong method. It should be helper.createCases.

Disclaimer: I haven't tested this code, so it may have a syntax error or two.

9
  • Thanks for the help! It's close. I'm getting an error now: FirmwareClass: Illegal assignment from Schema.SobjectField to String. DO I need to change the field type? Jun 20 '13 at 16:20
  • What line number is the error on? Jun 20 '13 at 16:33
  • Line 10, column 10 Jun 20 '13 at 16:39
  • Oops, missed a couple things. I've updated the code. You had the object name (Customer_Asset__c) instead of the variable (acc) name. Jun 20 '13 at 16:42
  • Ok Fixed that problem by just removing that line. I can always go in and change the Asset Name manually if I have to. At the moment I just want to get the cases created. I am now getting an error "Line 7, column 13: Comparison arguments must be compatible types: Schema.SObjectField, String The Field is a checkbox, I had assumed it TRUE would respond as a checkmark. Jun 20 '13 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.