+ Start a Discussion
SMGSFDCDEVSMGSFDCDEV 

CASE Trigger: Assign Date field from Custom Object to custom field on CASE object

Hello Force.com Development community

I am trying to create a trigger that will assign a Date (Redemption_Cutoff_Date__c) from one of my custom objects: Funds__c to the custom field: Redemption_Cutoff_Date__c on the CASE object.  The Trigger compiles without errors, however it is not work where the Redemption Cutoff Date from the Fund object is assigned to the CASE.Redemption_Cutoff_Date__c field.

 

Can someone please let me know where I am going wrong here:

 

trigger UpdateRedemptionCutoffDateonCASE on Case (before update) {

for(Case c: Trigger.new){


if(c.isRedemption__c = true && c.RecordTypeId == '012M00000004MTS'){


List<Funds__c> fund = new List<Funds__c>();
List<Case> cs = new List<Case>();

fund = [Select Funds__c.Id, Redemption_Cutoff_Date__c from Funds__c f
where Funds__c.Id = :c.Fund__c];


if(fund.size()>1){
fund[0].Redemption_Cutoff_Date__c = cs[0].Redemption_Cutoff_Date__c;
}
}
}
}

 

Best Answer chosen by Admin (Salesforce Developers) 
MikeGillMikeGill

Ok so you select the fund at the case object and you want to bring values from this object over to a field on the case?

 

if that's the case - you should be able to achieve this using workflow rules.

All Answers

MikeGillMikeGill

How are Case and Funds linked?

 

Is fund a lookup on the case object or a related list?

MikeGillMikeGill

Not sure your trigger is architected in the best way - however just tested this and it works.

 

	if (trigger.size ==1){
		
		for (Fund__c fund: [select Redemption_Cutofption_Cutoff_Date__c from Fund__c where Case__c =: Trigger.new[0].Id]){
			Trigger.new[0].Redemption_Cutoff_Date__c = fund.Redemption_Cutofption_Cutoff_Date__c;
		}
		
	}

 

Hope this moves you in the right direction.

SMGSFDCDEVSMGSFDCDEV

Hi Mike

Thanks for the reply.  really appreciate your contribution.

 

I tested your trigger and received an error around the Case__c field.  The Case object contains the Fund__c custom field.  The Fund object does not contain a case custom lookup relationship field to the Case object.

 

I did find your where clause interesting though: "where Case__c =: Trigger.new[0].Id". never you create create a trigger like that.

MikeGillMikeGill

Ok so you select the fund at the case object and you want to bring values from this object over to a field on the case?

 

if that's the case - you should be able to achieve this using workflow rules.

This was selected as the best answer
SMGSFDCDEVSMGSFDCDEV

Hi Mike

Thanks for that.  you are right.  A workflow rule with a field update that uses a formula to retrieve the Date field from the Fund object solved the problem.

 

Thanks again for your help

MikeGillMikeGill

Hey that's cool - but we love coding!