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
- :
- Creating Contact Objects Based on Field Data
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Creating Contact Objects Based on Field Data
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-04-2013 01:58 PM
On our Project object, we have a Salesman picklist field, which just lists the last name of the salesman who sold the project. We have a Project Contact object on the Project. We want to use this Salesman field to automatically create a Project Contact looking up to the Contact record that corresponds to that salesman. Right now we're currently doing this by hardcoding the IDs of the contacts - which I understand is bad programming, but still works in production. I want to be able to do this without hardcoding the IDs, however I'm floundering over how to query just the salesmen contacts without having a huge OR statement in the where clause for all their last names, and how to then correctly grab the right salesman contact for each project in a for loop. I know I can't use a query inside the for loop. This sounds like something I'd use Maps for - is it possible to construct a Map where the last name as a String is the key and the Contact object (or ID) is the value? Or is there some other way I should do it? I'm an Apex (and programming in general) newbie. Thanks in advance!
Solved! Go to Solution.
Re: Creating Contact Objects Based on Field Data
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 04:39 AM
You can build a Set<String> of the Contact Names you want to search, then SOQL from Contacts where LastName in :yourSet
This will give you a List<Contact>. From there, if you wanted to create a Map<String, Contact>, or Map<String, Id> you can do something like
for (Contact c : myList){
myMap.put(c.LastName, c.Id);
}
Re: Creating Contact Objects Based on Field Data
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
02-05-2013 10:44 AM
This worked! Thank you so much!

