function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SeanSeeSeanSee 

Case to Custom Object Trigger

I'm trying to create a trigger that will update a custom object that we have called a participant record anytime a user submits a cancellation case.  The problem I'm running into is that we also use a custom object called programs and we've made a change so that multiple records use the same name.  I am trying to use an if else statement and the division to differentiate the different program names.

 

Right now the trigger is not getting to the end to update the participant record but I'm not sure why.  If anyone has any suggestions it would be a huge help.

 

trigger CancellationCaseTrigger on Case (before insert, before update) {
    for (Case thiscase: System.Trigger.new) {
    
       
        // DE-6 : Modifed Orignal Trigger to Only Cancel the Program specified on the Case Object
        Participant__c[] Participants = [Select Id from Participant__c WHERE Account_del__c = :thiscase.AccountId AND Program__C = :progORsvc.id  ];
        
        for (Participant__c p : Participants) {
            p.Cancellation_Case__c = thiscase.Id;
            p.Program_Status__c = 'Cancelled';
            p.Cancel_Date__c =  thiscase.Program_End_Date__c;
            p.Enrolled__c = 'No';
            
            update p;
        }
    }
    }
}}}}}}

 

MandyKoolMandyKool

Hi,

 

Could you please explain in detail what you are trying to achieve.

 

From your code its hard to understand it. Also for each condition you are written one SOQL statement. As a best practice you should write the bulk trigger, that will help you even if the data is loaded from data loader. 

 

Please explain in detail what you want to achieve in detail so that we can help you.

SeanSeeSeanSee

We are currently using Cases to accept cancellations for recurring programs for clients.  The process is:

 

  • A cancellation case is entered
  • The Trigger checks to see if
  •  The Type = Cancellation
  •  The Program End Date is not null
  •  The Product or Service is not null
  •  Cancellation = FULL
If it meets this criteria it needs to look up the Program ID, however there Multiple records with the same Program Name.  To identify which record is the correct one I am trying to use the Division Field.  So as an example we have three Programs with the name Service Reminder Program, however each one has a differnt client in the division__c field.
  • Then the multiple SOQL queries were the only way I could think to identify the correct program since the names were the saame
  • Next it needs use that information to lookup the Participant record so it can be updated
  • Then the following fields need to be updated on the Participant Record
        Cancellation_Case__c = thiscase.Id;
                p.Program_Status__c = 'Cancelled';
                p.Cancel_Date__c =  thiscase.Program_End_Date__c;
                p.Enrolled__c =

    Does this help at all?  Thanks so much!

 

MandyKoolMandyKool

Hi Sean,

 

I will try to write a code for you then u can test it.

SeanSeeSeanSee

That's awesome thank you so much.

MandyKoolMandyKool

Hi Sean,

 

Do u have a skype id/gmail id?

 

Sorry, if u dont want u dont give, but here asking questions and interacting is real pain.

Dont knw when salesforce will come up with the chat room for developers. :D