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
tengeltengel 

Detail record creation trigger failing

Hi all,

 

I've been pouring over the boards here trying to figure out why I can't get my trigger to create a detail record on master record creation.

 

Master Record = Policy__c

Detail Record = Transaction__c

 

Error message when trying to save trigger:

Error: Compile Error: Incorrect SObject type: Policy__c should be Transaction__c at line 1 column 1

 

Trigger code:

trigger createTransaction on Policy__c (after insert) {

    List<Transaction__c> addTA = new List<Transaction__c>();
    for (Policy__c p : Trigger.new)
    {
        Transaction__c t = new Transaction__c();
        t.Related_Policy__c = p.Id;
        addTA.add(t);
    }
    insert addTA;
}

I sincerely appreciate any guidance.

Best Answer chosen by Admin (Salesforce Developers) 
zachelrathzachelrath

Did you accidentally create the trigger on the Transaction__c object instead of the Policy__c object? Try creating a new Trigger, only make sure that it is on the Policy__c object. 

All Answers

zachelrathzachelrath

Did you accidentally create the trigger on the Transaction__c object instead of the Policy__c object? Try creating a new Trigger, only make sure that it is on the Policy__c object. 

This was selected as the best answer
tengeltengel

Arrrrrrrrrrrrgggggggghhhhhhhhh!

 

Can you tell I'm a noob?

 

Thank you for your response, my first trigger is working!