You need to sign in to do that
Don't have an account?

Trigger that creates Location Record using shipping address from Account Record when the account is created
Hello, I'm trying to make a trigger that A) creates a Location Record (named Location 1) when a new Account Record is made, and B) automatically populates the new Location Record's address information using the new Account Record's shipping information. The problem that I seem to be having is that there's an error thrown when I try to compile complaining that the variables that I used for the Location object do not exist, when in fact they do. I think the problem is that there is some kind of difference between creating a location for the account and creating a location record, since the user is not asked their address when a location is added to the account. Thanks in advance!
trigger SetsLocationAddress on Account (after insert) {
for(Account accountInLoop : Trigger.new )
{
//tests if account is type Customer
if( accountInLoop.salesReach__Account_Type__c == 'Customer - Partner' || accountInLoop.salesReach__Account_Type__c == 'Customer - Direct')
{
//creates new location record based on shipping address on account record
Location newLocation = new Location();
newLocation.salesReach__Location__c = 'Location 1';
newLocation.salesReach__Street__c = accountInLoop.salesReach__Address__c;
newLocation.salesReach__City__c = accountInLoop.salesReach__City__c;
newLocation.salesReach__State__c = accountInLoop.salesReach__State__c;
newLocation.salesReach__Zip_Code__c = accountInLoop.salesReach__ZIP__c;
}
}
}
trigger SetsLocationAddress on Account (after insert) {
for(Account accountInLoop : Trigger.new )
{
//tests if account is type Customer
if( accountInLoop.salesReach__Account_Type__c == 'Customer - Partner' || accountInLoop.salesReach__Account_Type__c == 'Customer - Direct')
{
//creates new location record based on shipping address on account record
Location newLocation = new Location();
newLocation.salesReach__Location__c = 'Location 1';
newLocation.salesReach__Street__c = accountInLoop.salesReach__Address__c;
newLocation.salesReach__City__c = accountInLoop.salesReach__City__c;
newLocation.salesReach__State__c = accountInLoop.salesReach__State__c;
newLocation.salesReach__Zip_Code__c = accountInLoop.salesReach__ZIP__c;
}
}
}
All Answers