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
SF Beginner 2019SF Beginner 2019 

apex class to formula field

this may sounds funny, but I'm really struggling with this one.
 
if(p.Type__c == 'Contractor' &&  p.hasRecord__c == true && p.Visible__c == 'OFF'){
                p.Output__c= false;  
            }
            else if(p.Type__c == 'Contractor' &&  p.hasRecord__c == true && p.Visible__c == 'ON'){
                p.Output__c= true;
            }
            else if(p.Type__c == 'Contractor' &&  p.hasRecord__c == false && p.Visible__c == 'OFF'){
                p.Output__c= true; 
            }
            else if(p.Type__c == 'Contractor' &&  p.hasRecord__c == false && p.Visible__c == 'ON'){
                p.Output__c= true;
            }


can you convert that into formula field, I tried several time but I'm having issues with the 1st and 3rd statement.

 
IF (
    AND  
       (Type__c = 'Contractor',OR(
          AND(Visible__c = 'ON',hasRecord__c = true),
          AND(Visible__c = 'OFF', hasRecord__c = false,
          AND(Visible__c = 'ON',hasRecord__c = false)))
        ),
true,IF (
    AND  
       (Type__c = 'Contractor',
          AND(Visible__c = 'OFF', hasRecord__c = True)
        ),
false,

True)))



 
David Zhu 🔥David Zhu 🔥
You may try this:
IF (
    AND  
       (Type__c = 'Contractor',
         OR(
           AND(Visible__c = 'ON',hasRecord__c = true),
           AND(Visible__c = 'OFF', hasRecord__c = false),
           AND(Visible__c = 'ON',hasRecord__c = false)
         )
        ),
    true,
    IF (
       AND  
        (Type__c = 'Contractor',
          AND(Visible__c = 'OFF', hasRecord__c = True)
        ),
      false,
      True)
)