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
Lori Antone 1Lori Antone 1 

Workflow or Trigger

Hi,

I'm new to the development side so any help would be appreciated.

I have created a custom object Prospects, whose standard field is Prospect Name. I would like Prospect Name to autopopulate with the Account Name that the custom object is associated with. (Account is a lookup on the custom object). I first tried this with a workflow and it is not updating when I create a new record. My next thought is that this needs to be a trigger, but I do not have enough experience writing these. Is this even possible? Any suggestions would be appreciated.
Pankaj_GanwaniPankaj_Ganwani
Hi Lori,

You can achieve this using workflow rule. Select *Field Update* action in workflow and select Prospect Name from dropdown. In formula field, Use Account__r.Name. I think it will work.
VinojVinoj
Hi Lori,

There isn't a great way to do this as the 'Name' fields is required and you cannot use a formula to set it's value.  You can build a workflow, but you would still have to enter a 'dummy' name to get past the required field validation.  Have a look at this thread - https://developer.salesforce.com/forums/ForumsMain?id=906F00000008oR8IAI
Rahul BorgaonkarRahul Borgaonkar
Hi,

To change Prospect Name with Account name, you have to insert Prospect record first and then update again with Account name again.

Prospect Name should not be Auto Number though.

Regards,

Rahul
Lori Antone 1Lori Antone 1
The workflow did not work. To me that is the way it should work.

Thanks for the work around Vinoj., I'll give that a shot.
Leslie  KismartoniLeslie Kismartoni
Well, this is hackish, but it may work:
  1. You could use the url parameter "&name=TEMPNAME" which would populate the propect object name until the record saved.
    • You'd need to override the links to that object... 
  2. Then a trigger that switches the name fires after save
I've got code to do this somewhere... Lemme see what I can dig up.

BTW - is this Lori from near Chicago?
Lori Antone 1Lori Antone 1
Thanks! If you come across the code I'd be interested.

The reason I felt this could work is it is done on our opportunity name, but I know that is a standard object. However, I noticed when I click New Opportunity in the contact or account this works and in the Opportunity Name field it says [Set by workflow rule]. However, if I go directly to the opportunity page and click new it does not autopopulate this. So maybe this is controlled by a url on the button instead?

No, not from Chicago.... from Denver! :)

 
Leslie  KismartoniLeslie Kismartoni
Hi Lori,

Well since you aren't from Chicago ... I can't help you...

;)

After taking some time on vacation and thinking about this a bit, I figured it might actually be easier to just handle via some onclick javascript.
Here's the assumptions that I'm working with and how I coded the potential solution:
  • You have a custom object OR standard object.
  • Both are related to Account and Contact objects.
  • You'd like to have the Account Name appear in the custom object's (or standard object's) name field when clicking the "New ..." button off the related lists from the Account or Contact pages.
What I did: 
  • Just used the standard Account/Contact --> Opportunity objects. 
  • Override the button of the Opportunity List view on the Account and Contact pages.

Instructions for Opportunity Override:

Creating Buttons:
You're going to create 2 buttons for the Opportunity: 1 that comes from an Account page and one that comes from a Contact page.
  • Navigate to the Opportunity objects custom button's and links:
    • Setup --> Customize --> Button, Links, and Actions
  • Click on "New Button or Link"
  • Give it a Label, name, and Description
    • Make the label semi-distinct: "New Account Opportunity" 
  • Select the "List Page Button" from the radio buttons
  • On the Dropdown, select "Display in existing window without sidebar or headers"
  • Content Source will be a "URL"
  • In the text area, past the following:
/006/e?retURL=%2F{!Account.Id}&accid={!Account.Id}&opp3={!Account.Name}

If you're coming from a contact: Follow all the steps above, but change the label to something distinct "New Contact Opportunity", and paste the following:
 
/006/e?lookupcmpgn=1&retURL=%2F{!Contact.Id}&accid={!Account.Id}&conid={!Contact.Id}&opp6={!Contact.LeadSource}&opp3={!Account.Name}


Adding the buttons to the page layouts
Once you've created the buttons, we just need to disable the standard "New" button listviews and add the custom button to the related list. I'm going to gloss over a bunch of page layout editing stuff (since you may have them by specific user, etc...)
  • Get to the page layout editor page. (Setup --> Customize --> Account --> Page Layouts)
  • Find the Opportunity related list and click on the "wrench" in the tab bar's right hand corner. This should spawn a modal.
  • Click the "+" next to the buttons section and expand the buttons picker.
    • Uncheck the "new" button.
    • Select the button for the specific object (If you're editing the related list off the account view, use the New Account Opportunity" button...)
  • Click OK, then click save.
Do the same thing for the other object (Contact)

Once you click the custom button off the Account or Contact, you should be all set... You should see the Account Name pulled into the Opportunity Name.


Note for Custom Objects
For custom objects, some tweaking of the URL parameters might be necessary - instead of opp3, you'd have to use name, for example. 


Hope this helps. If it does, please mark this as a correct solution...