The error message indicates that you attempted to use a 'dot' to retrieve a value that doesn't exist.
trigger BusinessDivisionOpportunity on Opportunity (before insert)
{
Map<String, String> myPickListMap = Constants.businessDivisionMap;
for (Opportunity o : Trigger.new)
{
// the .get() from the map will retrieve the value associated with the key
// which is your accountId. The value returned (based on the way your map
// is defined (<string, string>) will be a string value.
// So, your code is attempting to retrieve a field named Business_Division__c
// from a string, which can't be done.
// o.Business_Division__c = myPickListMap.get(o.AccountId).Business_Division__c;
// try this - it presumes that the value in the map is the "business division"
o.Business_Division__c = myPickListMap.get(o.AccountId);
}
}
Update
It seems that what you're trying to accomplish is to just copy some data from the parent Account onto the Opportunity. This can most easily and simply be accomplished using a workflow rule that executes on new Opportunity records and performs a field update on the record using the relationship to the parent Account.
Unless there's some complicated logic in the Constants
class for determination of those business division values, a workflow field update might be a far simpler solution. Edit: It's not simpler in this case. A second answer added with caveats.
Alternatively, if this is the scenario (copy the field data from the parent account) that you are trying to accomplish must be done via trigger - my implementation would begin like this:
trigger BusinessDivisionOpportunity on Opportunity (before insert) {
// collect the account ID values from these opportunities
Set<Id> relatedAccountIdSet = new Set<Id>();
for (Opportunity o : Trigger.new) {
if (o.AccountId != null) {
relatedAccountIdSet.add(o.AccountId);
}
}
// query the Account details
Map<Id, Account> relatedAccountsMap = new Map<Id, Account>([SELECT Id
, Business_Division__c
FROM Account
WHERE Id IN :relatedAccountIdSet]);
// set the business division on the opportunity based on what's in the field on the account
for (Opportunity o : Trigger.new) {
if (o.AccountId == null) {
continue; // skip to the next opportunity in the list
}
Account parentAccount = relatedAccountsMap.get(o.AccountId);
o.Business_Division__c = parentAccount.Business_Division__c;
}
}