• Jyotirupa Das
  • NEWBIE
  • 0 Points
  • Member since 2019
  • Salesforce Developer
  • Cognizant

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 2
    Replies
Hi ,
Can someone please help me regarding test method for below code.

 @AuraEnabled
    public static String SaveContactInquiry(String con,String inq, String lang) {
        Contact cont = (Contact) JSON.deserialize (con,Contact.class); 
        Case inquiry = (Case) JSON.deserialize (inq,Case.class); 
        Case cas;
        Id InqId;
        String ContactId ='';
        List<GC_Language_Codes__mdt> langCodeList = new List<GC_Language_Codes__mdt>();
        try{
            langCodeList= [Select DeveloperName, Label from GC_Language_Codes__mdt where DeveloperName = :lang];
            /* updated based on US 5158 for setting the language on contact and Inquiry pages*/
            //Country__c countryinfo = [SELECT Id, Name,Country_ISO_Code__c, Country_Code__c,Default_Language__c FROM Country__c WHERE Id =:inquiry.LookupCountry__c];
            System.debug('^^ langCodeList'+langCodeList);
            if(lang != null && lang != '')
                cont.Preferred_Language__c = langCodeList[0].Label;
            
           /* getting all inquiry queue and assigning to that queue*/
            QueueSObject QueueID = [Select Queue.Id, Queue.Name, Queue.Type from QueueSObject WHERE Queue.Type ='Queue' AND Queue.Name =: Label.GC_GMI_All_Inquiry  Limit 1];
            
            
            List<Contact> checkContact = [SELECT Id,FirstName, LastName,State_Province__c 
                                          FROM Contact 
                                          WHERE FirstName =: cont.FirstName
                                          AND LastName =: cont.LastName 
                                          AND Country__c =: cont.Country__c
                                          AND Zip_Code__c =: cont.Zip_Code__c];
            System.debug('^^ checkContact List'+checkContact+'QueueID'+QueueID);
            if(checkContact.size() > 0){
                inquiry.ContactId = checkContact[0].Id;
                ContactId = inquiry.ContactId;  
            }
            else{
                Database.DMLOptions dml = new Database.DMLOptions();
                dml.DuplicateRuleHeader.allowSave = true;
                dml.DuplicateRuleHeader.runAsCurrentUser = true;
                Database.SaveResult sr = Database.insert(cont,dml);
                //insert cont;
                inquiry.ContactId =cont.id;
                ContactId = cont.id;
            } 
            if (QueueID.id   != null){
                inquiry.OwnerId = QueueID.Queue.Id;
            }
            system.debug('^^ inquery obj to be inserted'+inquiry);
            insert inquiry;
            InqId = inquiry.Id;
            cas = [select CaseNumber from case where id=:InqId];
            System.debug('^^ case'+cas);
            return  cas.CaseNumber +'@'+ContactId ;
           }
        catch(Exception e){
            createSystemLogEntry(InqId,'create the case and Contact',e.getMessage(),'Veeva Vault');
            System.debug('^^ Within error of case creation'+ e.getMessage());
            throw new GC_TriggerHandlerException('Error');
            
        }
        
    }
    

Thanks
Hi, This the method which is basically used to remove the version if any associated to contact while creating the case.
For example from contact 'Anonymous Japan Contact_v1.0.2021' some agent is trying to create a case, it will by default show him the contact as 'Anonymous Japan Contact' after case creation.

Here is the method
 public static void inquiryAssociatedToVersionContact(){
        String ConName = '';
        String ConName1 = '';
        String anonymize =  'Anonymized Contact'; //for Anonymized Contact
        String orignalname = '';
        String finalcon = '';
        String Middlename = '';
        String Firstname = '';
        set<Id> sets = new set<id>();
        List<Case> caseList = new List<Case>();
        List<Case> updatedCaseList = new List<Case>();
        List<Case> cas = trigger.new;
        for (Case c:cas){
            caseList.add(c);
            
            sets.add(c.ContactId );
            if( caseList.size()>0 && c.ContactId != NULL){
                List<Contact> cont = [select id, Name, Is_Contact_Version__c, Country__r.Name from Contact where id in :sets];            
                System.debug('@#@current Contact: ' + cont);
                for(Contact contact : cont ){
                ConName = contact.Name;
            
              if(c.LookupCountry__c == contact.Country__c && contact.Is_Contact_Version__c == TRUE )  //Is_Contact_Version__c = true
              {
                if( ConName.contains(anonymize)  ){
                        finalcon  = anonymize;
                        //Middlename = '';
                        Firstname = 'Anonymized';    
                    }
                    else{    
                    
                orignalname = 'Anonymous' + ' ' + contact.Country__r.Name + ' ' + 'Contact' ;               
                System.debug('@#@original contact: '+ orignalname);
                boolean istrue = ConName.contains(orignalname);
                 system.debug(' @#@istrue Contact Name' + istrue);
                if(istrue == True){
                    finalcon = orignalname;
                    Middlename = contact.Country__r.Name;
                }
                }       
                system.debug(' @#@final Contact Name' + finalcon);
                system.debug(' @#@final Middle Name' + Middlename);
                
            }
            //for Anonymized Contact
                if( contact.Is_Contact_Version__c == TRUE && contact.Country__r.Name == 'World'  ) {
                      orignalname = 'Anonymized Contact' ;               
                    System.debug('@#@original contact: '+ orignalname);
                    boolean istrue = ConName.contains(orignalname);
                     system.debug(' @#@istrue Contact Name' + istrue);
                    if(istrue == True){
                    finalcon = orignalname;
                    //Middlename = ;
                    Firstname = 'Anonymized';    
                    }
                       
                    system.debug(' @#@final Contact Name' + finalcon);
                    system.debug(' @#@final Middle Name' + Middlename);
                    
                }  
                }
        }
        
        List<Contact> con1 ;
        if( Middlename != ''  ){
            
        //Contact con = [select id, Name from Contact where MiddleName =:Middlename AND LastName = 'Contact'];
         con1 = [select id, Name from Contact where MiddleName =:Middlename AND LastName = 'Contact'];
            
             System.debug('@#@contact c: '+ con1);
            for(Contact con : con1){
             c.ContactId = con.id;
                    updatedCaseList.add(c) ;
            } 
        }
       if( Firstname != '' ){
             con1 = [select id, Name from Contact where FirstName =:Firstname AND LastName = 'Contact'];
           System.debug('@#@contact c: '+ con1);
           for(Contact con : con1){
            c.ContactId = con.id;
                    updatedCaseList.add(c) ;
           }   
                
            }    
        
                
                system.debug('%caselist%'+updatedCaseList);
    
    }
    
    }

