• Pammy
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi All,

I want to mask credit card number in Case Description field. Whenever case get created in sfdc if case description field contains any credit card number, I just wanted to mask credit card number. For example if anyone enter credit card number like 4346-7810-4356-6678 in case description, After saving the case Credit card number should be look like as xxxx-xxxx-xxxx-xxxx. I have also tried to write trigger on Case object. But it is not working properly. It is making all number as cross(x) in case description field. Please find below code:
Trigger:
trigger testMaskCC on Case(before insert){
 if(trigger.isBefore && trigger.isInsert){ 
        CreditCard_No_Masking_OnCase NewCase= new CreditCard_No_Masking_OnCase();
        NewCase.newCaseInsert(Trigger.new);
    }      
}


Trigger Class
public class CreditCard_No_Masking_OnCase{

    public void newCaseInsert(list<Case> newList){
    
    String reGexVisa='4[0-9]{12}(?:[0-9]{3})';
    Pattern regexPattern = Pattern.compile(reGexVisa);
        for(case cs : newList){
           String withOutSpec=(cs.description).replaceAll('[-, +]','');
           Matcher regexMatcher = regexPattern.matcher(withOutSpec);
            system.debug('-------------group count----'+regexMatcher.groupCount());
           while(regexMatcher.find()){
              Integer countGroup=0;
              String  matchValue=regexMatcher.group(countGroup);
              cs.description= String.valueOf(cs.description).replaceAll('[0-9]', 'X');
              countGroup++;
            }
        }
    }
}


And also I am using regex for idetifying different companies's credit card number like Visa Card: ^4[0-9]{12}(?:[0-9]{3})?$  Mastercard: ^5[1-5][0-9]{14}$.

Please help me to generalized Regex(I wanted to use one Regex to identify different comany's credit card instead of using different company's regex) and Mask the Credit Card number only.
Any Help in this regard would be much appriciated.

 
  • June 02, 2016
  • Like
  • 0
My code is given below. It displays error to me:
Error: Compile Error: Method does not exist or incorrect signature: [Schema.DescribeFieldResult].isCreatable() at line 44 column 25
 
public with sharing class CRUD_FLS_Create_Challenge{

    public Id newUser {get;set;}
    
    public List<Personnel__c> getUnReg() {
        unregisteredUsers = new List<Personnel__c>();
       List<Jouster__c> currentParticipants = [ select Participant_Name__r.Name from Jouster__c ];
       List<Personnel__c> currentPersonnel = [ select Id, Name, Favorite_Color__c, Castle__r.Name from Personnel__c limit 15];
       Boolean reg;
       
       System.debug(currentParticipants);
       System.debug(currentPersonnel);
       
       for( Personnel__c p : currentPersonnel)
       {
           reg = false;
           for(Jouster__c j : currentParticipants)
           {
               if(j.Participant_Name__r.Name == p.Name) {
                   reg = true;
                   break;
               }
           }
           
           if(reg == false)
               unregisteredUsers.add(p);
       }
       
       System.debug(unregisteredUsers);
       
       return unregisteredUsers;
    }

    public Jouster__c newParticipant {get;set;}
    public List<Personnel__c> unregisteredUsers;
    
    
    public void register(){
        System.debug(newUser);
        Personnel__c p = [select Name, Favorite_Color__c, Castle__r.Name from Personnel__c where Id =: newUser]; 
        if (!Schema.sObjectType.Jouster__c.fields.Participant_Name__c.isCreatable()) {
            if (!Schema.sObjectType.Jouster__c.fields.Color__c.isCreatable()) {
                if(!Schema.sObjectType.Jouster__c.fields.Favorite_Color__c.isCreatable()) {  
                    if(!Schema.sObjectType.Jouster__c.fields.Castle__c.isCreatable()) {   
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Insufficient Access'));                 
                    }
                }
            }  
        }
        if([select id from Jouster__c where Participant_Name__r.Name =: p.Name] != null)
            insert new Jouster__c(Participant_Name__c=newUser, Color__c=p.Favorite_Color__c, Castle__c=p.Castle__c);
        else
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Jouster already entered in Tournament'));
    }    
    public string[] getPermSets(){
        String[] permSetArray = new List<string>();
        PermSetArray.add('User with Read ONLY Access to the Jousters object'); // description of the needed permission set
        return permSetArray;
    }

}