• Gardenway
  • NEWBIE
  • 25 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 10
    Replies

Hi,

 

I am trying to update my contact phone from the Account phone.  However, in trying to bulkify the code, I keep running into problems with the mapping code.  I get an error:  Incompatible key type scheme.SObjectField for Map<Id,Account> for the line which attempts to pull the account out of the map based on the account id key that is stored in contact object.

 

Any help is greatly appreciated.

 

trigger SetPhone on Contact (before insert, before update) {
    Set<Id> accountIds = new Set<Id>();
    
    for (Contact c: Trigger.new){
        accountIds.add(c.Account.Id);
    }
    
    Map<Id, Account> accountPhoneMap =
        new Map<Id,Account>(
            [Select Id, Phone FROM Account WHERE Id IN: accountIds]);
        
    for (Contact c: Trigger.new){
        if(c.Phone == null) {
            Account a = accountPhoneMap.get(contact.Account.Id);
//Error prior line: Incompatible key type scheme.SObjectField for Map<Id,Account>
            c.Phone = a.Phone;
        }
    }
}

 Thank you,

 

John

I created a full sandbox.  I then logged in and found that only one of my two triggers are in the sandbox.

 

In my production environment, is see two triggers under setup->customize->contacts->triggers

 

However, in my sandbox, I only see one trigger.

 

I previously developed and deployed two triggers.  Why would only one show up in my new sandbox?

 

thank you,

 

John

Hi,

 

I am trying to update my contact phone from the Account phone.  However, in trying to bulkify the code, I keep running into problems with the mapping code.  I get an error:  Incompatible key type scheme.SObjectField for Map<Id,Account> for the line which attempts to pull the account out of the map based on the account id key that is stored in contact object.

 

Any help is greatly appreciated.

 

trigger SetPhone on Contact (before insert, before update) {
    Set<Id> accountIds = new Set<Id>();
    
    for (Contact c: Trigger.new){
        accountIds.add(c.Account.Id);
    }
    
    Map<Id, Account> accountPhoneMap =
        new Map<Id,Account>(
            [Select Id, Phone FROM Account WHERE Id IN: accountIds]);
        
    for (Contact c: Trigger.new){
        if(c.Phone == null) {
            Account a = accountPhoneMap.get(contact.Account.Id);
//Error prior line: Incompatible key type scheme.SObjectField for Map<Id,Account>
            c.Phone = a.Phone;
        }
    }
}

 Thank you,

 

John

Hi,

 

I'm trying to make a trigger that updates the contact when created if the account is left blank. I want contact to be assigned a default account is left blank. However right now an account is already automatically created of the contact's last name and assigned to that contact. 

 

Is there a way to get rid of this trigger so I can assign my default account to the contact if blank?

 

Thanks,

Sam

We have a custom Bill To object that populates address information onto the account. We have this snippet of code -

 

 

          a.BillingStreet = btst.Street_1__c!=null?btst.Street_1__c:''+' '+btst.Street_2__c!=null?btst.Street_2__c:'';

 

It is working correctly for Street 1, but Street 2 is not copying from Bill To to the Account. What could be the problem?

Hi,

 

Could any one help me on which text format is using Salesforce by default.

 

Thanks !!!