You need to sign in to do that
Don't have an account?
Rev Nivas
custom rollup summary
hi,
scenario is implement rollup summary to a lookup relationship
i have taken account---parent
contact---child
my code is______
public class triggeronContact
{
public list<id> accidlist{get; set;}
public triggeroncontact(){
accidlist = new list<id>();
}
public void Trigconmeth(list<contact> connew)
{
if(trigger.isinsert || trigger.isundelete)
{
for(contact con : connew)
{
if(con.AccountId != null) {
accidlist.add(con.accountid);
system.debug('*****accidlist are*****:'+accidlist);
}
}
}
if(trigger.isdelete)
{
for(contact condel : [select id from contact] )
{
accidlist.add(condel.accountid);
}
}
list<account> accupdatelist = new list<account>();
for(account acc : [select total_contacts__c,(select id from contacts)from account where id =: accidlist])
{
acc.total_contacts__c = acc.contacts.size();
accupdatelist.add(acc);
}
try
{
update accupdatelist;
}
catch(exception e)
{
system.debug('Exception:'+e.getMessage());
}
}
}
while executing below error is coming...line number 13 means here... if(trigger.isinsert || trigger.isundelete)
scenario is implement rollup summary to a lookup relationship
i have taken account---parent
contact---child
my code is______
public class triggeronContact
{
public list<id> accidlist{get; set;}
public triggeroncontact(){
accidlist = new list<id>();
}
public void Trigconmeth(list<contact> connew)
{
if(trigger.isinsert || trigger.isundelete)
{
for(contact con : connew)
{
if(con.AccountId != null) {
accidlist.add(con.accountid);
system.debug('*****accidlist are*****:'+accidlist);
}
}
}
if(trigger.isdelete)
{
for(contact condel : [select id from contact] )
{
accidlist.add(condel.accountid);
}
}
list<account> accupdatelist = new list<account>();
for(account acc : [select total_contacts__c,(select id from contacts)from account where id =: accidlist])
{
acc.total_contacts__c = acc.contacts.size();
accupdatelist.add(acc);
}
try
{
update accupdatelist;
}
catch(exception e)
{
system.debug('Exception:'+e.getMessage());
}
}
}
while executing below error is coming...line number 13 means here... if(trigger.isinsert || trigger.isundelete)
{
for(contact condel : [select id from contact] )
{
accidlist.add(condel.accountid);
}
}
Change your query and get Account ID.
like - Select id, AccountId from contact where AccountId != null
Please mark as a Best Answer if Error is not coming ye on your Line no 13.