• Ramakrishna Reddy Gouni
  • NEWBIE
  • 67 Points
  • Member since 2016
  • Senior Salesforce Developer

  • Chatter
    Feed
  • 2
    Best Answers
  • 1
    Likes Received
  • 10
    Likes Given
  • 5
    Questions
  • 63
    Replies
Hi,

As I am unable to complete the code coverage in batch apex.
global class countContactRecordsBatch implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext bc) {
        string query='select id,Census_Date__c from hed__Term__c where Census_Date__c=LAST_N_DAYS:1';
        system.debug('query' +query) ;
        return Database.getQueryLocator(query); 
    }
    
    global void execute(Database.BatchableContext bc, List<hed__Term__c> scope){
        
        list<hed__Term__c> termList=[select id from hed__Term__c where Census_Date__c=LAST_N_DAYS:1];
        list<hed__Course_Offering__c> moduleOfferingList=[select hed__Term__r.id,(select hed__Contact__r.id,hed__Program_Enrollment__r.Program__r.id  from hed__Course_Enrollment__r) from hed__Course_Offering__c where hed__Term__r.id IN:termList];
        Map<string,set<string>> termProgramContacts=new Map<string,set<string>>();
        for(hed__Course_Offering__c co:moduleOfferingList) {
            system.debug('Term Id-'+co.hed__Term__r.id);   
            
            for(hed__Course_Enrollment__c ce:co.hed__Course_Enrollment__r){
                string mapKey = co.hed__Term__r.id+'-'+ce.hed__Program_Enrollment__r.Program__r.id;
                if(ce.hed__Program_Enrollment__r.Program__r.id!=null){
                    if(termProgramContacts.containsKey(mapKey)){
                        set<string> existingValue = termProgramContacts.get(mapKey);
                        existingValue.add(ce.hed__Contact__r.id);
                        termProgramContacts.put(mapKey, existingValue);
                    }                       
                    else{
                        set<string> newValue = new set<string>();   
                        newValue.add(ce.hed__Contact__r.id);
                        termProgramContacts.put(mapKey,newValue);
                    }
                }
            }
        }
            
            system.debug('Program Contact- '+termProgramContacts);
            list<hed__Term__c> termProgramList=new list<hed__Term__c>();
            list <Program_Session__c> programSessionList = new list <Program_Session__c>();
            termProgramList=[select id,(select id,Program__r.id from Program_Sessions__r) from hed__Term__c where id IN:termList];
            Map<string,integer> updateCount = new Map<string,integer>();
            for(hed__Term__c termProgram:termProgramList){
                for(Program_Session__c ps:termProgram.Program_Sessions__r){
                    string tpKey = termProgram.id+'-'+ps.Program__r.id;
                    if(termProgramContacts.containsKey(tpKey)){
                        integer contactCount = termProgramContacts.get(tpKey).size();
                        integer existingCount = 0;
                        if(updateCount.containsKey(ps.id)){
                            existingCount = updateCount.get(ps.id);                         
                        }
                        updateCount.put(ps.id,contactCount+existingCount);//progran term id and count
                        system.debug('updateCount'+updateCount.values().size());
                    }
                    ps.Total_enrolments_actual__c=updateCount.get(ps.Id);
                    programSessionList.add(ps);
                    system.debug('Total_enrolments_actual__c' +ps.Total_enrolments_actual__c);                    
                    system.debug('termProgramList ' +termProgramList);            
                }
            }
            if(programSessionList!=null && !programSessionList.isEmpty()){
                update programSessionList;
                
                
            }
        
    }
            global void finish(Database.BatchableContext BC){
                
            }

       
    //code end
    
   
}
===
Test class
=====

@isTest
public class countContactRecordsBatchTest {
    
