You need to sign in to do that
Don't have an account?
![whatever whatever](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
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;
}
User defined string.
I changed it to an auto number and removed the name population. Still doesn't create.
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);
}
}