So, I’m assuming that the relationship between the
Address__c is a lookup from the Account to the address and so if an address is selected upon insert or edit this address should be stamped onto the account?
Under the above assumption you would need to query the
Address__c records based on their id rather than the id of the account itself, in the loop where you check for the
ac.id != null and add the id to a set you should be checking the id in the lookup to the address record, something like:
if((Trigger.isInsert && ac.address__c != null) ||
(Trigger.isUpdate && ac.address__c != null &&
ac.address__c != (Id)Trigger.oldMap.get(ac.id).get('address__c'))
The above logic would then allow you to successfully query the required address records to then stamp the BillingAddress fields with.
Note: i have added logic to the update section of the trigger so that it would only pick up addresses that have actually changed upon update, this may not be the overall desired outcome so different logic to address this may be needed if this is not the case
Another suggestion in this trigger would be to only pull records from the map if they meet the above criteria and they can be found in the map, this would help to stop null pointer issues in the event that an address could not be found.
for(Account a : Trigger.new)
if(a.address__c != null && fetch.containsKey(a.address__c))
Address__c ad = fetch.get(a.address__c);
a.Billingstreet = ad.Billing_Street__c;
a.Billingcity = ad.City__c;
a.Billingstate = ad.State__c;
a.BillingPostalcode = ad.Postal_Code__c;
a.Billingcountry = ad.Country__c;
I hope this helps!