function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
himanshu huske 7himanshu huske 7 

Change status field value on condition

Hi Guys,
Please help me in code.
I have some fields like fName, lNmae,Email, DrivingLiscience etc and a status__c field(values: not opened, in progress, compleated ) .
if all fields are populated then status__c = 'compleated' 
else status__c ='inprogress';
SwethaSwetha (Salesforce Developers) 
HI Himanshu,
You can create a formula field named Status__c and use the below criteria
IF(AND(ISBLANK(fName)),AND(ISBLANK(lNmae)),...."completed","inprogress")

Incase you do not want to create a new formula field for status and just want to update existing field, you can use  Workflow rule + field update to achieve this.

See approach mentioned in Https://salesforce.stackexchange.com/questions/74239/formula-to-update-field-with-another-field-value-if-empty/74241
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
himanshu huske 7himanshu huske 7
hi Swetha,
i want to do it through class level,
could you please help
 
SwethaSwetha (Salesforce Developers) 
HI himanshu,
As you can accomplish the functionality using the salesforce out of the box functionality, is there any specific reason why you want to go with custom code?

If coding is mandatory, I recommend writing a trigger as mentioned in below article:
https://developer.salesforce.com/forums/?id=906F00000008z93IAA

You need to fetch the desired fields from the SOQL query and loop over trigger.new to check if the fields are null and then update the picklist value to status__c = 'completed' 
else status__c ='inprogress'


Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you