I have created trigger on Account object to update the address field based on billing repository object(Custom object).

When I update address in Billing repository object it should be updated on account object when the Account Status field="Active". If status field ="Inactive" it should not be updated on account object. The address details on account object is Custom formula field.

This is my code but its not working .Please can any one help me out at this issue.

trigger Rfleet_Accountaddress on Account (after insert, after update){
        Set<ID> BilingId = new Set<ID>();

Set<ID> accids = new Set<ID>();

        List<Billing_Repository__c> childRecords = [Select id,Name FROM Billing_Repository__c where id=:BilingId];
        list<Account>acclist=[Select id,Rfleet_Id_Alcor__c FROM Account WHERE id in:accids];

        for(Account acc:acclist)
        for(Billing_Repository__c child :childRecords){

            if(trigger.isInsert && acc.Status__c == 'Active'){
                acc.Rfleet_Id_Alcor__c = child.Name;

            else if(trigger.isUpdate && acc.Status__c == 'InActive'){
                acc.Rfleet_Id_Alcor__c = '';

        if(childRecords.size() > 0)
            update acclist;
  • Where you populate your bilingId and accids sets? they are emtpy ATM and nothing will be retrieved into your lists
    – highfive
    Commented Sep 25, 2015 at 7:58
  • status field once active it's populated in address Billing_Repository__c object that means Rfleet_Id_Alcor__c field address of id.
    – Nikitha
    Commented Sep 25, 2015 at 9:05
  • If you had to manually link these records yourself by editing and saving the record, how would you know which Billing_Repository__c record needs to link with the account? Do you match by state, city, zip, or some other field? I think the Billing_Repository__c list will need its query modified to search on that condition instead of matching the BilingId Set.
    – smckitrick
    Commented Sep 25, 2015 at 13:59

1 Answer 1


The problem is that your trigger is firing on the wrong object. From your description you said: "When I update address in Billing repository object it should be updated on a child of the account object." For that to happen, your trigger needs to fire when the Billing_Repository__c object is updated, NOT when Account is updated!

I believe your trigger needs to be defined more like the following:

trigger Rfleet_Accountaddress on Billing_Repository__c (after insert, after update){

Than you can use the related AccountId of the child record to obtain the parent Id's Account number to update (or perhaps the Id of the Rfleet_Id_Record__c?). It appears you then want to update the Rfleet_Id_Record__c's Address (as opposed to the Account record's address) based on what I'm gathering from your code.

It's not totally clear to me what the relationships are, but you may be able to go directly from Billing_Repository__c to what appears to be a child object of Account. Rfleet_Id_Alcor__c I believe is the object with the records you want to make the actual updates to.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .