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
Lago S.p.a.Lago S.p.a. 

Error in Apex trigger for creating a new object

Hi, I'm trying to build a trigger that create an object when a checkbox cames to true value , here is the code :

trigger CreateTask on Container_Trigger__c (after update)
{
    //Map<ID,Book__c> BookInsert = new Map<ID,Book__c>
    //{
       
   // };
  for (Integer i = 0; i < Trigger.new.size(); i++)  
   {
        if (Trigger.new[i].Enable_TriggerBook__c != Trigger.old[i].Enable_TriggerBook__c && Trigger.old[i].Enable_TriggerBook__c == false)
      {
          Task_apt__c obj = new Task_apt__c();
          //obj.type__c = Post Vendita;
          //obj.responsabile__c = 003a000001v34bp;
          //obj.RecordType = 01Ia0000002Rcl2;
          obj.phone__c = 000000000;
          insert obj;
          //BookInsert.put(obj.id,obj);
      }
   }
}

The error is : Error: Compile Error: Incorrect SObject type: Container_Trigger__c should be task_apt__c at line 1 column 1
I really have no idea how to solve..please give me a hand :)
Thanks in advance
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Hi,

I think you have changed the trigger name after creation.
Please create trigger with same object name.

if this answers your question, mark this as best answer.

Thanks,
N.J
Vinit_KumarVinit_Kumar
The error seems weird to me .

Can you copy the code and delete this Trigger and start a new one.Another thing make sure the API name of the object is correct on which you are writing the Trigger!!
Lago S.p.a.Lago S.p.a.
Hi Everybody, thanks for the comments, now it works fine!
Have a nice day!
Vinit_KumarVinit_Kumar
Happy to help !!

Go ahead and mark it as best answer to help others :)