• SfdcDevLJ
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 8
    Replies
trigger matchUniqueID on Account(Before Insert, Before Update) 
{
    Map <Id, Id> uniqueIdMap = new Map <Id, Id> ();

    for (Account account : trigger.new)
    {
        uniqueIdMap.put(account.UniqueID__c, null);
    }

    for (Account account : [SELECT Id, UniqueID__c FROM Account WHERE UniqueID__c IN :uniqueIdMap.keySet()])
    {
        uniqueIdMap.put(uniqueIdMap.get(account.UniqueID__c), account.Id);
    }

    List <Account> existingAccountsToUpdate = new List <Account> ();

    for (Account account : trigger.new)
    {
        if (uniqueIdMap.containsKey(account.UniqueID__c) && account.Classcode__c == null)
        {
            // Existing account found
            Account existingAccount = new Account(Id = uniqueIdMap.get(account.UniqueID__c));
            // Set other field values to update
            // existingAccount.SOMEFIELD = SOMEVALUE;
            existingAccountsToUpdate.add(existingAccount);
        }
       
    }

    update existingAccountsToUpdate;
}

I am doing data upserts using jitterbit and we use SalesforceID as our external ID. However, some records coming in dont have a ID yet so in that case i want to match those records based on another field called UniqueID__c. I have the trigger pasted above.. but it's pulling the UniqueID__c and tries to match with SalesforceID. How can i fix this. 

 Execution of BeforeUpdate caused by: System.StringException: Invalid id: 1234355: External entry point

trigger AccountDuplicateTrigger on Account (before insert, before update) {
    //Create map of existing person accounts that don't have a externalID
	map<Id, Account> existingAccountMap = new Map<ID, Account>([Select ID, Name, externalID__c
                                                                FROM Account 
                                                                WHERE isPersonAccount=True AND externalID__c = Null]);
    //For new trigger accounts check if Name exists in existingAccountmap
    for(Account a : trigger.new) {
        map<ID, Account>newAccountMap = new Map<ID, Account>([SELECT ID, Name, externalID__c FROM Account
                                                                 WHERE ID IN :trigger.newMap.keySet()]);
    //If new account name matches an existing account then put UUID in the existing account
        if(a.name = existingAccountMap.get(a.ID).Name)
        {
          .........
        }
    
    }
}

We have an integration with a legacy system and we use an Unique ExternalID to send personAccount upserts back and forth between salesforce and the legacy system using JItterbit.
However, that externalID is provided by the legacy system, When a new record is created in Salesforce it is sent to the legacy system where it gets the Unique ExternalID. Problem is on the way back to Salesforce since the ExternalID isn't already on the Account, Jitterbit creates a new duplicate account. I was workign on the code above but not sure if it will get me what i'm trying to accomplish.
trigger matchUniqueID on Account(Before Insert, Before Update) 
{
    Map <Id, Id> uniqueIdMap = new Map <Id, Id> ();

    for (Account account : trigger.new)
    {
        uniqueIdMap.put(account.UniqueID__c, null);
    }

    for (Account account : [SELECT Id, UniqueID__c FROM Account WHERE UniqueID__c IN :uniqueIdMap.keySet()])
    {
        uniqueIdMap.put(uniqueIdMap.get(account.UniqueID__c), account.Id);
    }

    List <Account> existingAccountsToUpdate = new List <Account> ();

    for (Account account : trigger.new)
    {
        if (uniqueIdMap.containsKey(account.UniqueID__c) && account.Classcode__c == null)
        {
            // Existing account found
            Account existingAccount = new Account(Id = uniqueIdMap.get(account.UniqueID__c));
            // Set other field values to update
            // existingAccount.SOMEFIELD = SOMEVALUE;
            existingAccountsToUpdate.add(existingAccount);
        }
       
    }

    update existingAccountsToUpdate;
}

I am doing data upserts using jitterbit and we use SalesforceID as our external ID. However, some records coming in dont have a ID yet so in that case i want to match those records based on another field called UniqueID__c. I have the trigger pasted above.. but it's pulling the UniqueID__c and tries to match with SalesforceID. How can i fix this. 

 Execution of BeforeUpdate caused by: System.StringException: Invalid id: 1234355: External entry point

trigger AccountDuplicateTrigger on Account (before insert, before update) {
    //Create map of existing person accounts that don't have a externalID
	map<Id, Account> existingAccountMap = new Map<ID, Account>([Select ID, Name, externalID__c
                                                                FROM Account 
                                                                WHERE isPersonAccount=True AND externalID__c = Null]);
    //For new trigger accounts check if Name exists in existingAccountmap
    for(Account a : trigger.new) {
        map<ID, Account>newAccountMap = new Map<ID, Account>([SELECT ID, Name, externalID__c FROM Account
                                                                 WHERE ID IN :trigger.newMap.keySet()]);
    //If new account name matches an existing account then put UUID in the existing account
        if(a.name = existingAccountMap.get(a.ID).Name)
        {
          .........
        }
    
    }
}

We have an integration with a legacy system and we use an Unique ExternalID to send personAccount upserts back and forth between salesforce and the legacy system using JItterbit.
However, that externalID is provided by the legacy system, When a new record is created in Salesforce it is sent to the legacy system where it gets the Unique ExternalID. Problem is on the way back to Salesforce since the ExternalID isn't already on the Account, Jitterbit creates a new duplicate account. I was workign on the code above but not sure if it will get me what i'm trying to accomplish.