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
Aryan JhaAryan Jha 

Invalid bind expression type of Opportunity does not match domain of foreign key at line 3 column 49

trigger Opps_trigger1 on Opportunity (after insert) {
List<Contact>conlist=new List<Contact>();
List<Opportunity>oppslist=new List<Opportunity>([SELECT Id,Name,CloseDate FROM Opportunity WHERE AccountID IN:Trigger.new]);
for(Opportunity o:Trigger.new)
{
c.AccountID=o.AccountID;
c.FirstName='aryan';
c.LastName='jha';
conlist.add(c);
}
insert conlist;
}
Maharajan CMaharajan C
Hi Aryan,

The problem is where condition in query. AccountID >>> Id

Please use the below code:
 
trigger Opps_trigger1 on Opportunity (after insert) {
    List<Contact>conlist=new List<Contact>();
    List<Opportunity>oppslist=new List<Opportunity>([SELECT Id,Name,CloseDate FROM Opportunity WHERE Id IN:Trigger.new]);
    for(Opportunity o:Trigger.new)
    {
        contact c = new contact();
        c.AccountID=o.AccountID;
        c.FirstName='aryan';
        c.LastName='jha';
        conlist.add(c);
    }
    insert conlist;
}

I dont't know why you are having this query even it's not used in anywhere.

Thanks,
Maharajan.C
Aryan JhaAryan Jha
Thanks for the help