You need to sign in to do that
Don't have an account?
Bob
Adding date ranges to a trigger
I need to add multiple date ranges to my trigger below or maybe create a apex class to perform this function.
I have two objects Unit__c & Warranty__c . There are date fields on both object (Unit__c, ShipDateForm__c) (Warranty__c, WrntyStartDate__c).
I need my trigger or apex class to compare the ShipDateForm__c and the WrntyStartDate__c. can I do a IF statement with 3 conditions, because i need to check another field to.
This is what it looks like below, but it doesn't work. Any help would be appreciated
CODE SNIPPET:
if (newUnit .Warranty_Type__c == null && newUnit .ShipDateForm__c <= '2011-12-30' && newUnit .WrntyStartDate__c <= '2011-12-30' ) {
Warranty__c product = wrntyMap.get(newUnit.Product__c);
FULL TRIGGER:
trigger Trigger_UpdateWarranties on Unit__c (before insert, before update ) {
// Step 1: Create a set of all products of Units to query
Set<String> allwrnty = new Set<String>();
for (Unit__c newUnit : Trigger.new) {
if (newUnit.Product__c != null) {
allwrnty.add(newUnit.Product__c); }
}
// Step 2: Query for all the Units in Step 1
List<Warranty__c> potentialproduct = [SELECT Id, Name,Warranty_Active_Date__c, Product__c FROM Warranty__c
WHERE Product__c IN :allwrnty];
// Step 3: Make a Map that lets you search for units by product
Map<String, Warranty__c> wrntyMap = new Map<String, Warranty__c>();
for (Warranty__c w : potentialproduct) {
wrntyMap.put(w.Product__c, w);
}
// Step 4: Get the matching Warranty in the Map by product!
for (Unit__c newUnit : Trigger.new) {
if (newUnit .Warranty_Type__c == null && newUnit .ShipDateForm__c <= '2011-12-30' && newUnit .WrntyStartDate__c <= '2011-12-30' ) {
Warranty__c product = wrntyMap.get(newUnit.Product__c);
if (product != null) {
newUnit.Warranty_Type__c = product.Id;
}
}
}
}
I have two objects Unit__c & Warranty__c . There are date fields on both object (Unit__c, ShipDateForm__c) (Warranty__c, WrntyStartDate__c).
I need my trigger or apex class to compare the ShipDateForm__c and the WrntyStartDate__c. can I do a IF statement with 3 conditions, because i need to check another field to.
This is what it looks like below, but it doesn't work. Any help would be appreciated
CODE SNIPPET:
if (newUnit .Warranty_Type__c == null && newUnit .ShipDateForm__c <= '2011-12-30' && newUnit .WrntyStartDate__c <= '2011-12-30' ) {
Warranty__c product = wrntyMap.get(newUnit.Product__c);
FULL TRIGGER:
trigger Trigger_UpdateWarranties on Unit__c (before insert, before update ) {
// Step 1: Create a set of all products of Units to query
Set<String> allwrnty = new Set<String>();
for (Unit__c newUnit : Trigger.new) {
if (newUnit.Product__c != null) {
allwrnty.add(newUnit.Product__c); }
}
// Step 2: Query for all the Units in Step 1
List<Warranty__c> potentialproduct = [SELECT Id, Name,Warranty_Active_Date__c, Product__c FROM Warranty__c
WHERE Product__c IN :allwrnty];
// Step 3: Make a Map that lets you search for units by product
Map<String, Warranty__c> wrntyMap = new Map<String, Warranty__c>();
for (Warranty__c w : potentialproduct) {
wrntyMap.put(w.Product__c, w);
}
// Step 4: Get the matching Warranty in the Map by product!
for (Unit__c newUnit : Trigger.new) {
if (newUnit .Warranty_Type__c == null && newUnit .ShipDateForm__c <= '2011-12-30' && newUnit .WrntyStartDate__c <= '2011-12-30' ) {
Warranty__c product = wrntyMap.get(newUnit.Product__c);
if (product != null) {
newUnit.Warranty_Type__c = product.Id;
}
}
}
}
What exactly are you trying to do here? Could you just explain it in words without any code yet? Thanks