trigger UpdateAmount on Contact (after insert, after update) {
Map<ID, Account> parentAcc = new Map<ID, Account>();
List<Id> listIds = new List<Id>();
for (Contact childObj : Trigger.new {
listIds.add(childObj.Account);
}
parentAcc = new Map<Id, Account>([SELECT Id, Name, Phone FROM Account WHERE ID IN :listIds]);
for (Contact c: Trigger:new){
Account myParentOpp = parentAcc.get(c.Account__c);
myParentOpp.Phone = c.Phone; //Update parent record as necessary.
}
update parentAcc.values();
}
HI!!!! I am writing like this acc=[Select id,Total__c,(Select id,Amount__c From Contact) From Account Where ID IN :listIds];
But its raising an error as below
Didn't understand relationship 'Contact' 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.
All Answers
Here is one sample for you,
I am writing like this
acc=[Select id,Total__c,(Select id,Amount__c From Contact) From Account Where ID IN :listIds];
But its raising an error as below
Didn't understand relationship 'Contact' 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.
What to do please help me.
But i hve another doubt why it is Account not Accounts