Here is the query which will get me all the contacts have HD quality orders.
`Orderc__c[] orders = [SELECT id,customer__c, Customer__r.Number_of_HD_Orders__c,` `Quality_Code__c FROM Orderc__c where Quality_Code__c='HD'];`
then I change use these code to update the number of HD orders for each contact:
for(Orderc__c o: orders){
if(o.Customer__r.Number_of_HD_Orders__c==null)
o.Customer__r.Number_of_HD_Orders__c=0.0;
o.Customer__r.Number_of_HD_Orders__c++;
}
now, the question is how can I update the contacts. as “update orders;” will not update the contacts.
You just need to add all the contacts to a new collection and then update that:
Note this is very rough, doesn’t check for too many contacts in an update etc., but it should get your thinking in the right direction!