    static testMethod void contactRecords(){
        
        list<Program_Session__c> psList=new list<Program_Session__c>();
        list<Account> acc=new list<Account>();
        list<hed__Term__c> termList=new list<hed__Term__c>();//term 
        list<Program__c> programList=new list<Program__c>();
        list<hed__Course_Offering__c> mcList=new list<hed__Course_Offering__c>();
        list<hed__Course__c> courseList=new list<hed__Course__c>();
        list<hed__Program_Enrollment__c> prEnrollmentList=new list<hed__Program_Enrollment__c>();
        list<Contact> consList=new list<contact>();
        
        
        Account a=new account();
        a.Name='Test Account';
        acc.add(a);
        
        insert acc;
        
        hed__Term__c te=new hed__Term__c();
        te.Name='test term';
        te.hed__Account__c=acc[0].id;
        te.Census_Date__c=date.today();
        termList.add(te);
        insert termList;//Term
        
        Program__c pc=new Program__c();
        pc.Name='test program ';
        programList.add(pc);//Program ..
        
        
        //insert module offering
        hed__Course_Offering__c mc=new hed__Course_Offering__c();
        hed__Course__c cou=new hed__Course__c();
        cou.name='test course';
        cou.hed__Account__c=acc[0].Id;
        courseList.add(cou);
        insert courseList;
        
        mc.Name='Test Module Offering';
        mc.hed__Course__c=courseList[0].id;
        mc.hed__Term__c=termList[0].id;
        mcList.add(mc);
        
        
        //Insert contact
        contact con=new contact();
        con.lastName='test contact Name';
        consList.add(con);    
        
        
        //program Enrollment
        hed__Program_Enrollment__c pe=new hed__Program_Enrollment__c();
        pe.Program__c=programList[0].id;
        pe.hed__Contact__c=consList[0].id;
        prEnrollmentList.add(pe);
        
        
        Program_Session__c ps=new Program_Session__c();
        ps.Term__c=termList[0].id;
        //     ps.Program__c=programList[0].id;
        ps.Program__c=programList[0].id;
        //ps.Total_enrolments_actual__c=1;
        psList.add(ps);
        database.insert (psList,false);
        
        list<Program_Session__c> prs=[select id ,Term__r.id,Program__r.id,Total_enrolments_actual__c from Program_Session__c];
        for(Program_Session__c pccc:prs){
            pccc.Total_enrolments_actual__c=10;
        }
        
        test.startTest();
        
        database.SaveResult []sr=database.update(prs,false);
        countContactRecordsBatch obj=new countContactRecordsBatch();
        database.executeBatch(obj);
        test.stopTest();
    }
    
}

As I am getting 44% code coverage on it.
Any suggestions.

Thanks
Hay, 
Im new to "SOQL". And I had to interdgete website with salsforce. 
I need to get data in one query like that.
"select id,name, (select id,name,student__c,(SELECT Id,Name FROM student__r) from Sponsorships__r) from contact WHERE RecordTypeId='0126A000000MAV6QAO'"


My question is, in this query "student__c" related to the "Account" object. I need to get that account detail and after again inside I need to get that account related "Contact" table data.

another way to explain
1. need to get "contact" data  RecordTypeId='0126A000000MAV6QAO'
2. with that I need to get "SponsorshipNEW__c" related data. Re.ship.name ="Sponsorships__r"
3. and "SponsorshipNEW__c" object have an Id "student__c" this is Related to the "Account" object. I need to get that account Object also.
4. Next to that particular Account have the "Contact" table Id. I need to get that too.
Please give me is that posible to do. 
Need to get as an outer join query
 
For me if I go to settings it is showing like below how to create a namespace there is no edit 

Please check below image help me how I can create it 
User-added image
There is no Edit option that is what is showing for me in my org account
Hi,

In LWC, on the component load, I am fetching the latitude and longitude of the logged in user and trying to display it on the component. I have created two attributes named lat and lng and marked it with @track decorator so that whenever the value of these attributes is changed, the component will rerender automatically. I am setting the value of these attributes in connectedCallback, but the updated value is not getting reflected on the component. Below is the html and js files.
 
<template>
    <div class="slds-box">
        <div class="slds-text-heading--large">Weather Report - {lat} {lng}</div>
    </div>
</template>
 
import { LightningElement, track } from 'lwc';

