• Vivek Nayak
  • NEWBIE
  • 15 Points
  • Member since 2016
  • Cognizant

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 13
    Replies
Hi ,
I am using lightning:input of type text and want no special chars to be entered. Some posts say that we can use built-in pattern  attribute but its not working  for me.No idea what is missing .

<lightning:input  aura:id="BiCity"
                          label="Residential City" value=""  required="true"                                  messageWhenPatternMismatch="No special characters allowed"
                          pattern="[a-zA-Z]"
/>

Any help would be appreciated.
Thanks 
Hi folks,
I am struglling to compare one datetime field to dynamic date in SOQL.
Below is my query:

Select Id from Customobject__c where
EndDate__c =datetime.now().addMonths(3);

now problem is EndDate__c format on existing records which is
2020-08-28T14:00:00.000+0000

and i have compare this format with a date 3 month after today.
i.e. datetime.now().addMonths(3) or date.today.addMonths(3) whose value  will be
2020-09-02 00:00:00. 

I cant change EndDate__c format so how do i adjust RHS fomat (datetime) similar to EndDate__c   so that it can be compare to fecth records.
also tried 'yyyy-MM-dd\'T\'HH:mm:ss\'Z\'' but still no chance.
Any help would be really help 
Thanks
 

 
Hi Guys,
I need urgent help . I am deserializing callout response into list<object> which looks like below:
(
{
DealerSelected=true,
address={country=AU, postCode=2154, state=NSW, streetAddress=2 Victoria Ave, suburb=CASTLE HILL},
ealerCode=36333, dealerName=Castle Hill Toyota, 
lastUpdated=2019-11-25, latitude=-33.7345000, localityName=NSW, longitude=150.9810610, sapBranchCode=36333
},
)
i want to iterate over it and get attributes for but unable to read 
using dot notation. 

Below is code :



