You need to sign in to do that
Don't have an account?

Apex Trigger Creation to Sum Case field from Work Order Formula Currency Field
Hello,
First time question here from a Apex Newbie.....
I have a standard object (Case) which will have a currency field, that I want to update from a rollup summary field on a custom object (Work Order) called Price__c. The Price__c field on the Work Order Custom Object totals all work order work detail lines, and I want the Price__c field to update the currency field on the case record.
So far I have the following code written, but I am getting an Invalid Ofreign Key error when tring to quick save. Can anyone help me here......Thank you in advance
trigger DoRollup on SVMXC__Service_Order__c (after insert, after update, after delete, after undelete) {
Set<Id> setCaseId=new Set<Id>();
Map<string,decimal> CaseWithTotalWorkOrders=new Map<string,decimal>();
for(SVMXC__Service_Order__c mst:Trigger.New){
if(Case.Total_Billable_Work_Orders__c!=null){
setCaseId.add(mst.SVMXC__Service_Order__c.Price__c);
}
}
}
First time question here from a Apex Newbie.....
I have a standard object (Case) which will have a currency field, that I want to update from a rollup summary field on a custom object (Work Order) called Price__c. The Price__c field on the Work Order Custom Object totals all work order work detail lines, and I want the Price__c field to update the currency field on the case record.
So far I have the following code written, but I am getting an Invalid Ofreign Key error when tring to quick save. Can anyone help me here......Thank you in advance
trigger DoRollup on SVMXC__Service_Order__c (after insert, after update, after delete, after undelete) {
Set<Id> setCaseId=new Set<Id>();
Map<string,decimal> CaseWithTotalWorkOrders=new Map<string,decimal>();
for(SVMXC__Service_Order__c mst:Trigger.New){
if(Case.Total_Billable_Work_Orders__c!=null){
setCaseId.add(mst.SVMXC__Service_Order__c.Price__c);
}
}
}
I forgot to add semicolon,try this one :-
If this helps,please mark it as best answer to help others :)
All Answers
Can you assign appropriate Recody type for
Set<Id> setCaseId=new Set<Id>();
Id,You can use for record id only,But here You trying to add some Price__C ,It may number or decimal.
http://salesforce.stackexchange.com/questions/15244/access-field-on-lookup-relationship-in-trigger
Thank you again,
mst.SVMXC__Service_Order__r.Price__c
mst.SVMXC__Service_Orders__r.Price__c
trigger DoRollup on SVMXC__Service_Order__c (after insert, after update, after delete, after undelete) {
Set<Id> setCaseId=new Set<Id>();
Map<string,decimal> CaseWithTotalWorkOrders=new Map<string,decimal>();
for(SVMXC__Service_Order__c mst:Trigger.New){
if(Case.Total_Billable_Work_Orders__c!=null){
mst.SVMXC__Service_Order__r.Price__c;
}
}
}
The error I am getting is: Error: Compile Error: Invalid foreign key relationship: SVMXC__Service_Order__c.SVMXC__Service_Order__r at line 6 column 6
How Case and your custom object SVMXC__Service_Order__c are related ,I mean based on which field.
So,there must be a field on Service_Order__c which would be referencing to Case object,could you check which field is that ??
try below code :-
If this helps,please mark it as best answer to help others :)
I forgot to add semicolon,try this one :-
If this helps,please mark it as best answer to help others :)
it seems your field datatypes are not correct,will have to see then I can modify it accordingly.But,I gave you the approach as how you can do it.
Thank you very much for your work and time. I will play with the field types and learn a little more about which field types are not allowed in code as I never ran into this issue before. Thanks again.