You need to sign in to do that
Don't have an account?
bhanu_prakash
create a rollup summary to child object
we have two object transcation and balance with lookup relationship,
when ever balance child records is more than 50 which is associated to transtion record
if i try to add 51 need to show error . how can i acheive it ?
we cannot want to install third paty rollup helper or similar ..
Thanks on advance
when ever balance child records is more than 50 which is associated to transtion record
if i try to add 51 need to show error . how can i acheive it ?
trigger UpdateItemRollup on Balance__c (after delete, after insert, after update) { Set<id> TransactionIds = new Set<id>(); List<Transaction__c> tr = new List<Transaction__c>(); List<Balance__c> ba = new List<Balance__c>(); for (Balance__c item : Trigger.new) TransactionIds.add(item.Transaction__c); if (Trigger.isUpdate || Trigger.isDelete) { for (Balance__c item : Trigger.old) TransactionIds.add(item.Transaction__c); } // get a map of the traments with the number of items Map<id,Transaction__c> TransactionMap = new Map<id,Transaction__c>([select id, RollUp_Count__c from Transaction__c where id IN :TransactionIds]); // query the traments and the related inventory items and add the size of the inventory items to the trament's RollUp_Count__c for (Transaction__c tra : [select Id, Name, RollUp_Count__c,(select id from Balance__r) from Transaction__c where Id IN :TransactionIds]) { TransactionMap.get(tra.Id).RollUp_Count__c = tra.Balance__r.size(); // add the value/trament in the map to a list so we can update it tr.add(TransactionMap.get(tra.Id)); } update tr; }Showing error at relationship error
[select Id, Name, RollUp_Count__c,(select id from Balance__r) from Transaction__c where Id IN :TransactionIds]) {
we cannot want to install third paty rollup helper or similar ..
Thanks on advance
Just try to add a if condition at line 20 by checking the size of Balance__r.
if(Balance__r.size() > 50 ){
trigger.addError('You Cannot Insert more than 50 ');
}
else {
//do update
}
What is the error you are getting?
Also make sure that you are using correct child relation name in your query.
Regards,
Kiran
RollUp_Count__c,(select id from Balance__c) from Transaction__c
^
ERROR at Row:1:Column:50
Didn't understand relationship 'Balance__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.
Cross the child Relation ship name once,
Here Employee__c is child object and Project is a Parent object, so use the relationship as Employees__r
Ex: Select Id,Name,(Select Id,Name from Employees__r) From Project__c