+ Start a Discussion
sekhar passamsekhar passam 

While creating account record I want to set the status to Open by default and after creation I want to change status to complete if linked contact records are 10 or greater than 10?


While creating account record I want to set the status to Open by default and after creation, I want to change status to complete if linked contact records are 10 or greater than 10?
Shubham NandwanaShubham Nandwana
Hi sekhar,
I assume your status is a picklist field, so you can set a default value directly in 'fields and relationships' section of Account in object manager.
For performing any operation after insertion of a record, you can write a after trigger on Account where you can get no of contacts linked and update the field.
Check the below code:
trigger TriggerAccount on Account (after insert) {
   for(Account a:Trigger.New){
    List<Contact> contactsLinked=[select Id from contact where AccountId=:a.Id];
   }
   if(contactsLinked.size()>=10){
     status='complete';
   }
}

Select it as best answer if it helps.

Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts
sekhar passamsekhar passam
Hai 
Shubham Nandwana, can't we do in this without the trigger .like configuration side 
Thanks @regards 
Sekhar p
Sujeet PatelSujeet Patel
I am not sure but We can do this by using process builder.
May be i will work for you
Shubham NandwanaShubham Nandwana

Hi sekhar,
You can try doing it using process builder+flow.

Process: To trigger when account is updated, and calls the flow
Flow: Lookup into all contacts for that account,and update account accordingly.
You can refer to below links.
http://succeedwithsalesforce.com/using-process-and-flows-to-update-parent-record-based-on-all-related-child-records/
https://automationchampion.com/learning-flow/
 

Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts