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
Sami ShakithSami Shakith 

Update a field by comparing 2 fields in the same object

Hi,

I want to update a field by comparing two other fields in the same object. For that what should i do? should i write a trigger or workflow? if trigger means how to write?
Best Answer chosen by Sami Shakith
Mudasir WaniMudasir Wani
This will solve your issue 
Use the minimum, pass criteria  i have put it to 33
 
if( AND(IF(paper1__c > 33 , true, false) , IF(   paper2__c >33 , true, false)),'Pass', 'Fail' )

 

All Answers

Mudasir WaniMudasir Wani
Hi Sami,
You should go for workflow because it is out of box functionality.
So you need not to maintain it. !!!!!!!!!!!
Here are some links where you can learn

https://help.salesforce.com/apex/HTViewHelpDoc?id=workflow_defining_field_updates.htm
https://help.salesforce.com/HTViewHelpDoc?id=workflow_field_update_considerations.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=workflow_field_update_considerations.htm&language=en_US)


Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.
Sami ShakithSami Shakith
can i use formula field for that ?
Mudasir WaniMudasir Wani
Yes you can use if your requirement is of that kind.
Can you elobrate what is the actual requirement.
Sami ShakithSami Shakith
Thank you for your reply.

For eg i have fields like paper1, paper2 in object1 and also having result field in that object. i want to automatically update the result field after updating the paper1 and paper2, that result field should be based on the both fields.
Mudasir WaniMudasir Wani
What is the data type of the paper1 and paper2
 
Sami ShakithSami Shakith
Number
Mudasir WaniMudasir Wani
Then create a formulae with the decimal place you want and use the formulae
Assuming the api name are paper1__c  and paper2__c create a formulae and select return type as number with number of decimal places and use the following formulae 
paper1__c  + paper2__c 

Don't forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help.



 
Sami ShakithSami Shakith
No i want that result field as text. can i?
Mudasir WaniMudasir Wani
Yes you can then use the following formulae

TEXT(paper1__c  + paper2__c )
Sami ShakithSami Shakith
I just want that text would be either pass or fail .
Mudasir WaniMudasir Wani
Paste the complete requirement here that would be great.
Whatever is possible I will try to answer to the best of my knowledge
Sami ShakithSami Shakith
There is 3 fields in an object. Paper1,Paper2 and Result. Paper2 & Paper2 are number fields. The Result field is Text data type. The Result field should be updated eaither as pass or fail based on the values in both paper1 & paper2 field. 
Mudasir WaniMudasir Wani
This will solve your issue 
Use the minimum, pass criteria  i have put it to 33
 
if( AND(IF(paper1__c > 33 , true, false) , IF(   paper2__c >33 , true, false)),'Pass', 'Fail' )

 
This was selected as the best answer
Sami ShakithSami Shakith
Thank you so much. could you please explain the logic?
Mudasir WaniMudasir Wani
The logic for the below expression 

 
if( AND(IF(paper1__c > 33 , true, false) , IF(   paper2__c >33 , true, false)),'Pass', 'Fail' )
//Check if the paper1 have marks morethan 33 if yes return true 
IF(paper1__c > 33 , true, false) = A---say for example

//Check if the paper2 have marks morethan 33 if yes return true
IF(paper2__c > 33 , true, false) = B----say for example

//Check if both the papers return true
AND(IF(paper1__c > 33 , true, false) , IF( paper2__c >33 , true, false))
AND(A , B)= Z --say for example
if A and B are both true
AND(True, true) will return true


//If both papers have passing marks then return pass else fail


if( Z,'Pass', 'Fail' )
if( true,'Pass', 'Fail' ) hence it will return Pass 
So the last expression evaluates

Hope this makes it clear



 
Sami ShakithSami Shakith
Yeah very clear now. Thanks a lot wani.