global class DealerSearchController {
 // Callout method
    @AuraEnabled
    public static ResponseWrapper getDealerList(String SearchString){
    //public static List<object>  getDealerList(String SearchString){
    system.debug('SearchString '+SearchString);  
    ResponseWrapper wr=new ResponseWrapper();         
    Http http=new Http();
    HttpRequest req= new HttpRequest();
    req.setMethod('GET');     
    String endpoint ='URL';
     req.setEndpoint(endpoint);    
     
    HttpResponse res=http.send(req);
    system.debug('Response '+res.getBody());
    List<object> DealerList;    
    if (res.getStatusCode()== 200){ 
        
    
    system.debug('body '+json.deserializeUntyped(res.getBody())) ; 
    Map<String,Object>DeserializedResponse=(Map<String,Object>)json.deserializeUntyped(res.getBody()); 
          
    DealerList= (List<object>) DeserializedResponse.get('locations');    
    system.debug('deserializedResponse '+DeserializedResponse);
    system.debug('Locations '+DealerList);
    wr.DealerList=DealerList; 

}

return wr;

    
    }    
   
 // other method  
    @AuraEnabled
public static void addSelectedDealer(List<Object>selectedDealers,String AccountId){
    //Map<String,Object>obj=New Map<String,Object>(selectedDealers);  
    //Map<String,Object>obj=(Map<String,Object>)selectedDealers;
  //iterating over selectedDealers
    for (object s : selectedDealers){      
    system.debug('record '+s); 
    //system.debug('abc '+s.dealerCode);     //throwing variable doent exist        
    }
    
    }

Can someone help how convert into list<object> into map to get object attributes?

Thanks
Hi All,
I have one autocomplete search functinality which shows a result list based on user input. I have used ui:input text for search box but problem is it doesnt handle up arrow/down arrow automatically like lightning:input.
I want when user start typing in box--> search result appear--> on pressing up (keycode 38) focus should move up and ressing down focus should move down with result list. This is really urgent.
Any help would be appreciated.

I have wriiten below part in controller for handling this.

var keycode=event.getParams.KeyCode;

switch (keycode) {
case 38:
// logic

break;

case 40:
}

Thanks
Hi All,

I am trying to write test class for a class which makes HTTP callout  and returns response in wrapper. Below is my code

//Callout Class. This is a blurpint please avaoid syntax error

public class CalloutClass {

@AuraEnabled
public static wrapperClass CalloutMethod (string wslr){   //This method returna a wrapper

wrapperClass wrapper =new wrapperClass();

Http h=new Http(); 
HttpRequest req=new HttpRequest();
/*
Request Params
*/

HttpResponse res=h.send(req);

/*
Deserialize response
*/

if(res.getStatusCode()==200){
wrapper.Status=res.getStatus();
wrapper.StatusCode=res.getStatusCode();
wrapper.response=res.getBody();

}

return wrapper;
}


public class wrapperClass{

@AuraEnabled public string Status {get; set;}
@AuraEnabled public integer StatusCode {get; set;}
@AuraEnabled public list<object> response {get; set;}
}


}

//Mock Class

@isTest
public class MockCallout implements HTTPCalloutMock {

Public HTTPResponse respond(HTTPRequest Req) {
    HTTPResponse Res=New HTTPResponse();
    
    Res.setStatusCode(200); 
    Res.setStatus('OK');    
    //Res.setBody(); //callout response is list of objects so dont know how to set response here without line break 
    return Res;    
    }


}

//Test Class

@isTest
Public Class OP_TestAppointmentCallout {

@isTest 
public Static void TestAppointmentData(){


   Test.setMock(HttpCalloutMock.class,new MockCallout());   

 
    CalloutClass.wrapperClass Wrapper=CalloutClass.CalloutMethod('93411');
    
    String Actualstatus =Wrapper.Status;
    Integer Actualstatuscode =Wrapper.StatusCode;
    
    
    system.assertEquals('OK',Actualstatus);
    system.assertEquals(200,Actualstatuscode);
   
    }

}

When i run test i am getting Null pointer exception for test class. I am not sure how to set fake response in mock class and how to call actuall class in test class. Please help 
Hi All,
I am struggling  to make Down Arrow key to move through list options in autocomplete combobox. Please see what is missing. Below is my code

<aura:component >
<div class="slds-form-element">
<label class="slds-form-element__label" for="combobox-id-22">Relate to</label>
<div class="slds-form-element__control">
<div class="slds-combobox_container">
<div class="slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open" aria-expanded="true" aria-haspopup="listbox" role="combobox">
<div class="slds-combobox__form-element slds-input-has-icon slds-input-has-icon_right" role="none">
<input type="text" class="slds-input slds-combobox__input slds-has-focus" id="combobox-id-22" aria-activedescendant="option1" aria-autocomplete="list" aria-controls="listbox-id-12" autoComplete="off" role="textbox" placeholder="Search..." />
</div>
<div id="listbox-id-12" class="slds-dropdown slds-dropdown_length-5 slds-dropdown_fluid" role="listbox">
<ul class="slds-listbox slds-listbox_vertical" role="presentation">
<li role="presentation" class="slds-listbox__item">
<div aria-selected="true" id="option1" class="slds-media slds-listbox__option slds-listbox__option_plain slds-media_small slds-has-focus" role="option">
<span class="slds-media__figure slds-listbox__option-icon"></span>
<span class="slds-media__body">
<span class="slds-truncate" title="Burlington Textiles Corp of America"> Burlington Textiles Corp of America</span>
</span>
</div>
</li>
<li role="presentation" class="slds-listbox__item">
<div id="option2" class="slds-media slds-listbox__option slds-listbox__option_plain slds-media_small" role="option">
<span class="slds-media__figure slds-listbox__option-icon"></span>
<span class="slds-media__body">
<span class="slds-truncate" title="Dickenson plc"> Dickenson plc</span>
</span>
</div>
</li>
<li role="presentation" class="slds-listbox__item">
<div id="option3" class="slds-media slds-listbox__option slds-listbox__option_plain slds-media_small" role="option">
<span class="slds-media__figure slds-listbox__option-icon"></span>
<span class="slds-media__body">
<span class="slds-truncate" title="Edge Communications"> Edge Communications</span>
</span>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
    
</aura:component>

Above code is copy of example given on link
https://www.lightningdesignsystem.com/components/combobox/#Keyboard-interaction

on pressing down key i can go throgh list options but when i copy-paste this code in new component its not working. I am not able to understand.
Thanks,
Vivek




 
Hi All,
I know local variables cant be accsssed outside function in JS but i have below requirement.

Helper:

({

helper1: func(){
var A=[];
//logic
A.push();
},

helper2: func(){
// I need A here.
cmp.set("v.data",A);
}
}}

As shown above, is there anyway to use variable of one function into another? I have also tried using component event but didnt succeed.
Please guide me.

Thanks,
Hi Everyone;
In each interview i am being asked this question but i am unable to write and run it properly.
Here is question:
write a trigger which will populate sum of child field values on prarent.(basically count Rollup summary trigger for lookup relationship)
I did search in community and got below program which is still not working:

trigger SumTrigger on Contact (before insert) {
list<Account>accts=new list<Account>();
set<ID>IDs=new set <ID>() ;
  if(trigger.isInsert||trigger.isUndelete){
      for(contact con:trigger.new) {  
      IDs.add(con.accountId) ;      
      }}   
    
  else if(trigger.isDelete){
      for(contact con:trigger.old) {  
      IDs.add(con.accountId) ;      
      }}   
 
else if(trigger.isUpdate){
      for(contact con:trigger.new) {
          if(con.AccountId !=null){
           IDs.add(con.accountId) ;   
          }     
            
      }}   
      
  if(IDs.size()>0){
 accts=[select id,TotalValue__c,(select id,value__c from contacts ) from Account where id in :IDs];              
  }     

  for(Account a:accts)  {
    for (contact c:a.contacts){
    a.TotalValue__c +=c.value__c;    
    }
        update accts; 
    }
}

No complie error but when inserting contact record getting below error:

SumTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.SumTrigger: line 30, column 1

also on modifying a section like below 

for(Account a:accts)  {
    decimal Value=0;
    for (contact c:a.contacts){
    value += c.value__c;
        
    }
    a.TotalValue__c =value;    
        
    }
     update accts;                 
}

