John Salvetti
John Salvetti

Reputation: 198

Salesforce: Create a Trigger to insert record in custom object

I'm trying to insert a new record into my custom object Commission_C. There are no errors in the code, but nothing happens when Policy_C is updated. What am I doing wrong?

trigger statusUpdate on Policy__c (before update) 
{
    List<Commission__c> comms = new List<Commission__c>();

    for(Policy__c a : trigger.new)
    {
       Commission__c comm = new Commission__c ();
       comm.Name = 'testName'; 
       comms.add(comm);      
    }

    insert comms; 

}

I've googled extensively, and from what I can tell, this seems to be what it should be. I've simplified my code because essentially I just need this part to work to get it all working.

Upvotes: 0

Views: 14583

Answers (4)

kishore
kishore

Reputation: 1

trigger statusUpdate on Policy__c (after Insert) { List comms = new List();

Commission__c comm = new Commission__c ();

for(Policy__c a : trigger.new)
{
   comm.id=a.id;
   comm.Name = 'testName'; 
   comms.add(comm);      
}

insert comms; 

}

Upvotes: 0

tvr
tvr

Reputation: 11

trigger statusUpdate on Policy__c (before update) 
{
    List<Commission__c> comms = new List<Commission__c>();

    for(Policy__c a : trigger.new)
    {
       Commission__c comm = new Commission__c ();
       comm.id=a.id
       comm.Name = 'testName'; 

       comms.add(comm);      
    }

    insert comms; 

}

Upvotes: 1

vijay
vijay

Reputation: 1

trigger statusUpdate on Policy__c (After update) { List comms = new List();

for(Policy__c a : trigger.new)
{
   Commission__c comm = new Commission__c ();
   comm.Policy__c = a.id;
   comm.Name =a. 'testName'; 
   comms.add(comm);      
}

insert comms; 

}

Now You can try this Trigger i think all most it will be work.

Upvotes: 0

PerlDev
PerlDev

Reputation: 437

You need check if you missed any required field of Comission__c, and also check if the security setting is set right. Turn on debug log, you should be able to see what went to wrong.

Upvotes: 0

Related Questions