0

Can we default Account field's name in Contact object? My requirement is I want to set the Account's value (in Contact) to the logged in user's Company name. I tried this code but it didn't worked. gave an error: Field $Action.accountId.New does not exist. Check spelling

<apex:page standardController="Contact" 
action="{!URLFOR($Action.accountId.New,$ObjectType.accountId,[con3=$User.companyname],true)}">
</apex:page>

Apologies for posting this question again, but since the problem is still existing, hence posting it again.

  • Is this question with respect to customer community users? – crmprogdev Dec 19 '14 at 18:48
  • Not sure about that.I need all new contacts in my org should have same Account name. All the users in the org already have the same company name and so no matter which user logs in, the company name would be same. I have also replaced the "NEW" button on Leads which defaults the company name to logged in user's company name so that whenever a New Lead is created, the Company field is auto filled with logged in User's company name. I want this same functionality in Contact for Account field. I already tried the same approach for Contact's Account field (posted in the question) but didn't worked – Salesforce Learner Dec 20 '14 at 6:30
0

The error message has nothing to do with what you want to do. Its related to your method. The message is telling you that the field $Action.accountId.New doesn't exist on your Contact Object. This makes sense in that you can't create a new accountId on a Contact. You can relate an AccountId to a Contact, or more accurately a Contact to an Account (contact having a look-up to the Account or being a child of it), but the Account has to first exist.

I have some more comments on what you want to do/are doing that you may want to think about. I don't know what you're use case is or if this is something you're simply "playing" with in a Dev Org. as an exercise. Salesforce is primarily a B2B platform and sometimes used for B2C (individual customer). When a User creates a Lead, it's to create a "prospect" for which a salesman in his Org might be able to sell something to another someone at another business, who for obvious reasons, presumably doesn't work for his company/Org. For that reason, it makes no sense to me that you'd want to assign a User's Company Name to the Lead, even if the Lead is an individual (B2C) sale prospect.

Similarly, in doing what you're attempting with Contacts, you're essentially creating contacts that would presumably all work for your Org/Company. Likewise, these contacts would all be assigned to the same company Account. Even if they do work for the same (your) company, most would have their own unique employee ID or company account number of some kind. As I said, I don't at all know what you're doing, so it's not for me to say that it's "wrong" to do it or that there's no use case for it.

That said, be aware that Users are created from Contacts, especially when it comes to customer community users. All Users have a ContactId. The real info you're looking for that you can count on for accuracy would come from a User's Contact info, not from their User Profile. So if there's a related AccountId, you'd find it in their Contact info; something which you can't get directly from User without running a query using a custom controller.

For additional info you may want to look at these relationships closer in Workbench and also refer to the Standard Objects section of the Object Reference to the various fields that exist in each of them.

  • Thanks for your inputs. We are currently on B2B model. We are actually not using Standard Account in our org. Hence we are not relating any Contact with the Account. We need all our Contact's Account to be same, which will logged in User's Company name. I thought this will be done by creating a VF page for "New" Button of Contact. – Salesforce Learner Dec 22 '14 at 11:45
  • No, you're going to need to create an actual account someplace before you can do that if you're going to use an AccountId. You could possibly create a custom controller to use with your VF page that allowed you to access both Accounts and Contacts from the same page. Remote Objects (W15) would possibly do the same thing if the Account exists. – crmprogdev Dec 22 '14 at 16:12
  • Do you have Users from different companies/Accounts using the same SF instance? That part wasn't clear to me. If so, you'll need to set up accounts for each of them. – crmprogdev Dec 22 '14 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.