again getting below error on insering any contact record:
SumTrigger: execution of BeforeInsert caused by: System.NullPointerException: Argument cannot be null. Trigger.SumTrigger: line 29, column 1

Please help me with easy trigger code to make it work.

Thanks in advance;
HI Carolina,

What is wrong with below code:
Public class StringArrayTest {

   public static list<string> generateStringArray(integer n){
    list<string> mylist=new list<string>();
    for(integer i=0; i<n; i++){
            mylist.add('Test ' + i);
     System.debug(mylist[i]);
    }
   return mylist;     
}
}

I have referred all your replies and post but silll getting error. Please help.
Thanks,
Vivek
Create Validation Rules
Learning Objectives challenge, I got this error when I put my frmula
Create Validation Rules
Learning Objectives
why??
Hello,
I have a trigger that is not not reaching the 75% threshold.
I have 2 lines of code where I am calling another Class.  Any help would be greatly appreciated.
trigger warrantyValueCalculation on Warranties_and_Surveys__c (before insert, before update) {
    for (Warranties_and_Surveys__c warRec: trigger.new)
    {
         if((trigger.isInsert) && (warRec.Warranty_Survey_Account__c=='123' || warRec.Warranty_Survey_Account__c=='456' || warRec.Warranty_Survey_Account__c=='789' || warRec.Warranty_Survey_Account__c=='136' || warRec.Warranty_Survey_Account__c=='764' || warRec.Warranty_Survey_Account__c=='111')&&(warRec.Project_Country__c=='US')){
         warrantyAmountCalculation.beforeInsert(trigger.new); ---no coverage
        }
        //if((trigger.isUpdate) && ((trigger.oldMap.get(warRec.Id).Registration_Status__c == 'Registered') && (warRec.Registration_Status__c == 'Registered'))){
         if((trigger.isUpdate) && (warRec.Warranty_Survey_Account__c=='001f100001M2FVP' || warRec.Warranty_Survey_Account__c=='876' || warRec.Warranty_Survey_Account__c=='590' || warRec.Warranty_Survey_Account__c=='327' || warRec.Warranty_Survey_Account__c=='970' || warRec.Warranty_Survey_Account__c=='327')&&(warRec.Project_Country__c=='US')){
         warrantyAmountCalculation.beforeInsert(trigger.new); ---no coverage
        }
    }

}

 
I have no coding knowledge. Salesforce Support provided a solution to an issue involving a flow; hidden code in the Salesforce Billing managed package was preventing the flow's execution. The solution includes apex code for a new class and two triggers. I created them in sandbox and they work great. Now, to deploy to production, I need someone to write unit tests. I'm under great time constraints and haven't got time to learn Apex right now. Would anyone be willing to tackle this for us? Someone looking for practice, perhaps?
  • I have to upsert records contained in a json format, total of around 5000 records (not bulk)
  • I will program the capture of JSON from a differnt system into an object and pass that for upsert to Salesforce
Hi All,

I am trying to write test class for a class which makes HTTP callout  and returns response in wrapper. Below is my code

//Callout Class. This is a blurpint please avaoid syntax error

