• Koustubh Masurkar
  • NEWBIE
  • 25 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 3
    Questions
  • 3
    Replies
I have a LWC which navigates to records using NavigationMixin. When I use the same LWC in VisualForce page using lightning out, the navigation does not work. I there any way to make it work? I did research but didn't find any.
I have written a trigger to count open cases of contacts. I wrote a test class for the trigger, but the code coverage remains 0%. What am I doing wrong here? Any help is appriciated.

This is my trigger:
trigger CountOpenCases on case (after insert, after update) { 	//Event after insert and after update
  List<Case> caseList = trigger.new;							//Assign cases to a list
  set<Id> contactIdSet = new set<Id>();							//Create set to store contact id
  for(Case cs: caseList ){										//Iterate over cases
     contactIdSet.add(cs.contactId);							//Add contact id from cases to set
  }
  if(contactIdSet.size() > 0){									//If set has elements
    List<contact> lstcontact = [select id, (select id from Cases where status!= 'Closed') from contact where id IN: contactIdSet ];	//Create list and query closed cases id and account id
       if(lstcontact.size() > 0){								//If query returns results
          for(contact acc: lstcontact)							//Iterate over result list
          { 
             acc.Open_Cases__c = acc.cases.size(); 				//Assign size of list to variable which counts open cases
          }
          update lstcontact;									//Update the contact
       }
  }
}

This is my test class:
@isTest
public class CountOpenCasesTestClass {
    static testmethod void myTest(){
        
        Account acc = new Account(Name = 'TestAccount1');
        insert acc;
        Id accid = acc.Id; //get account id
        Contact con = new Contact();
        con.LastName = 'TestContact1';
        con.AccountId = accid; //insert account id
        insert con;
        Case c = new Case(subject='Case of Test Class');
        Id cid = c.Id; //get case id
        c.Status = 'New';
        c.ContactId = cid; //insert contact id
        insert c;
    }
}


 
I wrote a trigger to count number of open cases for contacts. 
To reduce complexity and obey governor limits, how can I use Map instead of inner for loop in this case? 
 
trigger CountOpenCases on case (after insert, after update) {
  List<Case> caseList = trigger.new;
  set<Id> contactIdSet = new set<Id>();
  for(Case cs: caseList ){
     contactIdSet .add(cs.contactId);
  }
  if(contactIdSet.size() > 0){
    List<contact> lstcontact = [select id, (select id, status from Cases)from contact where id IN: contactIdSet ];
       if(lstcontact.size() > 0){
          for(contact acc: lstcontact)
          { 
             Integer openCases = 0;
             for(Case c : acc.cases){
                 if(c.Status != 'Closed')
                   openCases++;
             }
             acc.Open_Cases__c = openCases; 
          }
          update lstcontact;
       }
  }
}

 
I have a LWC which navigates to records using NavigationMixin. When I use the same LWC in VisualForce page using lightning out, the navigation does not work. I there any way to make it work? I did research but didn't find any.
If something goes wrong in lightning component and I go back to component bundle and mofidy the logic there and save and comeback to browser and refresh the page and execute the component , But the component is sometimes displaying the same old logic. Is it because the Javascript handler code is being cached in browser or any other reason. I am able to look at the new logic in browser after making three or four refreshes.

In my code I want to replace the following where I am checking the value of a formula field (of type text) that refers to a checkbox field. The fomula field returns 'true' or 'false' based on the checkbox being checked or unchecked.

 

Replace:

if ('true' == <MysObject>.Is_Range_Constrained__c) {...}

with:

if (Boolean.valueOf(<MysObject>.Is_Range_Constrained__c)) {...}

 

The problem is the API docs do not explicitly say what is valid arguments for Boolean.valueOf(...) and the expected return values and I do not want to use something that is not documented in case the behavior changes or is specified in a future release.

 

Does anyone know if the code below is the expected behavior of Boolean.valueOf(...) on SFDC and is it documented somewhere? The behavior I get by trial and error is roughly in line with what Java would return.

 

By trial and error I get the following:

System.debug('=======> ' + Boolean.valueOf('true')); .. returns true

System.debug('=======> ' + Boolean.valueOf('True')); .. returns true

System.debug('=======> ' + Boolean.valueOf('TRUE')); .. returns true

System.debug('=======> ' + Boolean.valueOf('false')); .. returns false

System.debug('=======> ' + Boolean.valueOf('False')); .. returns false

System.debug('=======> ' + Boolean.valueOf('FALSE')); .. returns false

System.debug('=======> ' + Boolean.valueOf('')); .. returns false

System.debug('=======> ' + Boolean.valueOf('nnnn')); .. returns false

System.debug('=======> ' + Boolean.valueOf(0)); .. System.TypeException: Invalid boolean or String: 0

System.debug('=======> ' + Boolean.valueOf(1)); .. System.TypeException: Invalid boolean or String: 1

System.debug('=======> ' + Boolean.valueOf(10)); .. System.TypeException: Invalid boolean or String: 10



I created a trigger on case. Member_ID__c is a auto-number field on contact object. I am trying to find out repeat cases logged by a contact using custom checkbox Repeat_Caller__c on case. There are many other conditions, but I removed them in this code for simplicity. I am not able to match Member_ID__c field in cases even though multiple cases are created by the same contact. In other words, I am not able to enter the IF condition. I have pasted the trigger below.

Please guide me as to where the problem might be. Any help is appreciated.

 
trigger repeatCase1 on Case (before insert,before update) {
    List<Case> caseList = trigger.new;   
    Set<id> memberIdSet = new set<id>();
    for(case c: caseList){
        memberIdSet.add(c.Contact.Member_ID__c);
    }
      List<Case> allcase = [select Contact.Member_ID__c from case where contact.Member_ID__c IN: memberIdSet];               
      for(Case cs: caseList ){  
        for(Case all: allcase ){ 
            if(cs.contact.Member_ID__c == all.contact.Member_ID__c ){
                    cs.Repeat_Caller__c=True;
            }
        }
    }
    
}