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
Krishna_Krishna_ 

How to write the soql query with select Owner field statement???

Hi to all.,
I have two objects.,
In one object (Contact details) the fields are  firstname ,lastname and Owner.
the second object(View)
I wrote the trigger on View object on after insert.

contact_Details con = [select firstname__c,Lastname__c,owner]

trigger trg_view on View__c (after insert)
{
    for(View__c viewobj: Trigger.New)
    {
  contact_Details__c con = [select id,firstname__c,Lastname__c,owner from contact_Details__c where owner =: CreatedById ];
  viewobj.condaetails__c = con.id;
    }

But this trigger show the error on OWNER FIeld.
then How to compare it and how to write the soql query with select Owner field statement?????

 

Thanks,
Krishna.

SuperfellSuperfell
The field is called ownerId
JmBessonartJmBessonart

Hi, one more thing... your code is wrong because you can't have a SOQL into a FOR statement. If you try to insert more than 100 records at onces, your code will faild. To avoid this you have to write a bulk trigger (using maps and IN clause, check the documentation for more information).

 

Regards,

J.