export default class WeatherAppContainer extends LightningElement {
    @track lat;
    @track lng;
    connectedCallback() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(showPosition);
        }
        
        function showPosition(position) {
            console.log("position: ",position);
            console.log("position coords: ",position.coords);
            console.log("position coords lat: ",position.coords.latitude);
            this.lat = position.coords.latitude; 
            this.lng = position.coords.longitude; 
            console.log("lat: ",this.lat);
            console.log("lng: ",this.lng);
        }
    }

}

The console "position coords lat" prints the value correctly, but the next console statment does not get printed. I am guessing that we cannot use this keyword in the connectedCallback. Any pointers how to solve this? Thanks.
I‘ve created a managed package that includes objects with Lightning Record Pages (LRP).

When I attempt to install the managed package in a test environment, I get the error “Small is not a supported form factor" which causes my install to fail.

I’ve traced this error back to the LRP activation.

If I activate a LRP as an Org Default I’m given the option to make it the default for Desktop, Phone, or Desktop and Phone.

I chose Desktop and Phone because why wouldn’t I want users to have a good mobile experience. 

But the Phone / mobile option caused the error.  I verified this by changing the activation to Desktop only and the install worked. 

Interestingly, if I go down the “App, Record Type, and Profile” activation path (some of my objects have different record types with different LRPs) I don’t get an option to choose Phone.  Desktop is the only option.

So, is there a way to activate LRPs for Phone without causing errors? 

If not, any idea why Salesforce give the option of assigning an LRP as the Phone view?   
What logical operator should work in lightning conditions
I am working on one lightning component for a calendar on event object.

On single click in calendar its opening up edit page of event record creation but I just want want to do it on double click instead of single click.
Can anyone help me out in this issue please.
My code is below.
Component:
<aura:component controller="LightningCalender" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
	 <ltng:require styles="{!$Resource.Calender     + '/fullcalendar-3.9.0/fullcalendar.css'}"
                  scripts="{!join(',',
                           $Resource.Calender  + '/fullcalendar-3.9.0/lib/jquery.min.js',
                           $Resource.Calender  + '/fullcalendar-3.9.0/lib/moment.min.js',
                           $Resource.Calender  + '/fullcalendar-3.9.0/fullcalendar.js'
                           )}"
                  afterScriptsLoaded="{!c.afterScriptsLoaded}" />
    
    <ltng:require styles="/resource/calender/fullcalendar-3.9.0/fullcalendar.css"/>
    
    <aura:attribute name='Objectlist' type='Object[]'/>
    <aura:attribute name="buttonstate" type="Boolean" default="false"/>
    
     <lightning:buttonStateful
        labelWhenOff="List View"
        labelWhenOn="Grid View"
        
        state="{!v.buttonstate}" onclick="{!c.handleClick }"/>
     
        <div id="calendar" class="slds-card">
      

    </div>
    <div id="listcalendar" class="slds-card"/>
</aura:component>

.js
({
	 afterScriptsLoaded: function(cmp,evt,helper){
         
         helper.fetchCalenderEvents(cmp);
        
    },
    
     handleClick : function(component, event, helper){ 
      
         var buttonstate = component.get("v.buttonstate");
         component.set("v.buttonstate",!buttonstate);
         if(!buttonstate){
          $("#listcalendar").show();
         $("#calendar").hide();
         $('#listcalendar').fullCalendar({
        	defaultView: 'listWeek',
             listDayFormat : true,
             events : component.get("v.Objectlist")
		});
        
         }
         else{
              $("#calendar").show();
           $("#listcalendar").hide();   
             helper.fetchCalenderEvents(component);
         }
        
    },

})