Can someone please assist e how to write the test method for above
I want to remove the salesforce validation rule on check of checkbox in VF page. It is workig for first time but if we try to submit the page without filling any of the required field, the field validation is showing up again.

User-added image

User-added image

This is the script
<script type="text/javascript">
      $(document).ready(function(){
            
        $("[id$=enabledisablecheckbox]").change(function(){
            if(this.checked==true){
                   $("[id$=FirstName]").prop("disabled",true);
                   $("[id$=LastName]").prop("disabled",true);
                    $("[id$=LastName]").prop("value",null);
                $("[id$=FirstName]").prop("value",null);
                
                if($(".anonymousFN")[0].parentElement != null){
                    $(".anonymousFN")[0].parentElement.children[0].className = '';
                    $(".anonymousLN")[0].parentElement.children[0].className = '';
                    //$(".anonymousFN")[0].value = 0;
                }
              //$("[id$=FirstName]").prop("required",false);
                 //  $("[id$=LastName]").prop("required",false);
               // $("[id$=FirstName]").required = false;
            }
            else{
                $("[id$=FirstName]").prop("disabled",false);
                $("[id$=LastName]").prop("disabled",false);
                // $("[id$=FirstName]").prop("required",true);
                  // $("[id$=LastName]").prop("required",true);
                if($(".anonymousFN")[0].parentElement != null){
                    $(".anonymousFN")[0].parentElement.children[0].className = 'requiredBlock';
                    $(".anonymousLN")[0].parentElement.children[0].className = 'requiredBlock';
                           
                }
            }
        });
    });
    </script>

here is the defination
<apex:pageblockSectionItem  >
                     <apex:outputLabel value="{!$Label.GMI_Anonymous_Contact}" ></apex:outputLabel>
                     <apex:inputCheckbox value="{!cas.AnonymousContact__c}" id="enabledisablecheckbox"  onClick="disableEnableField()" /> 
                   </apex:pageblockSectionItem >

Can someone please help!!
I want to display specific contact name on checking the check box field in VF page which should be in below format
'Anonymous '+case.country__r.Name+' Contact'
User-added imageCan anyone please help?
I have a requirement where if I am selecting the check box while creating a case in VF page, User-added image

It should Populate the Contact name as Anonymous Contact in Case object.
User-added image

Can someone please provide me some guidance on this requirement
I want to remove the salesforce validation rule on check of checkbox in VF page. It is workig for first time but if we try to submit the page without filling any of the required field, the field validation is showing up again.

User-added image

User-added image

This is the script
<script type="text/javascript">
      $(document).ready(function(){
            
        $("[id$=enabledisablecheckbox]").change(function(){
            if(this.checked==true){
                   $("[id$=FirstName]").prop("disabled",true);
                   $("[id$=LastName]").prop("disabled",true);
                    $("[id$=LastName]").prop("value",null);
                $("[id$=FirstName]").prop("value",null);
                
                if($(".anonymousFN")[0].parentElement != null){
                    $(".anonymousFN")[0].parentElement.children[0].className = '';
                    $(".anonymousLN")[0].parentElement.children[0].className = '';
                    //$(".anonymousFN")[0].value = 0;
                }
              //$("[id$=FirstName]").prop("required",false);
                 //  $("[id$=LastName]").prop("required",false);
               // $("[id$=FirstName]").required = false;
            }
            else{
                $("[id$=FirstName]").prop("disabled",false);
                $("[id$=LastName]").prop("disabled",false);
                // $("[id$=FirstName]").prop("required",true);
                  // $("[id$=LastName]").prop("required",true);
                if($(".anonymousFN")[0].parentElement != null){
                    $(".anonymousFN")[0].parentElement.children[0].className = 'requiredBlock';
                    $(".anonymousLN")[0].parentElement.children[0].className = 'requiredBlock';
                           
                }
            }
        });
    });
    </script>

here is the defination
<apex:pageblockSectionItem  >
                     <apex:outputLabel value="{!$Label.GMI_Anonymous_Contact}" ></apex:outputLabel>
                     <apex:inputCheckbox value="{!cas.AnonymousContact__c}" id="enabledisablecheckbox"  onClick="disableEnableField()" /> 
                   </apex:pageblockSectionItem >

Can someone please help!!
Hello All,

I have done a trigger which make toAddress mandate. However it is not working my code is here. I checked in debug log is toAddress is blank then salesforce automatically assigns AdditionalTo to toAddress field. is there any way to make it mandate? .Thanks
 
trigger EmailRelatedToIsBlank on EmailMessage (before insert) {
for(EmailMessage eMsg : Trigger.new)
    {
		system.debug('---eMsg.ToAddress--' + eMsg.ToAddress);
		if(eMsg.ToAddress != null){
			
		}else{
			
			eMsg.addError('To Address can not be blank');
		}
			
    }
}