You need to sign in to do that
Don't have an account?
Supriya P 24
Wanted to update a filed in opportunity(multiple status) with different condition
Hi All,
Could you please help me for below scenerio.
Opportunity object has field called "review" and it has 3 picklist values.
there are 4 different fields which needs to be considered to update the field.
1. when al the 4 fields are true then update "review" field = pass
2 When 2 or less field are true then update "review" field= reject
3. when 3 of the fields are true then update "review" field= awaiting.
Thanks in advance
Could you please help me for below scenerio.
Opportunity object has field called "review" and it has 3 picklist values.
there are 4 different fields which needs to be considered to update the field.
1. when al the 4 fields are true then update "review" field = pass
2 When 2 or less field are true then update "review" field= reject
3. when 3 of the fields are true then update "review" field= awaiting.
Thanks in advance
Use the below trigger for your requirement it may helpful for you
trigger TriggerForUpdateOpportunity on Opportunity(before insert, before update) {
if( (trigger.isUpdate && trigger.isBefore) || (trigger.isInsert && trigger.isBefore)){
for(Opportunity opp : trigger.new){
// Count how many input field has true value
Integer count = 0;
if(opp.Active_1__c == true){
count = count + 1;
}
if(opp.Active_2__c == true){
count = count + 1;
}
if(opp.Active_3__c == true){
count = count + 1;
}
if(opp.Active_4__c == true){
count = count + 1;
}
// Update Review__c field value according to count
if(count == 4){
opp.Review__c = 'pass';
}
if(count <= 2){
opp.Review__c = 'reject';
}
if(count == 3){
opp.Review__c = 'awaiting';
}
}
}
}
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com
All Answers
Use the below trigger for your requirement it may helpful for you
trigger TriggerForUpdateOpportunity on Opportunity(before insert, before update) {
if( (trigger.isUpdate && trigger.isBefore) || (trigger.isInsert && trigger.isBefore)){
for(Opportunity opp : trigger.new){
// Count how many input field has true value
Integer count = 0;
if(opp.Active_1__c == true){
count = count + 1;
}
if(opp.Active_2__c == true){
count = count + 1;
}
if(opp.Active_3__c == true){
count = count + 1;
}
if(opp.Active_4__c == true){
count = count + 1;
}
// Update Review__c field value according to count
if(count == 4){
opp.Review__c = 'pass';
}
if(count <= 2){
opp.Review__c = 'reject';
}
if(count == 3){
opp.Review__c = 'awaiting';
}
}
}
}
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com
try following code
let me know if it's works and mark it as Best Answer so that it's helps others too.
The fields are are populating from Account object and they have some criteria to compare before the "review" field gets updtaed.
Say like acc.Active_2__c >50k or acc.Active_1__c <=10k are the values and opportunity record should only chnage when the Stage value is "code live".
But when i update account object with the values then opportunity "review" field is not changing to meet the requirement. Only when new opportunity is created then the values are setting. after account update its not changing and with code live status not working.
Coul you please help me how can i fix this?
Thanks in advance,
supriya