Helper.js
({
	loadDataToCalendar :function(component,data){  
        //Find Current date for default date
        var d = new Date();
        var month = d.getMonth()+1;
        var day = d.getDate();
        var currentDate = d.getFullYear() + '/' +
            (month<10 ? '0' : '') + month + '/' +
            (day<10 ? '0' : '') + day;
         
        var self = this;
        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,basicWeek,basicDay'
            },
            selectable : true,
            defaultDate: currentDate,
            editable: true,
            eventLimit: true,
            events:data,
            dragScroll : true,
             droppable: true,
            weekNumbers : true,
  eventDrop: function(event, delta, revertFunc) {

    alert(event.title + " was dropped on " + event.start.format());

    if (!confirm("Are you sure about this change?")) {
      revertFunc();
    }
      else{
          var eventid = event.id;
          var eventdate = event.start.format();
          self.editEvent(component,eventid,eventdate);
      }

  },
            eventClick: function(event, jsEvent, view) {
           console.log(event.id);
              var editRecordEvent = $A.get("e.force:editRecord");
              editRecordEvent.setParams({
              "recordId": event.id
           });
           editRecordEvent.fire();
          },
            dayClick :function(date, jsEvent, view) {
              console.log(date.format());
                var datelist = date.format().toString().split('-');
             console.log(datelist[0]);
                console.log(parseInt(datelist[1])-1);
              var datetime = new Date(datelist[0],parseInt(datelist[1])-1,parseInt(datelist[2])+1,0,0,0,0);
            console.log(datetime);
             var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": "Event",
        "defaultFieldValues": {
        'StartDateTime' :  datetime
        
    }
    });
    createRecordEvent.fire();
          },
            
            eventMouseover : function(event, jsEvent, view) {
            
          }
    });
    },
       
    
    formatFullCalendarData : function(component,events) {
        var josnDataArray = [];
        for(var i = 0;i < events.length;i++){
            var startdate = $A.localizationService.formatDate(events[i].StartDateTime);
            var enddate = $A.localizationService.formatDate(events[i].EndDateTime);
            josnDataArray.push({
                'title':events[i].Subject,
                'start':startdate,
                'end':enddate,
                'id':events[i].Id
            });
        }
      console.log('josnDataArray'+josnDataArray);
        return josnDataArray;
    },
     
    fetchCalenderEvents : function(component) {
         var action=component.get("c.getAllEvents");
       
         action.setCallback(this, function (response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var data= response.getReturnValue();
               console.log(JSON.stringify(data));
                 var josnArr = this.formatFullCalendarData(component,response.getReturnValue());
                this.loadDataToCalendar(component,josnArr);
                component.set("v.Objectlist",josnArr);
           
            } else if (state === "ERROR") {
                                 
            }
        });
        
        $A.enqueueAction(action);
       
    }, 
    
    editEvent : function(component,eventid,eventdate){
         var action=component.get("c.updateEvent");
console.log(eventdate);
         action.setParams({ eventid : eventid ,
                           eventdate : eventdate});

         action.setCallback(this, function (response) {
            var state = response.getState();
            if (state === "SUCCESS") {
            console.log('updated');
           
            } else if (state === "ERROR") {
                                 
            }
        });
        
        $A.enqueueAction(action);

    }
})


 
I've developped a screen searchResults Lightning web component which display liste of customers.
When I selected one customer and save it in salesforce(Account). I want to display it in tab and close searchResult screen.

To display created account, I've used NavigationMixin.Navigate
To close searchResult screen I've created Aura Component which contains my LWC to be able to use WorkspaceAPI and closeTab...

But when tab screen is closed the focus is positioned on the precedent tab not on created account tab.

How to positione focus on createdAccountTab?
thx for help

Code 

ParentAuraComponent.cmp

<aura:component implements="flexipage:availableForAllPageTypes" access="global">    
   
 <lightning:workspaceAPI aura:id="workspace"/> 
<div><c:searchClientCustomerByPhoneResults oncloseclicked="{!c.handleFilterChange}"/></div>    

</aura:component>



ParentAuraComonent.js

