You need to sign in to do that
Don't have an account?

can anybody Resolve this code getting :Error: Compile Error: Variable does not exist: id at line 7 column 10
Trigger updatecontact on Account(after insert,after update)
{
set<id> set1=new set<id>();
list<contact> aconlist=new list<contact>();
for(account a:Trigger.new)
{
set1.add(a.id);
}
list<contact> conlist=[select id,name,accountid from contact where accountid in:set1];
for(account d:Trigger.new)
{
for(contact c:conlist)
{
if(d.id==c.accountid)
{
d.industry=c.department;
aconlist.add(c);
}
}
}
update aconlist;
}
{
set<id> set1=new set<id>();
list<contact> aconlist=new list<contact>();
for(account a:Trigger.new)
{
set1.add(a.id);
}
list<contact> conlist=[select id,name,accountid from contact where accountid in:set1];
for(account d:Trigger.new)
{
for(contact c:conlist)
{
if(d.id==c.accountid)
{
d.industry=c.department;
aconlist.add(c);
}
}
}
update aconlist;
}
I've re-writen your code with some improvments. Please find it below with comments.
I've also removed the aconlist contact list and the update because as you are not making an changes to the contact, there is no point updating it.
while updating a record I am getting this error on Account user interface.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger updatecontact caused an unexpected exception, contact your administrator: updatecontact: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.updatecontact: line 17, column 1
Have a look at the code i posted above.
I Tried you code but I am getting this error while insertion on Account user interface
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger updatecontact caused an unexpected exception, contact your administrator: updatecontact: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.updatecontact: line 17, column 1
Cheers
Have a look at this code:
Trigger updatecontact on Account(before insert,before update){
list<contact> conlist=[select id,name,accountid, Department from contact where accountid in : Trigger.new];
for(contact c: conlist){
Trigger.newMap.get(c.accountid).industry = c.department;
}
}
plz check the code:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger updatecontact caused an unexpected exception, contact your administrator: updatecontact: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.updatecontact: line 4, column 1
Same Error I am getting again and again after tried you sent the last code
But still I am getting this Error .what is the reason behind this?