You need to sign in to do that
Don't have an account?
Write a trigger to create related contact when an Account is created and associate that contact with that account
Hello guys
I am having above scenario but i am not able to findout perfect solution and i was trying but it is not working.
could someone help me out..
I am having above scenario but i am not able to findout perfect solution and i was trying but it is not working.
could someone help me out..
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
All Answers
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
Prateek Joshi 33
i have written the same code but just for extra caution i came here and copy paste it in my dev console but it still showing the same error : "Variable does not exist: FirstName". I have never faced this error, Can you bother to tell what is the problem cause i have write this code many times in past but i never faced this problem.
Please check if the field 'FirstName' exist in the contact object. Also make sure the field api name is 'FirstName'.
public class CountContactOnAccount {
Public Static void countContact(List<Contact> conList){
List<id> accId = new List<id>();
for(Contact con : conList){
if(con.AccountId != Null){
accId.add(con.accountId);
}
}
List<Account> accList = new List<Account>();
for(Account acc : [Select id,(Select id from Contacts) from account Where id IN: accId]){
acc.NumberofLocations__c = acc.Contacts.size();
accList.add(acc);
}
if(!accList.isEmpty()){
update accList;
}
}
}
@Govind Kumar