({
    handleFilterChange: function(component, event) {
var accountToDisplay = event.getParam('accountToDisplay');
var workspaceAPI = component.find("workspace"); 

workspaceAPI.getFocusedTabInfo().then(function(response) {
  
var focusedTabId = response.tabId;    
workspaceAPI.closeTab({tabId: focusedTabId});

 }).catch(function(error) { 
    console.log(error);

}
);


searchScreen.js(LWC)

saveRow() {

    saveAccountInSF({identifiant: this.identifiant}).then(result => {
                        
            if (result.length === 1) {  
                this.accountId = result[0].Id;                                                               
                /*Appel methode pour la consulation client */                                      
                this.navigateToRecordViewPage(); 
                closeTab();    
            } 
        }).catch(error => {
            this.error = error;                
        });
}        

        
closeTab(){
        var close = true;
        var accountToDisplay = this.accountId;
        //var urlToDisplay = this.url;
        const closeclickedevt = new CustomEvent('closeclicked', {
            detail: { close, accountToDisplay},
        });

         // Fire the custom event
        this.dispatchEvent(closeclickedevt);        
   }     
        
        
        
navigateToRecordViewPage() {
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.accountId,
                objectApiName: 'Account',
                actionName: 'view'
            }
        });
    }
I have one requirement: to make one of the multi select picklist fields as searchable. Meaning as I type the first letter, drop down with that value should be shown. How can that be done. I know it is not possible in Salesforce out of box. Can it be done through lightning components.

Thanks
I have a VF page which creates a new note (related list on event)when we click ' new note' custom button. once the records is created it redirects it back to event page showing certain fields of content note.I want to develop same functionality as mobile(lightning) compatible.Kindly suggest how to proceed.
Hi folks ,

I need to send email invoice to particular contacts of a account when I click a quick action button on Account page , it can be one contact or multiple, users will have the ability to select contact . Also having ability to add any extra e-mails id and since its a invoice email an attachment is also to be added which will be queried from attachment object basically  . I was thinking of using flows for this functionality but haven't been able to make sure if this is possible using flows . Can you please help with this ......

Thanks
Hi All,

I have a Custom button which uses Visualforce page with custom controller. Custom controller's save function does some calculations and redirects to Origin record page where my custon button is placed.
VF PAGE:

<apex:page standardController="ABC__c"  extensions="CustomController" action="{!save}">

</apex:page>
 
Custom controller:

public class CustomController {
    
// Constructor and other intializations

    public PageReference save()
    {
        try{
        
           // performing some calculations
            
            //return reference. 
            String returnUrl = URL.getSalesforceBaseUrl().toExternalForm() +'/' + EncodingUtil.URLENCODE(ApexPages.currentPage().getParameters().get(retURL),'UTF-8');        
            return new Pagereference(returnUrl);
			
        }catch(System.DMLException e){
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,e.getDmlMessage(0))); 
            return null;
        }
            
    } 
}




This is working as expected in Salesforce classic. But in Lightening experience the return page is opening in new tab and showing origin page in classic version.  I want to redirect the page to my Origin record page where my custon button is placed in Lightening experience and in the same tab.
Can anyone please help me to achieve this? Thanks in advace.
In Aura, we can do
$A.get('e.force:refreshView').fire();
to cause standard components to update.

How can we do an equivalent in LWC because sfdx refuses to publish .js code with $A in it saying the usage is disallowed in LWC?

For now i tricked it with 
eval("$A.get('e.force:refreshView').fire();");
but that is obviously less than ideal....
We have a VisualForce page that needs to be displayed on our website through an iframe. The problem is that both Mozilla and Chrome are displaying error message, saying that the connection is not secured. 

"Your connection is not secure
The owner of xyz.force.com has configured their website improperly. To protect your information from being stolen, Firefox has not connected to this website."

I checked the configuration of our site in Salesforce. It looks like HTTPS is enabled. We have a self-signed certificate, but that's it. 

We're using Salesforce Classic and for the moment there's no project to use tools like Canvas or Lightning out...  
Any suggestions? 
Thanks.  
Hello,

I am using lightning:datatble to display some list i have a requirement to use filters like start date end date and 2 picklist values ,user can choose any combination to update the list can any one suggest better design ?
Hi everyone,

Does anyone know the different badges that can be achieved by contributing to this forum (newbie, smartie, etc) and how many points match each level?

Regards,
Fred