function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
trictric 

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;

}
}

Best Answer chosen by Admin (Salesforce Developers) 
trictric

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

WorkhardWorkhard

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);

trictric

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;
}

This was selected as the best answer