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
whateverwhatever 

Custom Object Creation From Trigger.

Hey,

 

      I've been having problems creating a custom object from an apex trigger on leads. Essentially I need a few extra objects created (and populated) if a lead is converted. The following trigger was just a test to see if creating a custom object when the convert button is triggerd would work - however it doesn't. Any help would be appreciated.

 

trigger LeadConvert on Lead (before update) {

    // insert a custom object associated with the contact
    GIC_Deal__c obj = new GIC_Deal__c();
    obj.Name = 'temp';
    insert obj;
}

 

ZetaZeta
Is the Record Name field autogenerated or a user-defined string ?
whateverwhatever

User defined string.

 

I changed it to an auto number and removed the name population. Still doesn't create.

SteveBowerSteveBower

I'll assume that you're working in a Development environment and you actually have permissions to create such objects.

 

The next question I'd ask is:  Ok, so what *is* happening.  And, I think the answer is that you don't really know.

 

My bet is that for some reason it's not ok to create that object type with only the name field.  Perhaps you've got some other required field, perhaps a validation rule is preventing it from being created, perhaps you've got some other trigger firing which stops it, etc.

 

To find you you should enclose your code with a Try/Catch block and use system.debug to dump the Exception information that, I think, might explain it.

 

 

trigger LeadConvert on Lead (before update) { try {

// insert a custom object associated with the contact GIC_Deal__c obj = new GIC_Deal__c(); obj.Name = 'temp'; insert obj;

} catch (Exception e) {

system.debug('Exception in Trigger LeadConvert: ' + e);

}

 

}