• matthew_hicks_1
  • NEWBIE
  • 15 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi All, I trying to write my first trigger, failing hard. I would really appreciate any help.  Thank you, Matt

My Scenario: 
I have a custom object named Commerciant Customer Record that has a lookup field for Accounts. Every Account only has 1 Commerciant Customer Record that is imported into Salesforce. I have a lookup field on my Account object named Syspro Customer Record that needs to be passed the Id of the Commerciant Customer Record so I can link the two and write field formulas. Below are my field names and my trigger, I do not get any errors when saving it. Is my logic off and why does nothing happen when I create a new Commerciant Customer Record and link it to an account. 

Account = my parent object
Commerciant Customer Record (CommercientSF__ArCustomer__c) = child object
CommercientSF__AccountID__c = Lookup(Account) on Commerciant Customer Record Object
Syspro_Customer_Record__c = Lookup(Commerciant Customer Record) on Account object (the field I am trying up update)

trigger CustomerID on Account(after insert) {
if(trigger.isInsert)
  {
    set<Id> custId = new set<ID>();
    for(Account a : Trigger.New)
    {
       custID.add(a.Syspro_Customer_Record__c);
    }
    Map<Id, Id> custToAccountMap = new Map<Id, Id>();
    for(CommercientSF__ArCustomer__c c :[select Id, CommercientSF__AccountID__c from CommercientSF__ArCustomer__c where id in: custID])
    {
       custToAccountMap.put(c.id,c.CommercientSF__AccountID__c);
    }
    for(Account a: trigger.new)
    {
       a.Syspro_Customer_Record__c = custToAccountMap.get(a.Syspro_Customer_Record__c);
    }
   }
}


Hi All, I trying to write my first trigger, failing hard. I would really appreciate any help.  Thank you, Matt

My Scenario: 
I have a custom object named Commerciant Customer Record that has a lookup field for Accounts. Every Account only has 1 Commerciant Customer Record that is imported into Salesforce. I have a lookup field on my Account object named Syspro Customer Record that needs to be passed the Id of the Commerciant Customer Record so I can link the two and write field formulas. Below are my field names and my trigger, I do not get any errors when saving it. Is my logic off and why does nothing happen when I create a new Commerciant Customer Record and link it to an account. 

Account = my parent object
Commerciant Customer Record (CommercientSF__ArCustomer__c) = child object
CommercientSF__AccountID__c = Lookup(Account) on Commerciant Customer Record Object
Syspro_Customer_Record__c = Lookup(Commerciant Customer Record) on Account object (the field I am trying up update)

trigger CustomerID on Account(after insert) {
if(trigger.isInsert)
  {
    set<Id> custId = new set<ID>();
    for(Account a : Trigger.New)
    {
       custID.add(a.Syspro_Customer_Record__c);
    }
    Map<Id, Id> custToAccountMap = new Map<Id, Id>();
    for(CommercientSF__ArCustomer__c c :[select Id, CommercientSF__AccountID__c from CommercientSF__ArCustomer__c where id in: custID])
    {
       custToAccountMap.put(c.id,c.CommercientSF__AccountID__c);
    }
    for(Account a: trigger.new)
    {
       a.Syspro_Customer_Record__c = custToAccountMap.get(a.Syspro_Customer_Record__c);
    }
   }
}