Activity Forums Salesforce® Discussions What is the formula syntax when making a checkbox True or False from values collected from a Text Field?

  • What is the formula syntax when making a checkbox True or False from values collected from a Text Field?

    Posted by Nick on July 1, 2016 at 5:14 pm

    I have Master Detail object, named Agent__c, with a lookup text field named, Member__c, it has a child object related to it, Badges__c. Up to 6 related records can be created for the Member__c field [BadgeName01, BadgeName02, etc.] and each related record named differently (see below) and I would like to create 6 separate checkboxes to show True when any of the 6 related records has a value.

    I am going to create 6 custom checkboxes with values of:

    Check Awards__c
    Check Paper__c
    Check Rock__c
    Check Scissor__c
    Check Water__c
    Check Air__c

    If a value is present from the Member__c field, it should trigger a True value on the checkbox relating to it.

    Can someone help me out on this one?

    Below is more information about the objects and fields names.

    When a member is created, it creates an Id according the which record is created.
    The Member__c field choices are:

    Member Awards
    Member Paper
    Member Rock
    Member Scissor
    Member Water
    Member Air

    API Custom Object Names:
    Agent__c [contains the Member__c record field]
    Badges__c [contains the badges name record field]
    CheckXXXX__c [contains the True/False values and should be located on the Agent custom object]

    This is my diagram, hope it helps!

    Nick-formula-syntax

    Thank you in advance!

    • This discussion was modified 8 years, 4 months ago by  Nick.
    • This discussion was modified 8 years, 4 months ago by  Forcetalks.
    Nick replied 8 years, 4 months ago 2 Members · 2 Replies
  • 2 Replies
  • Ravi

    Member
    July 4, 2016 at 2:01 pm

    Hi Nick,

    You can do  this using salesforce automation tool like  workflow and  Process builder. As per the above requirement you  have to create  multiple workflow rule for each field update(checkbox)  and same goes for process builder.

    I think best way to achieve this to write a trigger on  Agent that will update your checkbox field by checking member name.

    Here is code that I have written that is working fine in my org.

    trigger UpdateAgent on Agent__c (before insert) {

    Set<Id> setOfmember = new set<Id>();
    Map<Id, Badges__c> mapToStoreMemberName;
    String member;

    for(Agent__c agent : trigger.new){
    setOfmember.add(agent.Member__c);
    }

    mapToStoreMemberName= new Map<Id, Badges__c>([select id, Name from Badges__c where id in : setOfmember]);

    for(Agent__c agent : trigger.new){

    member = mapToStoreMemberName.get(agent.Member__c).Name;

    if(member == 'Member Awards'){
    agent.Check_Awards__c = true;
    }
    else if(member == 'Member Paper'){
    agent.Check_Paper__c = true;
    }
    else if(member == 'Member Scissor'){
    agent.Check_Scissor__c = true;
    }
    else if(member == 'Member Water'){
    agent.Check_Water__c = true;
    }

    else if(member == 'Member Air'){
    agent.Check_Air__c = true;
    }

    }

    }

    Please do let me know if you face any issues.

  • Nick

    Member
    July 4, 2016 at 6:30 pm

    Hi Ravi,

    Thank you for taking the time to write out this APEX trigger. I tested it out in sandbox, and pushed to production and with some slight modifications, it is working just great! I had gone down the path of creating these in process builder, but was getting a little messy.

    I appreciate this!

    Many thanks!

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos