• R R M
  • NEWBIE
  • 55 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 23
    Questions
  • 36
    Replies

HI Folks 

I got strucked in code coverage, Now i have 63% coverage, Please do help. 

 

@RestResource(urlMapping='/api/IVR/*')

global class IVRRestAPI 
{
  
    @HttpPost
    global static List<IVR__c> CreateIVR(List<createIVR> icretIVR) 
    {
        try{
        Set<String> loanId = new Set<String>();
        List<Loan__c> loanlst = new List<Loan__c>();
        Map<String,String> mpidtoname = new Map<String,String>();
        List<IVR__c> IVRlst = new List<IVR__c>();
        for(createIVR icret:icretIVR)
        {
            if(icret.LoanID != null)
            {
                loanId.add(icret.LoanID);
            }
        }
        System.debug('loanId '+loanId);
        if(loanId.size() > 0)
        {
            loanlst = [SELECT Id,Name FROM Loan__c WHERE Name IN:loanId];
        }
        System.debug('loanlst '+loanlst);
        if(loanlst.size() > 0)
        {
            for(Loan__c iloan:loanlst)
            {
                mpidtoname.put(iloan.Name,iloan.Id);
            }
        }
        System.debug('mpidtoname '+mpidtoname);
        for(createIVR icret:icretIVR)
        {
            IVR__c IVR = new IVR__c();
                         
            if(mpidtoname.containskey(icret.LoanID))
            {
                IVR.Loan_Id__c = mpidtoname.get(icret.LoanID);
            }
            
            IVR.Name = icret.IVRId;
            IVR.Merchant_Name__c = icret.MerchantName; 
            IVR.IVR_Number__c = icret.IVRNumber;
            IVR.Disbursed_Amount__c = Decimal.valueOf(icret.DisbursedAmount);
            
            IVR.Disbursed_Date_Time__c = date.ValueOf(icret.DisbursedDateTime);
            IVRlst.add(IVR);
        }
        if(IVRlst.size() > 0)
        {
            insert IVRlst;
            return IVRlst;
        }
        return null;
        }catch(exception e){System.debug(e.getmessage() + e.getlinenumber());return null;}
    }
    global class createIVR
    {
        public String IVRId;
        public String LoanID;
        public String DisbursedAmount;
        public String MerchantName;
        Public String DisbursedDateTime;
        Public String IVRNumber;
        
        public createIVR(String IVRId,String LoanID,String DisbursedAmount,String MerchantName,String DisbursedDateTime,String IVRNumber){}
        
    }
}


Test Class ​

@istest
public class IVRRestAPITest{
 static testMethod void  IVRRestAPITest(){

   IVRRestAPI reqst=new IVRRestAPI();
   String JsonMsg=JSON.serialize(reqst);

   RestRequest req = new RestRequest();   
    req.addHeader('Content-Type', 'application/json'); 
    req.requestURI = '/services/apexrest/api/IVR/CreateIVR';
    req.httpMethod = 'POST';
    req.requestBody = Blob.valueof(JsonMsg);
    
    RestResponse res = new RestResponse();
    RestContext.request = req;
    RestContext.response= res;

    Test.startTest();
    List<IVRRestAPI.createIVR> icretIVRList  = new List<IVRRestAPI.createIVR>();
    icretIVRList.add(new IVRRestAPI.CreateIVR('Name','LoanID','DisbursedAmount','MerchantName','DisbursedDateTime','IVRNumber') );
    IVRRestAPI.CreateIVR(icretIVRList);
    Test.stopTest();
   }
}


Below lines are not covered in test class.

18                loanId.add(icret.LoanID);
24            loanlst = [SELECT Id,Name FROM Loan__c WHERE Name IN:loanId];
29            for(Loan__c iloan:loanlst)
30            {
31                mpidtoname.put(iloan.Name,iloan.Id);
41                IVR.Loan_Id__c = mpidtoname.get(icret.LoanID);
49            IVR.Disbursed_Date_Time__c = date.ValueOf(icret.DisbursedDateTime);
50            IVRlst.add(IVR);
51        }
52        if(IVRlst.size() > 0)
53        {
54            insert IVRlst;
55            return IVRlst;
56        }
57        return null;

 

Please do help to get code coverage. 
Thanks in Advance.

  • March 13, 2018
  • Like
  • 1
HI Folks

I got strucked with test class, Please help with Test Class for below class.
 
@RestResource(urlMapping='/api/IVR/*')

global class IVRRestAPI 
{
  
    @HttpPost
    global static List<IVR__c> CreateIVR(List<createIVR> icretIVR) 
    {
        try{
        Set<String> loanId = new Set<String>();
        List<Loan__c> loanlst = new List<Loan__c>();
        Map<String,String> mpidtoname = new Map<String,String>();
        List<IVR__c> IVRlst = new List<IVR__c>();
        for(createIVR icret:icretIVR)
        {
            if(icret.LoanID != null)
            {
                loanId.add(icret.LoanID);
            }
        }
        System.debug('loanId '+loanId);
        if(loanId.size() > 0)
        {
            loanlst = [SELECT Id,Name FROM Loan__c WHERE Name IN:loanId];
        }
        System.debug('loanlst '+loanlst);
        if(loanlst.size() > 0)
        {
            for(Loan__c iloan:loanlst)
            {
                mpidtoname.put(iloan.Name,iloan.Id);
            }
        }
        System.debug('mpidtoname '+mpidtoname);
        for(createIVR icret:icretIVR)
        {
            IVR__c IVR = new IVR__c();
            IVR.Name = icret.IVRId;
            IVR.Disbursed_Amount__c = Decimal.valueOf(icret.DisbursedAmount);
            IVR.Merchant_Name__c = icret.MerchantName; 
            IVR.Disbursed_Date_Time__c = date.ValueOf(icret.DisbursedDateTime);
            IVR.IVR_Number__c = icret.IVRNumber; 
            if(mpidtoname.containskey(icret.LoanID))
            {
                IVR.Loan_Id__c = mpidtoname.get(icret.LoanID);
            }
            
            IVRlst.add(IVR);
        }
        if(IVRlst.size() > 0)
        {
            insert IVRlst;
            return IVRlst;
        }
        return null;
        }catch(exception e){System.debug(e.getmessage() + e.getlinenumber());return null;}
    }
    global class createIVR
    {
        public String IVRId;
        public String LoanID;
        public String DisbursedAmount;
        public String MerchantName;
        Public String DisbursedDateTime;
        Public String IVRNumber;
    }
}


I have tried with test class to get test code but unfortunately i got just "0" Please do help. 

@istest
public class IVRRestAPITest{

 static testMethod void  IVRRestAPI(){

   IVR__c  TestOpp=new IVR__c ();
   TestOpp.name='TestOpp1';
   TestOpp.Disbursed_Amount__c=234567;
   TestOpp.IVR_Number__c ='2345678';
   TestOpp.Merchant_Name__c ='Test';
   insert TestOpp;
   
   IVRRestAPI reqst=new IVRRestAPI();
   String JsonMsg=JSON.serialize(reqst);
   Test.startTest();

   RestRequest req = new RestRequest(); 
   RestResponse res = new RestResponse();

    req.requestURI = '/services/apexrest/api/IVR/CreateIVR';  //Request URL
    req.httpMethod = 'POST';
    req.requestBody = Blob.valueof(JsonMsg);
    RestContext.request = req;
    RestContext.response= res;
    Test.stopTest();

   }
}
 

Please do help.  

Thanks in Advance.

  • March 12, 2018
  • Like
  • 0
HI Folks,

I have Onclick javascript button to change the status and i tried to capture the time and Userid. So its working perfectily for System administrators and able to capture userid and time also but for Custom profile users this not working. userid and time not capturinng. 

see below code
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")} 
var x; 
if (confirm("Are you Sure! You want to Reject this Customer?") == true) { 
x = "Yes"; 
} else { 
x = "Cancel"; 
} 
if(x == 'Cancel'){ 
window.location.replace('/{!Customer__c.Id}') 
} 
else { 
var journystatus = "SELECT id,Customer_Status__c FROM Customer__c WHERE Id = '{!Customer__c.Id}' limit 1"; 

var records = sforce.connection.query(journystatus); 
var values = records.getArray('records'); 
var status = values[0].Customer_Status__c ; 

if(status == 'Referred') 
{ 
var result = sforce.apex.execute("CustomerStatusChanginginDBUsingAPI","StatusChange", {extrnlid:"{!Customer__c.Customer_External_Id__c}", 
CusJurSt:"Rejected"}); 
location.reload(); 
} 
else 
{ 
alert('Cannot change the customer status as customer already in REJECTED/REFFERED state'); 
}
var f = new sforce.SObject("Customer__c"); 
f.id = "{!Customer__c.Id}"; 
f.Rejected_Date_Time__c =new Date().toISOString();
f.Rejected_By__c =sforce.connection.getUserInfo().userId; 
sforce.connection.update([f]); 
}


please do help.
Thanks in Advance. 
  • March 06, 2018
  • Like
  • 0
HI Folks, 

Need test class for below apex class.
 
public with sharing class ApexStartController {
    public ApexStartController() {
        params = System.currentPageReference().getParameters();
        // System.debug(params);
        execScript = false;
    }
    /** Parameter */
    public Map<String,String> params { get; set; }
    /** Question */
    public String q {
        get {
            if (q == null) {
                q = params.get('q');
                if (q != null)
                    q = EncodingUtil.urlDecode(q, 'UTF-8');
            }
            return q;
        }
        set; 
    }
    /** Apex Class */
    public String c {
        get { return params.get('a'); }
        set; 
    }
    /** Apex Method */
    public String m {
        get { return params.get('m'); }
        set; 
    }
    /** Parameter Name */
    public String n {
        get { return params.get('n'); }
        set; 
    }
    /** Parameter Value */
    public String v {
        get { return params.get('v'); }
        set; 
    }

    public Boolean execScript { get; set; }
    
    public PageReference doStart() {
        execScript = true;
        return null;
    }

    public PageReference doCancel() {
    PageReference pg;
        String r = params.get('r');
        if (r != null && r.length() > 0)

            pg=new PageReference(r);
            pg.setRedirect(true);
        return pg;
    }
}

I tried but getting error Attempt to de-reference a null object, and with 44% code coverage, please see below code and do need full help. 
 
@isTest 
public class ApexStartController_Test {
static testMethod void Apexstart() { 


Test.StartTest(); 
PageReference pageRef = Page.GenerateDocslink; // Add your VF page Name here
Test.setCurrentPage(pageRef);
ApexStartController Ln1 = new ApexStartController();
Ln1.doStart();
Ln1.doCancel();
Test.StopTest();
}
}

Thanks InAdvance. 
  • March 05, 2018
  • Like
  • 0
Hi Folks, 
I need to export Salesforce Data to FTP Server in Schedule and Real time manner. 
But except Dataloader.io.
Please advise

Thanks.
  • February 16, 2018
  • Like
  • 0
HI Folks, 
I have Onclick javascript button on Classic, now we need this button on Lightning pages, so i have developed lightning component but its not working not getting output, please do help. 

Original Onclick javascript button Code is :
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

var result = sforce.apex.execute("GeneratingNewDocLinkForLoanInDB","GeneratingDocLink", {extrnlid:"{!Loan__c.Loan_External_id__c}"}); 
location.reload();

My Apex class : 

global class GeneratingNewDocLinkForLoanInDB
{
    public static string accToken;
    public static string accsToken;
    public static String expireTime;
    public static String tokenType;
    public static String refToken;
    public Static blob response;
    public static String endpointurl;
    public static string ResponseString;
    public static string blobResult; 
   
    //public static Loan_Doc_Details__c iLDetails = new Loan_Doc_Details__c(); 
    public static list<Loan_Doc_Details__c> lstUpdate = new list<Loan_Doc_Details__c>();
    public static long str;
    
       
    global static void returnToken() 
    {    
        //Custom Settings
        Generate_Loan_Doc_Url__c iCustom = [SELECT Name,ClientId__c,Client_Secret__c,Login_URL__c,Password__c,User_Name__c,Active__c,
                                       EndPoint__c FROM Generate_Loan_Doc_Url__c WHERE Active__c = true];
        system.debug('iCustom'+iCustom);
        
        String loginUri = iCustom.Login_URL__c;
        String clientId = iCustom.ClientId__c;
        String targetString = iCustom.Client_Secret__c;
        String clientSecret = EncodingUtil.urlEncode(targetString,'UTF-8');
        String username = iCustom.User_Name__c;
        String password = iCustom.Password__c;
        endpointurl = iCustom.EndPoint__c;
        String reqbody = 'client_id='+clientId+'&client_secret='+clientSecret+'&scope=partners_api_sensitive&grant_type=client_credentials';
        System.debug(reqbody);
        HttpRequest req = new HttpRequest(); 
        req.setMethod('POST');
        req.setHeader('content-type','application/x-www-form-urlencoded');
        req.setEndpoint(loginUri);
        req.setBody(reqbody);
        Http http = new Http();
        HTTPResponse res = http.send(req);
        System.debug(res.getbody());
        
        //Custom Object - To check the access token expired or not
        Loan_Doc_Details__c iLDetails = [SELECT Id,Name,Access_Token__c,Active__c,Expiry_Time__c,Token_generated_time__c FROM Loan_Doc_Details__c 
                                            WHERE Active__c = true LIMIT 1];
        system.debug('iLDetails'+iLDetails);
        
        if(iLDetails.Token_generated_time__c != null){
        
            str = ((system.now().getTime() - iLDetails.Token_generated_time__c.getTime())/ 1000);
            system.debug(str);
        }
        
        system.debug(iLDetails.Access_Token__c);
        system.debug(iLDetails.Expiry_Time__c);
        
        if(iLDetails.Access_Token__c == '' || iLDetails.Access_Token__c == null || (iLDetails.Expiry_Time__c != null && str > iLDetails.Expiry_Time__c)){
            
            accessToken resp1 = (accessToken)JSON.deserialize(res.getbody(),accessToken.class);
            System.debug(resp1.access_token);
            accToken = resp1.access_token;System.debug(accToken);
            expireTime = resp1.expires_in;System.debug(expireTime);
            tokenType = resp1.token_type;System.debug(tokenType);
            
            //update custom object
            Loan_Doc_Details__c creds = new Loan_Doc_Details__c(Id = iLDetails.Id);
            system.debug('AccessToken length - '+accToken.length());
            creds.Access_Token__c = accToken;
            creds.Expiry_Time__c = decimal.valueof(expireTime);
            creds.Token_generated_time__c = system.now();
            system.debug('*****'+creds.Token_generated_time__c);
            lstUpdate.add(creds);
        
        } 
        else{
            accToken = iLDetails.Access_Token__c;
        }
    }

    Webservice static void GeneratingDocLink(String extrnlid)  
    {    
        returnToken();
        System.debug(extrnlid);

        Loan__c iloan = [SELECT ID,Loan_External_id__c FROM Loan__c WHERE Loan_External_id__c =:extrnlid];
        if(iloan.Loan_External_id__c !=null)
        {
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        req.setMethod('POST');
        system.debug(accToken);
        req.setHeader('Authorization', 'Bearer '+accToken);
        req.setHeader('Content-Type', 'application/octet-stream');
        System.debug('******'+endpointurl);
        String endpoint = endpointurl+'/'+iloan.Loan_External_id__c+'/'+'documents';
        system.debug(endpoint);
        req.setEndpoint(endpoint);
        req.setTimeout(100000);
        res = http.send(req);
        System.debug('******'+res.getbody());
        response = res.getbodyasblob();
        System.debug(Response);
               
        //update token details
        system.debug('*****'+lstUpdate);
        if(lstUpdate.size()>0){
            
            update lstUpdate;
        }      
       }        
    }  
    
    global class accessToken
    {
        public String id;
        public String access_token;
        public String expires_in;
        public String token_type;
    }
}
 


Using above code i have developed component and controller

Component :

<aura:component controller="GeneratingNewDocLinkForLoanInDB"
implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,force:hasSObjectName,lightning:actionOverride" access="global" >
	<ui:button label="Generate Document" press="{!c.Generatedoc}"/>
</aura:component>
 

Controller :

({
Generatedoc :function(component,event, helper){	
var result = (sforce.apex.execute("GeneratingNewDocLinkForLoanInDB","GeneratingDocLink", {extrnlid:"{!Loan__c.Loan_External_id__c}"})); 
location.reload();
}
})
 

Then added Quick action(TestButton) on Lightning page.

When i am clicking on TestButton getting popup with "Generate Document" Button. then when i clicks on  "Generate Document" button it is just reloading the page and not getting any output 

  • February 07, 2018
  • Like
  • 0

HI folks, 

I have Onclick javascript button in Classic and now i need use this button lightning component but unfortunately iam getting error. please help. 

Original Onclick javascript button code is:  

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

var result = sforce.apex.execute("GeneratingNewDocLinkForLoanInDB","GeneratingDocLink", {extrnlid:"{!Loan__c.Loan_External_id__c}"}); 
location.reload();

------------------------
i have tried use lightning component. 
Component 

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >

	<ui:button label="Generate Document Link" press="{!c.Generatedocslinks}"/>
</aura:component>


Controller ​

({
Generatedocslinks :function(cmp,event){	
var result = sforce.apex.execute("GeneratingNewDocLinkForLoanInDB","GeneratingDocLink", {extrnlid:"{!Loan__c.Loan_External_id__c}"}); 
location.reload();
}
})


Output​

User-added image

  • February 07, 2018
  • Like
  • 0

HI Friends, 
I got stricked please do help. 
We have custom execute javascript button which used to call third party api and using in classic mode. but now we moved to communities so now we are unable to show javascript button on communities pages. because lightning pages not supporting for javascrript buttons. 
Please do help with lightning componenets and vf how to do, because am not familier with lightning. 
Please do help.

Currently we have this java script button 

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

var result = sforce.apex.execute("GeneratingNewDocLinkForLoanInDB","GeneratingDocLink", {extrnlid:"{!Loan__c.Loan_External_id__c}"}); 
location.reload();

 Thanks in Advance.

  • February 06, 2018
  • Like
  • 0

HI Folks, 
Getting Debuglog Error, 

System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)

Below is my Trigger:

Trigger CaseCustomer on Case (before insert,after update) {
    Try{
    Set<String> stemail = new Set<String>();
    List<Customer__c> custlst = new List<Customer__c>();
    Map<String,Customer__c> mpemailtocustomer = new Map<String,Customer__c>();
    List<Case> updcaselst = new List<Case>();
    Map<String,Entitlement> mpentitle = new Map<String,Entitlement>();
    Set<Id> casid = new Set<Id>();
    List<CaseMilestone> cmsToUpdate = new List<CaseMilestone>();
    
    if(Trigger.isAfter)
    {
        for(Case icas:Trigger.New)
        {
            if((trigger.newMap.get(icas.id).Status!= trigger.oldMap.get(icas.id).Status) && icas.Status == 'Closed')
            {
                casid.add(icas.id);
                System.debug(casid);
            }
        }
        if(casid.size()>0)
        {
            cmsToUpdate = [select Id,completionDate from CaseMilestone where caseId IN :casid];
            System.debug(cmsToUpdate);
        }
        if(cmsToUpdate.size()>0)
        {
            for(CaseMilestone icasn:cmsToUpdate)
            {
                icasn.completionDate = System.now();
            }
            update cmsToUpdate;
        }
        
    }
    
   else
   {
    for(Case icas:Trigger.New)
    {
        if(icas.SuppliedEmail != null)
        {
            stemail.add(icas.SuppliedEmail);
            System.debug(stemail);
        }
    }
    if(stemail.size()>0)
    {
        custlst = [SELECT ID,Email__c FROM Customer__c WHERE Email__c IN:stemail];
        System.debug(custlst);
    }
    if(custlst.size()>0)
    {
        for(Customer__c icus:custlst)
        {
            mpemailtocustomer.put(icus.Email__c,icus);
            System.debug(mpemailtocustomer);
        }
    
    }
    List<Entitlement> entlst = [SELECT id,Name FROM Entitlement];
    if(entlst.size()>0)
    {
        for(Entitlement ient :entlst)
        {
            mpentitle.put(ient.Name,ient);
        }
    }
    
        for(Case icas : Trigger.New)
        {
            if(mpemailtocustomer.containskey(icas.SuppliedEmail))
            {
                icas.Customer__c = mpemailtocustomer.get(icas.SuppliedEmail).ID;           
            }
            if(icas.Origin == 'Email' ||  icas.Origin == 'Phone' || icas.Origin == 'Web')
            {
                icas.EntitlementId = mpentitle.get('Response').Id;
                System.debug(icas.EntitlementId);
            }
        }
    
    }
    }catch(exception e)
    {
        System.debug(e.getlinenumber()+e.getmessage());
    }
}

Please Do help,
Thanks In Advance.
  • January 10, 2018
  • Like
  • 0
I wrote a trigger that works perfectly in sandbox and has 83% test coverage and deployed it to production, then Trigger was worked smoothly up to 9 months,from 5days back onwords its not working in the production instance where as Working in Sandbox now also and I don't get any error messages, but the thing that it's supposed to do (Query and fill customer field in Case Based on SuppliedEmail) just doesn't happen. In production, it also has 83% coverage. Any ideas what's going on?
 
Here's the code:

Trigger CaseCustomer on Case (before insert,after update) {
    Try{
    Set<String> stemail = new Set<String>();
    List<Customer__c> custlst = new List<Customer__c>();
    Map<String,Customer__c> mpemailtocustomer = new Map<String,Customer__c>();
    List<Case> updcaselst = new List<Case>();
    Map<String,Entitlement> mpentitle = new Map<String,Entitlement>();
    Set<Id> casid = new Set<Id>();
    List<CaseMilestone> cmsToUpdate = new List<CaseMilestone>();
    
    if(Trigger.isAfter)
    {
        for(Case icas:Trigger.New)
        {
            if((trigger.newMap.get(icas.id).Status!= trigger.oldMap.get(icas.id).Status) && icas.Status == 'Closed')
            {
                casid.add(icas.id);
                System.debug(casid);
            }
        }
        if(casid.size()>0)
        {
            cmsToUpdate = [select Id,completionDate from CaseMilestone where caseId IN :casid];
            System.debug(cmsToUpdate);
        }
        if(cmsToUpdate.size()>0)
        {
            for(CaseMilestone icasn:cmsToUpdate)
            {
                icasn.completionDate = System.now();
            }
            update cmsToUpdate;
        }
        
    }
    
   else
   {
    for(Case icas:Trigger.New)
    {
        if(icas.SuppliedEmail != null)
        {
            stemail.add(icas.SuppliedEmail);
            System.debug(stemail);
        }
    }
    if(stemail.size()>0)
    {
        custlst = [SELECT ID,Email__c FROM Customer__c WHERE Email__c IN:stemail];
        System.debug(custlst);
    }
    if(custlst.size()>0)
    {
        for(Customer__c icus:custlst)
        {
            mpemailtocustomer.put(icus.Email__c,icus);
            System.debug(mpemailtocustomer);
        }
    
    }
    List<Entitlement> entlst = [SELECT id,Name FROM Entitlement];
    if(entlst.size()>0)
    {
        for(Entitlement ient :entlst)
        {
            mpentitle.put(ient.Name,ient);
        }
    }
    
        for(Case icas : Trigger.New)
        {
            if(mpemailtocustomer.containskey(icas.SuppliedEmail))
            {
                icas.Customer__c = mpemailtocustomer.get(icas.SuppliedEmail).ID;           
            }
            if(icas.Origin == 'Email' ||  icas.Origin == 'Phone' || icas.Origin == 'Web')
            {
                icas.EntitlementId = mpentitle.get('Response').Id;
                System.debug(icas.EntitlementId);
            }
        }
    
    }
    }catch(exception e)
    {
        System.debug(e.getlinenumber()+e.getmessage());
    }
}
  • January 09, 2018
  • Like
  • 0
HI Friends, 
Please look in to below image and help to find issue. 

User-added image
  • January 05, 2018
  • Like
  • 0

HI Friends, 

Please help here, i am unable to activate check box, where i need to check.? 
page layout Custom Console Components

User-added image

  • January 04, 2018
  • Like
  • 0

HI Friends, 

i am unable to select Perent record from Child 
Here i have Child is Case and Parent is Customer, So from Case Suddenly perent linking function not working from last week onwords, Unable to understand the issue. Please help,

 

User-added image

  • January 04, 2018
  • Like
  • 0
HI Friends, 

I am Newbie in writing Test classes, Please do help with test code for this apex class. 

public with sharing class AccountController {
    public AccountController() {
    }
    public AccountController(ApexPages.StandardController controller) {

    }
Public String selectedTab {get; set;}
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    
    User U;
    
    public ApexPages.StandardSetController setCon {
        get{
            if(setCon == null){
                size = 25;
                U = [select id,Phone,name from User WHERE ID =:userinfo.getUserId()]; 
                string queryString = 'Select Name, Rating,Phone from Account order by Name';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT id,Name,Phone from Account Where Phone =:U.Phone AND Rating ='Hot']));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;
    }
    
    Public List<Account> getAccounts(){
        List<Account> accList = new List<Account>();
        for(Account a : (List<Account>)setCon.getRecords())
            accList.add(a);
        return accList;
    }
    
    public pageReference refresh() {
        setCon = null;
        getAccounts();
        setCon.setPageNumber(1);
        return null;
    }
}
 
  • January 04, 2018
  • Like
  • 0
HI Friends, 
I need test class for this apex class, Please do Help, 

public with sharing class LenderLoansController {
    public LenderLoansController() {
    }
    public LenderLoansController(ApexPages.StandardController controller) {

    }
Public String selectedTab {get; set;}
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    
    User U;
    
    public ApexPages.StandardSetController setCon {
        get{
            if(setCon == null){
                size = 25;
                U = [select id,Phone,name,Lender_ID__c from User WHERE ID =:userinfo.getUserId()]; 
                string queryString = 'Select Name, Customer_Name__c, Aadhaar__c, Mobile__c,Order_ID__c, Number_of_Installment__c from Loan__c order by Name';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT id,Name,Customer_Journey_Status__c,Current_Assigned_Lender__c , Number_of_Installment__c,Aadhaar__c, Mobile__c,Customer_Name__c,Order_ID__c from Loan__c Where Current_Assigned_Lender__c =:U.Lender_ID__c AND Customer_Journey_Status__c='Active']));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;
    }
    
    Public List<Loan__c> getLoans(){
        List<Loan__c> accList = new List<Loan__c>();
        for(Loan__c a : (List<Loan__c>)setCon.getRecords())
            accList.add(a);
        return accList;
    }
    
    public pageReference refresh() {
        setCon = null;
        getLoans();
        setCon.setPageNumber(1);
        return null;
    }
}
 
  • January 03, 2018
  • Like
  • 0
HI Folks. 
Please do Help.
How to Show Dashboards on Visualforce page Based on Current Loggedin User

Thanks in Advance
  • January 03, 2018
  • Like
  • 0
HI Folks, 

How to Hide Plus icon on tabs for custom profiles.
User-added image
  • January 03, 2018
  • Like
  • 0
Hi Friends, 

Help me with test class, 
Below is my Apex Code.

public class LenderLoansDetailsSearchController {
    public String LoanID {get;set;}
    public String Email {get;set;}
    public String PAN {get;set;}
    public String Mobile {get;set;}
    public List<Loan__c> lstofResult {get;set;}
    public String LenderID{get;set;}
  
    public LenderLoansDetailsSearchController(){
        LoanID = '';
        PAN = '';
        Email = '';
        Mobile = '';
        lstofResult = new List<Loan__c>();
        LenderID= [select id,Phone,Lender_ID__c, name from User WHERE ID =:userinfo.getUserId()].Lender_ID__c;     
    }
    
    public void SearchAcc(){
        lstofResult = new List<Loan__c>();
        lstofResult = [SELECT Id,Name,Mobile__c,Customer_Name__c,Customer_Journey_Status__c,EMI_Amount__c,Loan_Amount__c,Customer_Email__c,Current_Assigned_Lender__c,Pan_Card__c FROM Loan__c WHERE Pan_Card__c like :PAN+'%'  AND Current_Assigned_Lender__c =:LenderID LIMIT 999];
           
    if (lstofResult.size() == 0){
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Warning,'No Loans Found Please try With Correct values'));
       }
     
    }
    
    public void SearchAcc1(){
        lstofResult = new List<Loan__c>();
        lstofResult = [SELECT Id,Name,Mobile__c,Customer_Name__c,Customer_Journey_Status__c,EMI_Amount__c,Loan_Amount__c,Customer_Email__c,Current_Assigned_Lender__c,Pan_Card__c FROM Loan__c WHERE Customer_Email__c like :Email+'%' AND Current_Assigned_Lender__c =:LenderID LIMIT 999];
           
    if (lstofResult.size() == 0){
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Warning,'No Loans Found Please try With Correct values'));
       }
     
    }
    public void SearchAcc2(){
        lstofResult = new List<Loan__c>();
        lstofResult = [SELECT Id,Name,Mobile__c,Customer_Name__c,Customer_Journey_Status__c,EMI_Amount__c,Loan_Amount__c,Customer_Email__c,Current_Assigned_Lender__c,Pan_Card__c FROM Loan__c WHERE Name like :LoanID+'%' AND Current_Assigned_Lender__c =:LenderID LIMIT 999];
           
    if (lstofResult.size() == 0){
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Warning,'No Loans Found Please try With Correct values'));
       }
     
    }
    public void SearchAcc3(){
        lstofResult = new List<Loan__c>();
        lstofResult = [SELECT Id,Name,Mobile__c,Customer_Name__c,Customer_Journey_Status__c,EMI_Amount__c,Loan_Amount__c,Customer_Email__c,Current_Assigned_Lender__c,Pan_Card__c FROM Loan__c WHERE Mobile__c like :Mobile+'%' AND Current_Assigned_Lender__c =:LenderID LIMIT 999];
           
    if (lstofResult.size() == 0){
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Warning,'No Loans Found Please try With Correct values'));
       }
     
    }
}
  • January 02, 2018
  • Like
  • 0

Hi Folks, 
Error : Method does not exist or incorrect signature: void query(String) from the type Search at line 12 column 45    

Please help me. 

Apex Class: -

public with sharing class TestSOSLController {
Public List<account> accList{get;set;} 
 Public String searchStr{get;set;}
   Public TestSOSLController(){
   }
  
  Public void soslDemo_method(){
   accList = New List<account>();
   if(searchStr.length() > 1){
   String searchStr1 = '*'+searchStr+'*';   
   String searchQuery = 'FIND \'' + searchStr1 + '\' IN ALL FIELDS RETURNING  Account (Id,Name,Type,Rating,Phone)';
   List<List <sObject>> searchList = search.query(searchQuery);
   accList = ((List<Account>)searchList[0]);
   
   if(accList.size() == 0){
       apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Sorry, no results returned with matching string..'));
       return;
   }
   }
   else{
   apexPages.addmessage(new apexpages.message(apexpages.severity.Error, 'Please enter at least two characters..'));
   return;
   }
  }
}

  • January 02, 2018
  • Like
  • 0
Hi Folks, 

Want to search account on Visualforce page and based on Selected Option. 
Ex : Name, Phone, Email.
Above there parameters need to add like in a picklist on Visualforce page and there should be an option to enter some characters and the search Button. 
Then based on selected option and entered value data should query and display. 
Please help. 

Thanks in Advance.
  • December 29, 2017
  • Like
  • 0

HI Folks 

I got strucked in code coverage, Now i have 63% coverage, Please do help. 

 

@RestResource(urlMapping='/api/IVR/*')

global class IVRRestAPI 
{
  
    @HttpPost
    global static List<IVR__c> CreateIVR(List<createIVR> icretIVR) 
    {
        try{
        Set<String> loanId = new Set<String>();
        List<Loan__c> loanlst = new List<Loan__c>();
        Map<String,String> mpidtoname = new Map<String,String>();
        List<IVR__c> IVRlst = new List<IVR__c>();
        for(createIVR icret:icretIVR)
        {
            if(icret.LoanID != null)
            {
                loanId.add(icret.LoanID);
            }
        }
        System.debug('loanId '+loanId);
        if(loanId.size() > 0)
        {
            loanlst = [SELECT Id,Name FROM Loan__c WHERE Name IN:loanId];
        }
        System.debug('loanlst '+loanlst);
        if(loanlst.size() > 0)
        {
            for(Loan__c iloan:loanlst)
            {
                mpidtoname.put(iloan.Name,iloan.Id);
            }
        }
        System.debug('mpidtoname '+mpidtoname);
        for(createIVR icret:icretIVR)
        {
            IVR__c IVR = new IVR__c();
                         
            if(mpidtoname.containskey(icret.LoanID))
            {
                IVR.Loan_Id__c = mpidtoname.get(icret.LoanID);
            }
            
            IVR.Name = icret.IVRId;
            IVR.Merchant_Name__c = icret.MerchantName; 
            IVR.IVR_Number__c = icret.IVRNumber;
            IVR.Disbursed_Amount__c = Decimal.valueOf(icret.DisbursedAmount);
            
            IVR.Disbursed_Date_Time__c = date.ValueOf(icret.DisbursedDateTime);
            IVRlst.add(IVR);
        }
        if(IVRlst.size() > 0)
        {
            insert IVRlst;
            return IVRlst;
        }
        return null;
        }catch(exception e){System.debug(e.getmessage() + e.getlinenumber());return null;}
    }
    global class createIVR
    {
        public String IVRId;
        public String LoanID;
        public String DisbursedAmount;
        public String MerchantName;
        Public String DisbursedDateTime;
        Public String IVRNumber;
        
        public createIVR(String IVRId,String LoanID,String DisbursedAmount,String MerchantName,String DisbursedDateTime,String IVRNumber){}
        
    }
}


Test Class ​

@istest
public class IVRRestAPITest{
 static testMethod void  IVRRestAPITest(){

   IVRRestAPI reqst=new IVRRestAPI();
   String JsonMsg=JSON.serialize(reqst);

   RestRequest req = new RestRequest();   
    req.addHeader('Content-Type', 'application/json'); 
    req.requestURI = '/services/apexrest/api/IVR/CreateIVR';
    req.httpMethod = 'POST';
    req.requestBody = Blob.valueof(JsonMsg);
    
    RestResponse res = new RestResponse();
    RestContext.request = req;
    RestContext.response= res;

    Test.startTest();
    List<IVRRestAPI.createIVR> icretIVRList  = new List<IVRRestAPI.createIVR>();
    icretIVRList.add(new IVRRestAPI.CreateIVR('Name','LoanID','DisbursedAmount','MerchantName','DisbursedDateTime','IVRNumber') );
    IVRRestAPI.CreateIVR(icretIVRList);
    Test.stopTest();
   }
}


Below lines are not covered in test class.

18                loanId.add(icret.LoanID);
24            loanlst = [SELECT Id,Name FROM Loan__c WHERE Name IN:loanId];
29            for(Loan__c iloan:loanlst)
30            {
31                mpidtoname.put(iloan.Name,iloan.Id);
41                IVR.Loan_Id__c = mpidtoname.get(icret.LoanID);
49            IVR.Disbursed_Date_Time__c = date.ValueOf(icret.DisbursedDateTime);
50            IVRlst.add(IVR);
51        }
52        if(IVRlst.size() > 0)
53        {
54            insert IVRlst;
55            return IVRlst;
56        }
57        return null;

 

Please do help to get code coverage. 
Thanks in Advance.

  • March 13, 2018
  • Like
  • 1
HI Folks

I got strucked with test class, Please help with Test Class for below class.
 
@RestResource(urlMapping='/api/IVR/*')

global class IVRRestAPI 
{
  
    @HttpPost
    global static List<IVR__c> CreateIVR(List<createIVR> icretIVR) 
    {
        try{
        Set<String> loanId = new Set<String>();
        List<Loan__c> loanlst = new List<Loan__c>();
        Map<String,String> mpidtoname = new Map<String,String>();
        List<IVR__c> IVRlst = new List<IVR__c>();
        for(createIVR icret:icretIVR)
        {
            if(icret.LoanID != null)
            {
                loanId.add(icret.LoanID);
            }
        }
        System.debug('loanId '+loanId);
        if(loanId.size() > 0)
        {
            loanlst = [SELECT Id,Name FROM Loan__c WHERE Name IN:loanId];
        }
        System.debug('loanlst '+loanlst);
        if(loanlst.size() > 0)
        {
            for(Loan__c iloan:loanlst)
            {
                mpidtoname.put(iloan.Name,iloan.Id);
            }
        }
        System.debug('mpidtoname '+mpidtoname);
        for(createIVR icret:icretIVR)
        {
            IVR__c IVR = new IVR__c();
            IVR.Name = icret.IVRId;
            IVR.Disbursed_Amount__c = Decimal.valueOf(icret.DisbursedAmount);
            IVR.Merchant_Name__c = icret.MerchantName; 
            IVR.Disbursed_Date_Time__c = date.ValueOf(icret.DisbursedDateTime);
            IVR.IVR_Number__c = icret.IVRNumber; 
            if(mpidtoname.containskey(icret.LoanID))
            {
                IVR.Loan_Id__c = mpidtoname.get(icret.LoanID);
            }
            
            IVRlst.add(IVR);
        }
        if(IVRlst.size() > 0)
        {
            insert IVRlst;
            return IVRlst;
        }
        return null;
        }catch(exception e){System.debug(e.getmessage() + e.getlinenumber());return null;}
    }
    global class createIVR
    {
        public String IVRId;
        public String LoanID;
        public String DisbursedAmount;
        public String MerchantName;
        Public String DisbursedDateTime;
        Public String IVRNumber;
    }
}


I have tried with test class to get test code but unfortunately i got just "0" Please do help. 

@istest
public class IVRRestAPITest{

 static testMethod void  IVRRestAPI(){

   IVR__c  TestOpp=new IVR__c ();
   TestOpp.name='TestOpp1';
   TestOpp.Disbursed_Amount__c=234567;
   TestOpp.IVR_Number__c ='2345678';
   TestOpp.Merchant_Name__c ='Test';
   insert TestOpp;
   
   IVRRestAPI reqst=new IVRRestAPI();
   String JsonMsg=JSON.serialize(reqst);
   Test.startTest();

   RestRequest req = new RestRequest(); 
   RestResponse res = new RestResponse();

    req.requestURI = '/services/apexrest/api/IVR/CreateIVR';  //Request URL
    req.httpMethod = 'POST';
    req.requestBody = Blob.valueof(JsonMsg);
    RestContext.request = req;
    RestContext.response= res;
    Test.stopTest();

   }
}
 

Please do help.  

Thanks in Advance.

  • March 12, 2018
  • Like
  • 0
HI Folks, 

Need test class for below apex class.
 
public with sharing class ApexStartController {
    public ApexStartController() {
        params = System.currentPageReference().getParameters();
        // System.debug(params);
        execScript = false;
    }
    /** Parameter */
    public Map<String,String> params { get; set; }
    /** Question */
    public String q {
        get {
            if (q == null) {
                q = params.get('q');
                if (q != null)
                    q = EncodingUtil.urlDecode(q, 'UTF-8');
            }
            return q;
        }
        set; 
    }
    /** Apex Class */
    public String c {
        get { return params.get('a'); }
        set; 
    }
    /** Apex Method */
    public String m {
        get { return params.get('m'); }
        set; 
    }
    /** Parameter Name */
    public String n {
        get { return params.get('n'); }
        set; 
    }
    /** Parameter Value */
    public String v {
        get { return params.get('v'); }
        set; 
    }

    public Boolean execScript { get; set; }
    
    public PageReference doStart() {
        execScript = true;
        return null;
    }

    public PageReference doCancel() {
    PageReference pg;
        String r = params.get('r');
        if (r != null && r.length() > 0)

            pg=new PageReference(r);
            pg.setRedirect(true);
        return pg;
    }
}

I tried but getting error Attempt to de-reference a null object, and with 44% code coverage, please see below code and do need full help. 
 
@isTest 
public class ApexStartController_Test {
static testMethod void Apexstart() { 


Test.StartTest(); 
PageReference pageRef = Page.GenerateDocslink; // Add your VF page Name here
Test.setCurrentPage(pageRef);
ApexStartController Ln1 = new ApexStartController();
Ln1.doStart();
Ln1.doCancel();
Test.StopTest();
}
}

Thanks InAdvance. 
  • March 05, 2018
  • Like
  • 0
HI Folks, 
I have Onclick javascript button on Classic, now we need this button on Lightning pages, so i have developed lightning component but its not working not getting output, please do help. 

Original Onclick javascript button Code is :
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

var result = sforce.apex.execute("GeneratingNewDocLinkForLoanInDB","GeneratingDocLink", {extrnlid:"{!Loan__c.Loan_External_id__c}"}); 
location.reload();

My Apex class : 

global class GeneratingNewDocLinkForLoanInDB
{
    public static string accToken;
    public static string accsToken;
    public static String expireTime;
    public static String tokenType;
    public static String refToken;
    public Static blob response;
    public static String endpointurl;
    public static string ResponseString;
    public static string blobResult; 
   
    //public static Loan_Doc_Details__c iLDetails = new Loan_Doc_Details__c(); 
    public static list<Loan_Doc_Details__c> lstUpdate = new list<Loan_Doc_Details__c>();
    public static long str;
    
       
    global static void returnToken() 
    {    
        //Custom Settings
        Generate_Loan_Doc_Url__c iCustom = [SELECT Name,ClientId__c,Client_Secret__c,Login_URL__c,Password__c,User_Name__c,Active__c,
                                       EndPoint__c FROM Generate_Loan_Doc_Url__c WHERE Active__c = true];
        system.debug('iCustom'+iCustom);
        
        String loginUri = iCustom.Login_URL__c;
        String clientId = iCustom.ClientId__c;
        String targetString = iCustom.Client_Secret__c;
        String clientSecret = EncodingUtil.urlEncode(targetString,'UTF-8');
        String username = iCustom.User_Name__c;
        String password = iCustom.Password__c;
        endpointurl = iCustom.EndPoint__c;
        String reqbody = 'client_id='+clientId+'&client_secret='+clientSecret+'&scope=partners_api_sensitive&grant_type=client_credentials';
        System.debug(reqbody);
        HttpRequest req = new HttpRequest(); 
        req.setMethod('POST');
        req.setHeader('content-type','application/x-www-form-urlencoded');
        req.setEndpoint(loginUri);
        req.setBody(reqbody);
        Http http = new Http();
        HTTPResponse res = http.send(req);
        System.debug(res.getbody());
        
        //Custom Object - To check the access token expired or not
        Loan_Doc_Details__c iLDetails = [SELECT Id,Name,Access_Token__c,Active__c,Expiry_Time__c,Token_generated_time__c FROM Loan_Doc_Details__c 
                                            WHERE Active__c = true LIMIT 1];
        system.debug('iLDetails'+iLDetails);
        
        if(iLDetails.Token_generated_time__c != null){
        
            str = ((system.now().getTime() - iLDetails.Token_generated_time__c.getTime())/ 1000);
            system.debug(str);
        }
        
        system.debug(iLDetails.Access_Token__c);
        system.debug(iLDetails.Expiry_Time__c);
        
        if(iLDetails.Access_Token__c == '' || iLDetails.Access_Token__c == null || (iLDetails.Expiry_Time__c != null && str > iLDetails.Expiry_Time__c)){
            
            accessToken resp1 = (accessToken)JSON.deserialize(res.getbody(),accessToken.class);
            System.debug(resp1.access_token);
            accToken = resp1.access_token;System.debug(accToken);
            expireTime = resp1.expires_in;System.debug(expireTime);
            tokenType = resp1.token_type;System.debug(tokenType);
            
            //update custom object
            Loan_Doc_Details__c creds = new Loan_Doc_Details__c(Id = iLDetails.Id);
            system.debug('AccessToken length - '+accToken.length());
            creds.Access_Token__c = accToken;
            creds.Expiry_Time__c = decimal.valueof(expireTime);
            creds.Token_generated_time__c = system.now();
            system.debug('*****'+creds.Token_generated_time__c);
            lstUpdate.add(creds);
        
        } 
        else{
            accToken = iLDetails.Access_Token__c;
        }
    }

    Webservice static void GeneratingDocLink(String extrnlid)  
    {    
        returnToken();
        System.debug(extrnlid);

        Loan__c iloan = [SELECT ID,Loan_External_id__c FROM Loan__c WHERE Loan_External_id__c =:extrnlid];
        if(iloan.Loan_External_id__c !=null)
        {
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        req.setMethod('POST');
        system.debug(accToken);
        req.setHeader('Authorization', 'Bearer '+accToken);
        req.setHeader('Content-Type', 'application/octet-stream');
        System.debug('******'+endpointurl);
        String endpoint = endpointurl+'/'+iloan.Loan_External_id__c+'/'+'documents';
        system.debug(endpoint);
        req.setEndpoint(endpoint);
        req.setTimeout(100000);
        res = http.send(req);
        System.debug('******'+res.getbody());
        response = res.getbodyasblob();
        System.debug(Response);
               
        //update token details
        system.debug('*****'+lstUpdate);
        if(lstUpdate.size()>0){
            
            update lstUpdate;
        }      
       }        
    }  
    
    global class accessToken
    {
        public String id;
        public String access_token;
        public String expires_in;
        public String token_type;
    }
}
 


Using above code i have developed component and controller

Component :

<aura:component controller="GeneratingNewDocLinkForLoanInDB"
implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,force:hasSObjectName,lightning:actionOverride" access="global" >
	<ui:button label="Generate Document" press="{!c.Generatedoc}"/>
</aura:component>
 

Controller :

({
Generatedoc :function(component,event, helper){	
var result = (sforce.apex.execute("GeneratingNewDocLinkForLoanInDB","GeneratingDocLink", {extrnlid:"{!Loan__c.Loan_External_id__c}"})); 
location.reload();
}
})
 

Then added Quick action(TestButton) on Lightning page.

When i am clicking on TestButton getting popup with "Generate Document" Button. then when i clicks on  "Generate Document" button it is just reloading the page and not getting any output 

  • February 07, 2018
  • Like
  • 0
Hi ,
Here is the code for javascript button.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var records = result.getArray("records");
var f = new sforce.SObject("Appointment__c");
f.id = "{!Appointment__c.Id}";
f.Fini_Status__c = "Appt Canceled";
var user = sforce.connection.getUserInfo();
f.Cancelled_By__c =user.getuuserid;
f.Cancelled_Date_Time__c=new Date().toISOString();
sforce.connection.update([f]);