You need to sign in to do that
Don't have an account?
Shruthi MN 88
Database.update
Hi Everyone,
Can you help be with the below code:
1. Create an Account Record with Name =”Eternus”. Create associated contacts. Create a Custom field called Contact Count on Account . Query on Contact
where Account.Name =”Eternus” and count the associated contacts. Update the custom field on Accounts with that count..
I am not getting the count of the records:
public class Accassoccon {
public static void accountacc(){
Account a = new Account();
a.Name = 'Eternus';
Database.insert(a,false);
system.debug('The inserted account is:' +a);
list<Account > recordIDs = new list<Account >();
List<Account> accountlist1 = [Select Id, ContactCount__c, (Select Id From Contacts) From Account where Id =: recordIDs]; //get a list of the corresponding accounts
for(Account account : accountlist1) {
if(account.Contacts == null) continue;
account.ContactCount__c = account.Contacts.size();
}
Database.update(accountList1,false);
}
}
Can you help be with the below code:
1. Create an Account Record with Name =”Eternus”. Create associated contacts. Create a Custom field called Contact Count on Account . Query on Contact
where Account.Name =”Eternus” and count the associated contacts. Update the custom field on Accounts with that count..
I am not getting the count of the records:
public class Accassoccon {
public static void accountacc(){
Account a = new Account();
a.Name = 'Eternus';
Database.insert(a,false);
system.debug('The inserted account is:' +a);
list<Account > recordIDs = new list<Account >();
List<Account> accountlist1 = [Select Id, ContactCount__c, (Select Id From Contacts) From Account where Id =: recordIDs]; //get a list of the corresponding accounts
for(Account account : accountlist1) {
if(account.Contacts == null) continue;
account.ContactCount__c = account.Contacts.size();
}
Database.update(accountList1,false);
}
}
If this information helps, please mark the answer as best. Thank you
Hi Shruthi,
Try with this:
I hope this will help you.
Thanks!