function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ivan WinzerIvan Winzer 

Push contact field data on account record

So the company has an ID that is being pushed from a third party to a contact record in SF. But we also need this info on the account the contact is associated with (mind you we have one contact to one account *it was already setup that way before i got the job*). So im trying to buidl a trigger that when a data is updated on the contact it will push that info onto the assoicated account. Below is what i have peiced together so far but i keep getting this 'missing EOF at (parentobjlist) error when i try to save it. Can anyone help...

 

trigger pushRevelID on Contact (after insert, after update) {

 

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

List<Id> listIds = new List<Id>();

List<Contact> newRevel = new Contact[]{};

 

for (Contact childObj : Trigger.new {

listIds.add(childObj.Account);

newRevel.put(childObj.Account, Contact);

}

 

parentObjList = [SELECT id, Name FROM Account WHERE ID IN :listIds]; (ERROR HAPPENING ON THIS LINE)

 

for (Account acct : parentObjList){

acct.Revel_ID__c = newRevel.get(acct.Id).Revel_ID__c;

}

 

update parentObjectList;

 

}


Best Answer chosen by Ivan Winzer
vmanumachu1.393650924860069E12vmanumachu1.393650924860069E12
Made changes to your code and it saves fine now. Didnt check the logic though

trigger pushRevelID on Contact (after insert, after update) {

List<Account> parentObjList = new List<Account>();
List<Id> listIds = new List<Id>();
Map <Id,Contact> newRevel = new Map<Id,Contact>();

for (Contact childObj : Trigger.new) {
    listIds.add(childObj.AccountId);
    newRevel.put(childObj.AccountId, childObj);
}

parentObjList = [SELECT id, Name FROM Account WHERE ID IN :listIds];

for (Account acct : parentObjList){
     acct.Revel_ID__c = newRevel.get(acct.Id).Revel_ID__c;
}

update parentObjList;

}

All Answers

Avidev9Avidev9
Well looks like
this should be a map

List < Contact > newRevel = new Contact[] {};

So it should be something like

Map < IdContact > newRevel = new Map<Id,Contact>();


Ivan WinzerIvan Winzer
trigger pushRevelID on Contact (after insert, after update) {

List<Account> parentObjList = new List<Account>();
List<Id> listIds = new List<Id>();
Map <Id,Contact> newRevel = new Map<Id,Contact>();

for (Contact childObj : Trigger.new {
    listIds.add(childObj.Account);
    newRevel.put(childObj.Account, Contact);
}

parentObjList = [SELECT id, Name FROM Account WHERE ID IN :listIds];

for (Account acct : parentObjList){
    acct.Revel_ID__c = newRevel.get(acct.Id).Revel_ID__c;
}

update parentObjectList;

}

So i changed that but the error on line 12 stll exist.
vmanumachu1.393650924860069E12vmanumachu1.393650924860069E12
Made changes to your code and it saves fine now. Didnt check the logic though

trigger pushRevelID on Contact (after insert, after update) {

List<Account> parentObjList = new List<Account>();
List<Id> listIds = new List<Id>();
Map <Id,Contact> newRevel = new Map<Id,Contact>();

for (Contact childObj : Trigger.new) {
    listIds.add(childObj.AccountId);
    newRevel.put(childObj.AccountId, childObj);
}

parentObjList = [SELECT id, Name FROM Account WHERE ID IN :listIds];

for (Account acct : parentObjList){
     acct.Revel_ID__c = newRevel.get(acct.Id).Revel_ID__c;
}

update parentObjList;

}
This was selected as the best answer
Ivan WinzerIvan Winzer
Awesome thanks vmanumachu1 it saved and worked. Now i just need to write a test and i'll be set. Thanks again...