You need to sign in to do that
Don't have an account?
Nikitha
hey I'm new to Trigger. I am creating a trigger , whenever iam creating in customer_Detail__c record customer_Detail__c Address Should be copy Account Billing Address. here I have lookup for both account and customer_Detail__c. But im geting err.
trigger AccountCustomerDetail on Customer_Detail__c (before insert) {
set<id>accountId = new set<id>();
for(Customer_Detail__c customer : trigger.new){
accountId.add(customer.id);
}
List<Account> acclist = [Select id,BillingStreet,BillingCity from Account
where id in: accountId];
Map<id,Account>accMap = new Map<id,Account>();
for(Account acc: trigger.new){
accMap.put(acc.id, acc);
}
for(Customer_Detail__c customer : Trigger.new){
customer.APShipping_Street__c = accMap.get(customer.Id).BillingStreet;
customer.AP_Shipping_City__c = accMap.get(customer.Id).BillingCity;
}
}
Err is Line 9 Invalid loop variable type expected Customer_Detail__c was Account. Please help me to solve this.
set<id>accountId = new set<id>();
for(Customer_Detail__c customer : trigger.new){
accountId.add(customer.id);
}
List<Account> acclist = [Select id,BillingStreet,BillingCity from Account
where id in: accountId];
Map<id,Account>accMap = new Map<id,Account>();
for(Account acc: trigger.new){
accMap.put(acc.id, acc);
}
for(Customer_Detail__c customer : Trigger.new){
customer.APShipping_Street__c = accMap.get(customer.Id).BillingStreet;
customer.AP_Shipping_City__c = accMap.get(customer.Id).BillingCity;
}
}
Err is Line 9 Invalid loop variable type expected Customer_Detail__c was Account. Please help me to solve this.
Compare your line number 3 and 9. You will understand why the error is.
If it is the correct answer, please mark it as the best answer, it will help others.
And see the trigger tutorial here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm
All Answers
I think you can have a simple formula field of text type that can hold the address as text, the details are mentioned in the below help article:
>> https://help.salesforce.com/articleView?id=000334673&type=1&mode=1
Below are the steps mentioned for quick reference:
1. Go to Contact page from within Setup.
In Salesforce Classic: Setup | Customize | Contacts | Fields.
In Lightning Experience: Gear Icon | Setup | Object Manager | Contact | 2. Fields & Relationships
3. Click New.
4. Select Formula for the Data Type.
5. Name the field and select Text for the Formula Return Type.
6. Click Next.
7. Enter your formula syntax.
For the Account Billing Address use this formula syntax: For the Account Shipping Address use this formula syntax:
8. Click Next.
9. Add the desired field level security and page layouts in the respective formulas above.
10. Click on Save.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Compare your line number 3 and 9. You will understand why the error is.
If it is the correct answer, please mark it as the best answer, it will help others.
And see the trigger tutorial here: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm
Thanks for the help. I have compared my Line 3 and 9 . and changed trigger.new as accList now I'm err free but as apart of output.after filling my required details in Customer_Detail__c object. I didn't get any output.(Account address). I don't know what to do. can you please recheck my above code.