You need to sign in to do that
Don't have an account?
Vinu Varghese
I am getting the following soql query in trigger. would you help me to trace the error.
trigger InvoiceTotal on Invoice_Item__c (after insert, after update) {
set<ID> setId = new set<ID>();
List<invoice__c> lstInvoice = new List<invoice__c>();
for(Invoice_Item__c fndId :trigger.new){
setId.add(fndId.invoice__c);
}
for(invoice__c parentInvoice :[select id, name, invoice_no__c, (select id, invoice__c, Total_Price__c, name from Invoice_Item__c) from Invoice__c where Invoice__c.id in :setId]){
Invoice__c Inv = new Invoice__c();
inv.id = parentInvoice.id;
inv.Total_amount__c =parentInvoice.Total_price__c;
lstInvoice.add(inv);
}
update lstInvoice;
}
set<ID> setId = new set<ID>();
List<invoice__c> lstInvoice = new List<invoice__c>();
for(Invoice_Item__c fndId :trigger.new){
setId.add(fndId.invoice__c);
}
for(invoice__c parentInvoice :[select id, name, invoice_no__c, (select id, invoice__c, Total_Price__c, name from Invoice_Item__c) from Invoice__c where Invoice__c.id in :setId]){
Invoice__c Inv = new Invoice__c();
inv.id = parentInvoice.id;
inv.Total_amount__c =parentInvoice.Total_price__c;
lstInvoice.add(inv);
}
update lstInvoice;
}
You have to grab whats inside of the relationship, like this:
You could sum every total of the children, I dont know if it is your objective:
inv.Total_amount__c +=item.Total_amount__c
All Answers
You could use Invoice__c Inv = new Invoice__c(Id=parentInvoice.id); instead of
Invoice__c Inv = new Invoice__c();
inv.id = parentInvoice.id;
But please share the error so I can be of more assistance.
If this helps please like and if it solves your issue mark as correct as it may help others.
invoice__c, Total_Price__c, name from Invoice_Item__c) from Invoice__c ^ ERROR at Row:1:Column:84 Didn't understand relationship 'Invoice_Item__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the ‘__r’ after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
For example if you use a subquery of Account to search their contacts you dont use From Contact, you use From Contacts, as that is the relationship name defined on the custom relationship field.
trigger InvoiceTotal on Invoice_Item__c (after insert, after update) {
set<ID> setId = new set<ID>();
List<invoice__c> lstInvoice = new List<invoice__c>();
for(Invoice_Item__c fndId :trigger.new){
setId.add(fndId.invoice__c);
}
for(invoice__c parentInvoice :[select id, name, invoice_no__c, (select id, invoice__c, Total_Price__c, name from invoice_Items) from Invoice__c where id in :setId]){
Invoice__c Inv = new Invoice__c();
inv.id = parentInvoice.id;
inv.Total_amount__c =parentInvoice.Total_price__c;
lstInvoice.add(inv);
}
update lstInvoice;
}
[select id, name, invoice_no__c, (select id, invoice__c, Total_Price__c, name from invoice_Items__r) from Invoice__c where id in :setId]
If it helps please like and mark as correct, it may help others.
Regards.
Line 12 inv.Total_amount__c =parentInvoice.Total_price__c;
Total_price__c is in the inner loop as you can see in the query.
Variable does not exist : Total_price__c
You have to grab whats inside of the relationship, like this:
You could sum every total of the children, I dont know if it is your objective:
inv.Total_amount__c +=item.Total_amount__c