
Just wondering how i can accomplish the following...
I have a Task on an Opportunity called "Qualify Opportunity". The purpose of this task is to prompt the Sales user to enter values for 4 fields on the Opp. If the User tries to complete the Task, without populating all 4 fields, i want to prevent them from doing so, and have a validation message saying "Task cannot be completed until the following fields have been populated: Field1, Field2, Field3, Field4".
Does anyone have any suggestions on the best way to accomplish this?
Many thanks
4 respostas
Hi Wes,
There are two ways to achieve this functionality i.e.
1) Create a Custom Lookup Field on the Activity Object that looks upto Opportunity Object
Using the Process Builder, you need to automatically update the Custom Lookup field with the Opportunity Name that is selected under the Related To field
Now create a Validation rule on Task and your validation rule will be something like
Assuming you are using subject to indicate the Task is "Qualify Opportunity".
2) If this is not work then please try the below trigger and by this you achieve your functionality.
trigger ErroMessage on Task (before update) {
list<id> opportunityIds = new list<id>();
for(task tsk : trigger.new){
if(tsk.whatid != null){
if(string.valueof(tsk.whatid).substring(0,3) == '006'){
opportunityIds.add(tsk.whatid);
}
}
}
map<id,opportunity> OpportunitytaskMap = new map<id,opportunity>([select id,Field1__c,Field2__c,Field3__c,Field4__c from opportunity where id in :opportunityIds]);
for(task tsk: trigger.new){
if(OpportunitytaskMap.keyset().contains(tsk.whatid)){
if(OpportunitytaskMap.get(tsk.whatid).Field1__c == null && OpportunitytaskMap.get(tsk.whatid).Field2__c== null && OpportunitytaskMap.get(tsk.whatid).Field3__c== null && OpportunitytaskMap.get(tsk.whatid).Field4__c== null && tsk.Status == 'Completed' && tsk.Subject == 'Qualify Opportuntity'){
tsk.adderror('Task cannot be completed until the following fields have been populated: Field1, Field2, Field3, Field4');
}
}
}
}
Thanks
Gyani
www.mirketa.com