public class CalloutClass {

@AuraEnabled
public static wrapperClass CalloutMethod (string wslr){   //This method returna a wrapper

wrapperClass wrapper =new wrapperClass();

Http h=new Http(); 
HttpRequest req=new HttpRequest();
/*
Request Params
*/

HttpResponse res=h.send(req);

/*
Deserialize response
*/

if(res.getStatusCode()==200){
wrapper.Status=res.getStatus();
wrapper.StatusCode=res.getStatusCode();
wrapper.response=res.getBody();

}

return wrapper;
}


public class wrapperClass{

@AuraEnabled public string Status {get; set;}
@AuraEnabled public integer StatusCode {get; set;}
@AuraEnabled public list<object> response {get; set;}
}


}

//Mock Class

@isTest
public class MockCallout implements HTTPCalloutMock {

Public HTTPResponse respond(HTTPRequest Req) {
    HTTPResponse Res=New HTTPResponse();
    
    Res.setStatusCode(200); 
    Res.setStatus('OK');    
    //Res.setBody(); //callout response is list of objects so dont know how to set response here without line break 
    return Res;    
    }


}

//Test Class

@isTest
Public Class OP_TestAppointmentCallout {

@isTest 
public Static void TestAppointmentData(){


   Test.setMock(HttpCalloutMock.class,new MockCallout());   

 
    CalloutClass.wrapperClass Wrapper=CalloutClass.CalloutMethod('93411');
    
    String Actualstatus =Wrapper.Status;
    Integer Actualstatuscode =Wrapper.StatusCode;
    
    
    system.assertEquals('OK',Actualstatus);
    system.assertEquals(200,Actualstatuscode);
   
    }

}

When i run test i am getting Null pointer exception for test class. I am not sure how to set fake response in mock class and how to call actuall class in test class. Please help 
Hi All,
I know local variables cant be accsssed outside function in JS but i have below requirement.

Helper:

({

helper1: func(){
var A=[];
//logic
A.push();
},

helper2: func(){
// I need A here.
cmp.set("v.data",A);
}
}}

As shown above, is there anyway to use variable of one function into another? I have also tried using component event but didnt succeed.
Please guide me.

Thanks,
Hi Everyone;
In each interview i am being asked this question but i am unable to write and run it properly.
Here is question:
write a trigger which will populate sum of child field values on prarent.(basically count Rollup summary trigger for lookup relationship)
I did search in community and got below program which is still not working:

trigger SumTrigger on Contact (before insert) {
list<Account>accts=new list<Account>();
set<ID>IDs=new set <ID>() ;
  if(trigger.isInsert||trigger.isUndelete){
      for(contact con:trigger.new) {  
      IDs.add(con.accountId) ;      
      }}   
    
  else if(trigger.isDelete){
      for(contact con:trigger.old) {  
      IDs.add(con.accountId) ;      
      }}   
 
else if(trigger.isUpdate){
      for(contact con:trigger.new) {
          if(con.AccountId !=null){
           IDs.add(con.accountId) ;   
          }     
            
      }}   
      
  if(IDs.size()>0){
 accts=[select id,TotalValue__c,(select id,value__c from contacts ) from Account where id in :IDs];              
  }     

  for(Account a:accts)  {
    for (contact c:a.contacts){
    a.TotalValue__c +=c.value__c;    
    }
        update accts; 
    }
}

No complie error but when inserting contact record getting below error:

SumTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.SumTrigger: line 30, column 1

also on modifying a section like below 

for(Account a:accts)  {
    decimal Value=0;
    for (contact c:a.contacts){
    value += c.value__c;
        
    }
    a.TotalValue__c =value;    
        
    }
     update accts;                 
}

again getting below error on insering any contact record:
SumTrigger: execution of BeforeInsert caused by: System.NullPointerException: Argument cannot be null. Trigger.SumTrigger: line 29, column 1

Please help me with easy trigger code to make it work.

Thanks in advance;
Hi All Champs,

Does anyone has any idea, why am I getting this error. " Challenge Not yet complete... here's what's wrong: 
The 'Accounts Without SolarBot Opportunities' report doesn't include the correct collection of accounts
"
I have created a report with Account standard report type. How can we fulfill this requirement for challenge#2.
User-added image

Thanks 
Guns
Hello,

This is the trailhead questions which I am trying to solve :

Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.The Apex class must be called 'StringArrayTest' and be in the public scope.
The Apex class must have a public static method called 'generateStringArray'.
The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.


Here is my code :

public class StringArrayTest {
    public static List <String> generateStringArray (Integer n) {
       List<String> List1 = new List<String> ();
        for(Integer i=0;i<n;i++) {
          List1.add('\'Test'+ i+'\'' );
  }
        System.debug(List1);
        return List1;
    } 

}


I am getting following error :

Challenge not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.


I tried it many times but I am not able to solve this problem. Please help.