You need to sign in to do that
Don't have an account?
Michal Skuhra
Trigger to retrieve record from another object
Hi all,
i´ll try describe my problem. I have 2 objects, Standart (Opportunity) and Custom (Point_of_delivery__c). Both have same fields (EIC_code__c, Number_code__c). but value are only in custom object (Point_of_delivery__c).
In Opportunity IF i set EIC_code__c, then I need retrieve Number_code__c
FROM custom object Point_od_delivery__c which have right EIC_code__c.
My code is right.
trigger T22 on Opportunity (before insert, before update) {
Opportunity[] opportunity = Trigger.new;
Point_of_delivery__c Number_code;
Number_code =
[SELECT Number_code__c
FROM Point_of_delivery__c
WHERE Point_of_delivery__c.EIC_code__c = :opportunity[0].EIC_code__c
LIMIT 1];
opportunity[0].Number_code__c = Number_code.Number_code__c;
}
BUT:
If I set wrong EIC_code__c which doesnt exist, I have error. I need set default value if Number_code is null.
i´ll try describe my problem. I have 2 objects, Standart (Opportunity) and Custom (Point_of_delivery__c). Both have same fields (EIC_code__c, Number_code__c). but value are only in custom object (Point_of_delivery__c).
In Opportunity IF i set EIC_code__c, then I need retrieve Number_code__c
FROM custom object Point_od_delivery__c which have right EIC_code__c.
My code is right.
trigger T22 on Opportunity (before insert, before update) {
Opportunity[] opportunity = Trigger.new;
Point_of_delivery__c Number_code;
Number_code =
[SELECT Number_code__c
FROM Point_of_delivery__c
WHERE Point_of_delivery__c.EIC_code__c = :opportunity[0].EIC_code__c
LIMIT 1];
opportunity[0].Number_code__c = Number_code.Number_code__c;
}
BUT:
If I set wrong EIC_code__c which doesnt exist, I have error. I need set default value if Number_code is null.
All Answers
Also there's core error in your trigger - if trigger will process more than 1 Opportunity, only first will be processed correctly.
Could you tell me what type has EIC_code__c field ?
EIC code is number type
Picklist is String, etc