You need to sign in to do that
Don't have an account?
Bencredible
Update account and company info on custom object
I have searched the boards looking for an answer, and can't quite find what I'm looking for.
We have a custom object called 'domains' which is simply a form listing off any domains that a user may have purchased through us. Each contact is associated with an account, a company and an office. In the cases section when we select a contact it auto-populates the account and office information. In this new custom object it doesn't seem to grab the account or office info.
Tried creating a trigger to update these fields, but was not successful. I'm a bit of a SalesForce n00b and would greatly appreciate any help in creating this function. Basically, when we select a contact the contacts account and office information should auto populate those fields, either on save or when it is selected.
Help?
Thanks,
Benjamin Higginbotham
We have a custom object called 'domains' which is simply a form listing off any domains that a user may have purchased through us. Each contact is associated with an account, a company and an office. In the cases section when we select a contact it auto-populates the account and office information. In this new custom object it doesn't seem to grab the account or office info.
Tried creating a trigger to update these fields, but was not successful. I'm a bit of a SalesForce n00b and would greatly appreciate any help in creating this function. Basically, when we select a contact the contacts account and office information should auto populate those fields, either on save or when it is selected.
Help?
Thanks,
Benjamin Higginbotham
Here's a walkthrough of it:
1: Declare this trigger to execute whenever a Domain__c is created or updated
2: Run a loop through each Domain__c that was created or updated (because sometimes things happen in batch)
3: Grab the Contact's ID that the user entered (this assumes your field name is called Contact__c, you may need to adjust this)
4: Run a query to the Contact table and find that associated account ID
5: Store this account ID in the Account__c field (again, your field name may be different)
Ryan
All Answers
What about setting up the account and office fields on your domain object as formulas? Formulas can now reference related objects. The formula could be something like this:
Contact__r.Account.Country
This would retrieve the Country of the Contact's associated account.
Ryan
Right now by manually selecting the account, company and office it is attaching properly... Just not automated like I would like. Gotta make it simple for the users :)
Thanks,
B
Leave the Account and Office fields as lookups but make them read-only (via Field-level security). This way, they will only show up when viewing a domain, not when creating or editing one, but the Contact field will show on both view and edit. Then setup an Apex trigger that will update these fields based on the Contact that was entered. This way those fields will be automatically updated for you.
Here's an example trigger that updates the Account field on a "Thing" object based on the Contact field.
Ryan
I created a sandbox because it appears that I can't create a new trigger in anything but...
I modified the code to read as follows:
Pretty much changing out 'thing' for either domain or domains depending on the field used... But when I run it I get an error 'Compile Error: expecting a left angle bracket, found 'Contacts' at line 4 column 14'
Tried adding brackets around 'Contacts' to no avail.
Thoughts?
Here's a walkthrough of it:
1: Declare this trigger to execute whenever a Domain__c is created or updated
2: Run a loop through each Domain__c that was created or updated (because sometimes things happen in batch)
3: Grab the Contact's ID that the user entered (this assumes your field name is called Contact__c, you may need to adjust this)
4: Run a query to the Contact table and find that associated account ID
5: Store this account ID in the Account__c field (again, your field name may be different)
Ryan
Thank you!
So this APEX Trigger works great in the sandbox. After reading a bit I learned that I needed Eclipse to push to production. Installed that and got it linked to my sandbox. The trigger I added to the sandbox downloaded. Yeah!
I right-click on the trigger, select 'deploy' and enter all my info... Get to a validate screen and it comes back with a 0% validation.
After reading up on the forums a bit it sounded like I just needed to fire off the trigger a couple of times. So I went through, added a couple of domains, saw the account and company info get updated (w00t) but I was unable to get Eclipse to say that it was more than 0% verified.
Not sure if it helps, but this is the code I ended up using:
I must be doing something very simple wrong.
Thoughts?
If not, fire me a screenshot of the validation error at rmarples at salesforce.com.
Ryan
Message Edited by ryan_marples on 11-06-2008 07:45 AM
Ben,
Did you get this to work? If so, could you outline the steps you took from beginning to end?
Thanks!
Hi Ryan, I work with Ben and this worked perfectly. Thank you so much.
Testing is the most confusing part of the SalesForce development process. Could you point me towards a few good sources to learn what needs to be done in order to get through testing.
Thanks again!