Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Re: Contact-Creating Trigger : Where Did It Go?
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Contact-Cr eating Trigger : Where Did It Go?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 02:50 AM
Hi,
I've created a new custom object, called obj_Single_Account,
and added it a trigger that's supposed to create a new Contact_Object,
called obj_Cntct, of standard type Contact , every time upon user's
creating of a new obj_Single_Account object:
trigger trg_Contact_Create on obj_Single_Account__c (after insert) {
List<Contact> obj_ContactList = new List<Contact>();
for (obj_Single_Account__c obj_SA : Trigger.New) {
Contact obj_Cntct = new Contact ();
obj_Cntct.Description = obj_SA.txt_Company_Name__c;
obj_Cntct.Phone=obj_SA.txt_Phone_Number__c;
obj_ContactList.add(obj_Cntct);
}
try {
insert obj_ContactList;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
Now, I've also created some TEST_Class -- which, according to the
run_log seemed to have worked out correctly (i.e., w/o error),
but when I switched to USER_Mode interface (via my Internet browser)
and (as a USER) created a new obj_Single_Account, this new object
did NOT seem to have any CONTACT-type object attached.
Would anyone know why ?
Thanks
George
Re: Contact-Cr eating Trigger : Where Did It Go?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 03:14 AM
As you are catching the error and just outputting debug, you are effectively swallowing the error. The code will appear to complete successfully even though the insert failed.
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter
I don't respond to private messages/emails asking for help.
Take the Bob Buzzard Sobject Fields quiz.
Re: Contact-Cr eating Trigger : Where Did It Go?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 03:21 AM
Capisci.
Will look into it.
Thanks
George
Re: Contact-Cr eating Trigger : Where Did It Go?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 03:46 AM
Attempt # 2 : Did NOT seem to work either :-(
I've fixed the code like so:
trigger trg_Contact_Create on obj_Single_Account__c (after insert) {
List<Contact> obj_ContactList = new List<Contact>();
for (obj_Single_Account__c obj_SA : Trigger.New) {
Contact obj_Cntct = new Contact ();
obj_Cntct.FirstName = 'First';
obj_Cntct.LastName = 'Last';
obj_Cntct.Description = obj_SA.txt_Company_Name__c;
obj_Cntct.Phone=obj_SA.txt_Phone_Number__c;
obj_ContactList.add(obj_Cntct);
}
try {
insert obj_ContactList;
} finally { }
// catch (system.Dmlexception e) {
// system.debug (e);
// }
}
The TEST_Class returned a "success",
but I still could NOT find this supposedly-new Contact_Object
at either the obj_Single_Account object or the "Contacts_TAB"
as a user.
Any ideas ?
Thanks
George
Re: Contact-Cr eating Trigger : Where Did It Go?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 04:04 AM
You haven't specified the obj_Single_Account__c that the contact belongs to anywhere. You've copied the name and phone number, but you need to relate the objects to each other by filling in the lookup/master detail that relates this contact to the parent single account.
I don't think the contact will appear in the contacts tab because you haven't specified the AccountId field - this means its a private contact
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter
I don't respond to private messages/emails asking for help.
Take the Bob Buzzard Sobject Fields quiz.
Re: Contact-Cr eating Trigger : Where Did It Go?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-07-2013 05:28 AM
OK.
I've tried to add the following statements to my trigger - separately of course,
right before the other field-value assignments:
(1) First, I tried the VARIABLE name:
obj_Cntct.MasterRefFields = obj_Single_Account;
The compiler / syntax checker returned :
Error: Compile Error: Variable does not exist: obj_Single_Account at line 8 column 45
(2) Then, I thought, it might require the Custom name:
obj_Cntct.MasterRefFields = obj_Single_Account__c;
The compiler / syntax checker returned :
Error: Compile Error: Variable does not exist: obj_Single_Account__c at line 8 column 45
(3) Next, I thought it might require quotation marks:
obj_Cntct.MasterRefFields = 'obj_Single_Account';
The compiler / syntax checker returned :
Error: Compile Error: Invalid field MasterRefFields for SObject Contact at line 8 column 17
(4) Thus, I thought, maybe the Custom name should be specified:
obj_Cntct.MasterRefFields = 'obj_Single_Account__c';
The compiler / syntax checker returned :
Error: Compile Error: Invalid field MasterRefFields for SObject Contact at line 8 column 17
Now, other online code examples have suggested I should use some sort of an ID field;
I assumed it'd be some unique number to be assigned by the internal database mechanism,
but I wouldn't know how to use it - should I simply copy it into some equivalent field in the
new-contact object ?
Puzzled,
George
Re: Contact-Cr eating Trigger : Where Did It Go?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-07-2013 08:24 AM
The instance of obj_Single_Account__c is in the iterator variable 'obj_SA'. That will be the parent of the newly created contact. So the code should be:
obj_Cntct.MasterRefFields = obj_SA;
However, I also think you'll need to use the __c notation for your MasterRefFields as its a custom field - e.g.
obj_Cntct.MasterRefFields__c = obj_SA;
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter
I don't respond to private messages/emails asking for help.
Take the Bob Buzzard Sobject Fields quiz.

