You need to sign in to do that
Don't have an account?
Trigger Error
Hi ,
I have created custom object accountnames and lookupfield on the accountnames object to the account object .
Name of the lookup field is Account__c which does a lookup to the related account and make changes to another custom field named upsellopporunity on acccount .It is not a complete trigger but while compiling I got the following error on the line in red
Compile Error: Incompatible element type Id for collection of SOBJECT:AccountName__c at line 6 column 1
trigger AccountNames on AccountName__c (before insert) {
set<AccountName__c>lap=new set<AccountName__c>();
for(AccountName__c acc:trigger.new)
lap.add(acc.account__c);
}
map<id,account> must=new map<id,account>();
for(account l:[select id,name,upsellopportunity__c from account where id in:lap])
{
must.put(l.id,l);
}
for(accountname__c dry:trigger.new)
{
account asp=must.get(dry.accountname__c).upsellopportunity__c;
}
}
Hi,
Thank for yopu advice but it is working even with the sets.Since I was adding reference id's so i changed the set type also to id's and now everything is working fine.I have my code on the forum and I am marking it as solved incase it might help somebody.,
Thanks,
Tric
trigger AccountNames on AccountName__c (before insert) {
set<id>lap=new set<id>();
for(AccountName__c acc:trigger.new)
{
lap.add(acc.account__c);
}
map<id,account> must=new map<id,account>();
list<account> slap=new list<account>();
for(account l:[select id,name,upsellopportunity__c from account where id in:lap])
{
//l.upsellopportunity__c='true';
must.put(l.id,l);
}
map<id,account> asp=new map<id,account>();
for(accountname__c dry:trigger.new)
{
must.get(dry.account__c).upsellopportunity__c='Yes';
slap.add(must.get(dry.account__c));
}
update slap;
}
All Answers
Hi,
You are geting this error because you want to add an id value inside the Object. You can use Map insted of set.Use like this
Map<Id,AccountName__c> lap=new Map<AccountName__c>();
for(AccountName__c acc:trigger.new)
lap.add(acc.id , acc);
Hi,
Thank for yopu advice but it is working even with the sets.Since I was adding reference id's so i changed the set type also to id's and now everything is working fine.I have my code on the forum and I am marking it as solved incase it might help somebody.,
Thanks,
Tric
trigger AccountNames on AccountName__c (before insert) {
set<id>lap=new set<id>();
for(AccountName__c acc:trigger.new)
{
lap.add(acc.account__c);
}
map<id,account> must=new map<id,account>();
list<account> slap=new list<account>();
for(account l:[select id,name,upsellopportunity__c from account where id in:lap])
{
//l.upsellopportunity__c='true';
must.put(l.id,l);
}
map<id,account> asp=new map<id,account>();
for(accountname__c dry:trigger.new)
{
must.get(dry.account__c).upsellopportunity__c='Yes';
slap.add(must.get(dry.account__c));
}
update slap;
}