• Pooja Nekkalapudi
  • NEWBIE
  • 65 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 14
    Replies
LWC.js
getSelectedRec() { var selectedRecords = this.template.querySelector("lightning-datatable").getSelectedRows(); if(selectedRecords.length > 0){ console.log('selectedRecords are ', selectedRecords); let ids = ''; selectedRecords.forEach(currentItem => { ids = ids + ',' + currentItem.Id; }); this.selectedIds = ids.replace(/^,/, ''); this.lstSelectedRecords = selectedRecords; alert(this.selectedIds); } } async handleChange() { let records = this.template.querySelector('lightning-datatable') .getSelectedRows().map( // Converts the Array to desired field updates (record) => ({ ...record, [STATUS_FIELD.Role__c]: 'Actively Prospecting', sobjectType: OBJECT_NAME.Coverage_Team__c }) );
await updateRecords({ records }); }

LWC.html
  <lightning-button   variant="Neutral"
                            label="Selected Records"
                            title="Selected Records"
                            onclick={getSelectedRec} 
                            slot="actions"
                            icon-name="utility:check">
        </lightning-button>
                <lightning-button   variant="Neutral"
                            label="Update Records"
                            title="Update Records"
                            onclick={handleChange} 
                            slot="actions">
                            
        </lightning-button>
        <div style="border-top: 1px solid rgb(221 219 218);">
            <!-- datatable -->
            <lightning-datatable
                    key-field="id"
                    data={data}
                    columns={columns}
                    column-widths-mode="fixed">
            </lightning-datatable>
            <!-- /datatable -->
        </div>

Apex controller:
public with sharing class PA_WBTeam { @AuraEnabled (cacheable=true) public static List<Coverage_Team__c> getTeam(){ return [SELECT Actively_Prospecting_Team__c,Company__c,Contact_Status__c,Employee__c,Id,Location__c,My_Coverage_Team__c,Role__c,Sponsors__c,Status__c,Website__c FROM Coverage_Team__c WHERE Role__c='Suggested by ML Model' AND My_Coverage_Team__c = 'true' ]; }
@AuraEnabled public static void updateRecords(Coverage_Team__c[] records) { update records; } }
aura.com
<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable" access="global">
    <lightning:listView aura:id="listViewSuggestedCompanies"
    objectApiName="Coverage_Team__c"
    listName="My_Suggested_Companies"
    rows="5"
    showSearchBar="true"
    showActionBar="true"
    enableInlineEdit="true"
    showRowLevelActions="true"
    />

Need to add two buttons that launch a flow in modal dialog rather than in a new window/same window 
Shown Like below 
User-added image
On click should open
User-added image
case 'logacall': this[NavigationMixin.Navigate]
({ type: 'standard__objectPage',
attributes: { objectApiName: 'task', actionName: 'new' },
state : { defaultFieldValues:"WhatId=" + this.Id} });
break;

How to navigate to the Homepage after that save of new task, right now this takes to the new task record
 
import { LightningElement, track,api, wire } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { CurrentPageReference, NavigationMixin } from 'lightning/navigation';
import { handleMonitoringLog } from 'c/ent_MonitoringLogFacade';
import getColumnNames from '@salesforce/apex/PA_My_Prospects_Datatable_Cont.getColumnNames';
import updateProspects from '@salesforce/apex/PA_My_Prospects_Datatable_Cont.updateProspects';
import getDualListBoxVals from '@salesforce/apex/PA_My_Prospects_Datatable_Cont.getDualListBoxVals';
import removeMeFromTeam from '@salesforce/apex/PA_My_Prospects_Datatable_Cont.removeMeFromTeam';
import { loadScript } from 'lightning/platformResourceLoader';
import jQuery from '@salesforce/resourceUrl/ent_JQuery';
export default class slDatatableWrapper extends NavigationMixin(LightningElement) {

    @track data = [];
    @track relatedData = [];
    @track draftValues = [];
    lastSavedData = [];
    @track queryColumnsString='';
    @track columns;
    @track columnsActions=[
        { label: 'Edit Company', name: 'edit' },
        { label: 'Edit Industry, Sector, Sub-Sector', name: 'edit_industry'},
        { label: 'Manage Board Members', name: 'manage_board_members'},
        { label: 'Manage Sponsors', name: 'manage_sponsors'},
        { label: 'Remove Me from Coverage Team', name: 'remove_me'},
        { label: 'New Last Activity', name: 'logcall'}];
-
-
-
-
 handleRowActions(event) {
        var eventName=event.target.dataset.id;
        const actionName = event.detail.action.name;
        const row = event.detail.row;
        this.prospectId = row.Id;
        this.prospectName=row.Name;
        switch (actionName) {
            case 'edit':
                this.isModalOpen=true;
                this.showChildTable=false;
                this.showEditForm=true;
                this.childListHeader='Edit';
                this.showDataSpinnerChild=false;
                handleMonitoringLog({Action_Taken__c:'Click',Component__c:eventName+'.'+actionName,Status__c:'Success',URL__c:window.location.href,Record_Interacted_With__c:this.prospectId});
                break;
            case 'manage_board_members':
                this.isModalOpen=true;
                this.showChildTable=true;
                this.childListHeader='Board Member';
                this.showDataSpinnerChild=true;
                handleMonitoringLog({Action_Taken__c:'Click',Component__c:eventName+'.'+actionName,Status__c:'Success',URL__c:window.location.href,Record_Interacted_With__c:this.prospectId});
                break;
-
-
-
-
case 'logcall':
                this[NavigationMixin.Navigate]({
                    type: 'standard__objectPage',
                    attributes: {
                        objectApiName: 'task',
                        actionName: 'new'
       
                    }
                });
                break;

        }
    }
How to get this row action logcall to pass in the rowID as whatID for new task 
Im trying to create a related list lightning component that does inline editing .. everything so far works fine if I pass the Parent id .. I would like it to dynamically pull the parent id depending on the record im on .. 

Apex controller : Project__c should be dynamically pulled depending on the record im on ( project is parent Historical p&l is child)
public class DataTableApexClass {
    @AuraEnabled
  
  public static List<Historical_Projected_P_L__c> getHPPL(){
 
      //  String url =  ApexPages.currentPage().getUrl();
     //  string str = url.right(23).substring(0,15);
    List <Historical_Projected_P_L__c> returnList = new List<Historical_Projected_P_L__c>();
        returnList = [select id, Project__c,Closed_Deal_Data__c,Label2__c, FY0__c,FY1__c,FY_3__c,FY_1__c,LTM__c,FY_2__c,FY2__c,FY3__c from Historical_Projected_P_L__c  where Project__c='a0w0d000003yohCAAQ' ];
        //Project__c= :currentRecordId];   
        return returnList;  
    } 
    @AuraEnabled
    public static void updateHPPL(List<Historical_Projected_P_L__c> HPPL ){
        update HPPL;
    }}

Lightning component :
<aura:component controller="DataTableApexClass"  implements="flexipage:availableForAllPageTypes,force:appHostable,flexipage:availableForRecordHome,force:hasRecordId,force:hasSObjectName" access="global">
    
    <aura:attribute name="data" type="Object"/>
    <aura:attribute name="columns" type="List"/>
    <aura:attribute name="errors" type="Object" default="[]"/>
    <aura:attribute name="draftValues" type="Object" default="[]"/>
    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
    <b>this is recordID {!v.recordID}</b><br/>
    <div class="slds-p-around_medium">
        <h1 class="slds-text-heading_large">Inline edit Data table</h1>
    </div>
    
    <!-- the container element determine the height of the datatable -->
    <div style="height: 300px">
        <lightning:datatable aura:id="dtTable"
                             columns="{! v.columns }"
                             data="{! v.data }"
                             strRecordId ="{! v.strRecordId}"
                             keyField="Id"
                             errors="{! v.errors }"
                             draftValues="{! v.draftValues }"
                             onsave="{! c.handleSaveEdition }"
                             />
    </div>
    
    
</aura:component>

Lightning controller : ({
    init: function (cmp, event, helper) {
        cmp.set('v.columns', [
            {label: 'Index', fieldName: 'Index__c', type: 'Number' , editable: true},        
            {label: 'Project', fieldName: 'Project__c', type: 'text' ,editable: false},
            {label: 'Financial Metrics', fieldName: 'Label2__c', type: 'text' ,editable: false},
            {label: 'FY-3', fieldName: 'FY_3__c', type: 'number' ,editable: true},
            {label: 'FY-2', fieldName: 'FY_2__c', type: 'number' ,editable: true},
            {label: 'FY-1', fieldName: 'FY_1__c', type: 'number' ,editable: true},
            {label: 'FY3', fieldName: 'FY3__c', type: 'number' ,editable: true},
            {label: 'FY2', fieldName: 'FY2__c', type: 'number' ,editable: true},
            {label: 'FY1', fieldName: 'FY1__c', type: 'number' ,editable: true}
        ]);
        helper.fetchData(cmp,event, helper);
    },
    handleSaveEdition: function (cmp, event, helper) {
        var draftValues = event.getParam('draftValues');
        console.log(draftValues);
        var action = cmp.get("c.updateHPPL");
        action.setParams({"HPPL" : draftValues});
        action.setCallback(this, function(response) {
            var state = response.getState();
            $A.get('e.force:refreshView').fire();        
        });
        $A.enqueueAction(action);     
    },
})


helper: 
({
    fetchData: function (cmp,event,helper) {
        var action = cmp.get("c.getHPPL");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var data = response.getReturnValue();
                cmp.set('v.data',data);
            }
            // error handling when state is "INCOMPLETE" or "ERROR"
        });
        $A.enqueueAction(action);
    }
})


ANy help will be appreciated 
 
Uncaught afterRender threw an error in 'ui:outputRichText' [Cannot read property 'querySelectorAll' of null]

Any ideas as to how to resolve this 
Lightning Cmp:
<div class="slds-modal__content slds-p-around--medium" style="display: flex;">
                    <ui:outputRichText class="slds-text-longform " value="{!v.cellVal}"/>
                </div>
Lightning Js :
({
    render: function(cmp, helper) {
        var ret = this.superRender();
        var isRef = cmp.get('v.curFld.isRef');
        var fldType = cmp.get('v.curFld.fldType');
        var cmpType;
        var attrs = {};
       
        if(isRef) {

            cmpType = 'c:Link';
            attrs['curFld'] = cmp.get('v.curFld');
            attrs['cellVal'] = cmp.get('v.cellVal');
            attrs['lkupId'] = cmp.get('v.lkupId');

        } else {
            attrs.value = cmp.get('v.cellVal');
            if( fldType==='ID' || fldType==='COMBOBOX' || 
                fldType==='ENCRYPTEDSTRING' || fldType==='BASE64' || 
                fldType==='PICKLIST' || fldType === 'MULTIPICKLIST' || fldType === 'TIME') {
                cmpType = 'ui:outputRichText';
                
            } else if(fldType === 'LOCATION'){
                if(attrs.value){
                    cmpType='lightning:buttonIcon';
                    attrs.iconName ="utility:checkin";
                    attrs.onclick=  cmp.getReference("c.openMapModelBox"); 
                }
                

            }else if (fldType === 'DATE') {
    
                cmpType = 'ui:outputDate';
                
            }else if (fldType === 'DATETIME' ) {

                attrs.value=$A.localizationService.formatDateTimeUTC(cmp.get('v.cellVal'), "MM/DD/YYYY hh:mm a");
                cmpType = 'ui:outputRichText';
                
            } else if (fldType === 'BOOLEAN') {
                
                cmpType = 'ui:outputCheckbox';
                
            } else if (fldType === 'CURRENCY') {
                
                cmpType = 'ui:outputCurrency';
                
            } else if (fldType === 'DOUBLE' || fldType === 'INTEGER') {
                
                cmpType = 'ui:outputNumber';
                
            } else if (fldType === 'PERCENT') {
                
                cmpType = 'ui:outputNumber';
                
            } else if (fldType === 'EMAIL') {
                
                cmpType = 'ui:outputEmail';
                
            } else if (fldType === 'PHONE') {
                
                cmpType = 'ui:outputPhone';
                
            } else if (fldType === 'STRING' || fldType === 'TEXTAREA') {

                //var Components=[];
                $A.createComponents([
                ["aura:HTML", {
                    "tag": "div",
                    "HTMLAttributes": {
                        "class" : 'imgSize',
                        "onclick": cmp.getReference('c.handlePress'),
                        "Id" : cmp.get('v.cellVal')
                    }
                }],
                ["ui:outputRichText", {
                        "class" : 'imgSize',
                        "value": cmp.get('v.cellVal')
                    }]
                    ],
                    function(Components, status, statusMsgLst) {
                    if(cmp.isValid()){
                            var divTag = Components[0];
                            var textTag = Components[1];
                            var divBody =divTag.get("v.body");
                            divBody.push(textTag);
                            divTag.set("v.body",divBody);

                             var body = cmp.get('v.body');
                             body.push(divTag);
                             cmp.set('v.body', body);
                    }
                });
                return ret;
                // cmpType.push("ui:outputRichText");
                
            } else if (fldType === 'URL') {
                attrs.label = cmp.get('v.cellVal');
                attrs.target='_blank';
                cmpType = 'ui:outputURL';
                
            }
            
            /* Not currently handling images */

            
            if(fldType === 'PERCENT' && attrs.value) {
                attrs.value += '%';
            }
            
            if(fldType === 'DATE' && attrs.value) {
                attrs.format = 'M/DD/YYYY';
            }
            
            // if(fldType === 'DATETIME' && attrs.value) {
            //     attrs.format = 'M/DD/YYYY h:mm a';
            // }
        }
        if(cmpType){
           $A.createComponent(cmpType, attrs, function(newCmp, status, statusMsgLst) {
                if(cmp.isValid()){
                    var body = cmp.get('v.body');
                    body.push(newCmp);
                    cmp.set('v.body', body);
                }
            }); 
        }
        return ret;
        
    }
})

 
Is there a way to clone a case and make the orignal case the Parent on the cloned case?
Im tryig to convert a JS button to work as lightning button or even could be a quick action
{!REQUIRESCRIPT('/soap/ajax/19.0/connection.js')}

function updatefield() {
var record = new sforce.SObject('CustomObject__c');
record.id = '{!CustomObjec__c.Id}';
record.CheckBox__c = 'true';
var records=new Array();
records[0]=record;
var result = sforce.connection.update(records);
if (result[0].getBoolean("success")) window.location.reload()
else alert(result[0].errors.message);
}
try{
updatefield();
}
catch(ex){
alert(ex);
}

According to this Im creating a update a record qucik action n pre defining the check box to true but it isnt quite working or may be Im reading the code wrong??
Below is the class that updates sharing of person accounts
Each person account has a Record Owner and can only see their owned records, but once few person accounts are grouped together(households__Household__c) as a relation group and each of the person accounts are its members (households__Householdmember__c) their respective owners all should get sharring rule set to see all those records that come under one group. We have had trouble getting the batch job that runs of this to work, we noticed that when creating new shares we have not accounted for inactive record owners, how do I acheive this ? on the bolded code how do I add a if userid is active then only perform the create new share

public without sharing class SL_HouseholdMember_Handler {

    static Map<Id,RecordType> mapFamily_Household;

    static {
                mapFamily_Household = new Map<Id,RecordType>([
                    SELECT Id, DeveloperName FROM RecordType WHERE SobjectType = 'households__Household__c' AND DeveloperName IN ('Family', 'Household')
                ]);
    }

    public static void updateOwnerOnInsert( Map<ID, households__HouseholdMember__c> hhMembers ) {
        
        Set<Id> set_ParentIds = new Set<Id>();
        for(households__HouseholdMember__c hhm : hhMembers.values()) set_ParentIds.add(hhm.households__Household__c);
        

        Map<Id,Integer> mapHhId2ChildCount = new Map<Id,Integer>();
        Integer tmpInt;
        for(households__HouseholdMember__c hhm : [SELECT Id, households__Household__c FROM households__HouseholdMember__c WHERE households__Household__c IN :set_ParentIds]) {
            if(!mapHhId2ChildCount.containsKey(hhm.households__Household__c)) mapHhId2ChildCount.put(hhm.households__Household__c, 0);
            tmpInt = mapHhId2ChildCount.get(hhm.households__Household__c);
            tmpInt++;
            mapHhId2ChildCount.put(hhm.households__Household__c, tmpInt);
        }
        

        Set<Id> set_ParentId_toNewOwner = new Set<Id>();
        for(households__HouseholdMember__c hhm : hhMembers.values()){
            if(mapHhId2ChildCount.get(hhm.households__Household__c) == 1)
                set_ParentId_toNewOwner.add(hhm.households__Household__c);
        }

        

        if(set_ParentId_toNewOwner.size() > 0) {
            
            String profileName3letter = [SELECT Name FROM Profile WHERE Id = :UserInfo.getProfileId() LIMIT 1].Name.substring(0,3);
            
            Id newOwnerId;
            SL_WM_Config__c cs = SL_WM_Config__c.getOrgDefaults();
            
            
            if(profileName3letter == 'IMC') newOwnerId = cs.IMC_Relationship_Group_Owner__c;
            if(profileName3letter == 'PCA') newOwnerId = cs.PCA_Relationship_Group_Owner__c;
            

            if(newOwnerId != null) {
                List<households__Household__c> lstHH = [SELECT Id, OwnerId FROM households__Household__c WHERE Id IN :set_ParentId_toNewOwner];
                
                for(households__Household__c hh : lstHH) {
                    hh.OwnerId = newOwnerId;
                }
                
                update lstHH;
            }
        }
    }


    public static void householdMember_Share( Map<ID, households__HouseholdMember__c> hhMembers, String mode) {
        
        Map<Id,Set<Id>> mapHhId2setUser = new Map<Id,Set<Id>>();

        Set<Id> set_HhIds = new Set<Id>();
        for(households__HouseholdMember__c hhm : hhMembers.values()) {
            set_HhIds.add(hhm.households__Household__c);
            mapHhId2setUser.put(hhm.households__Household__c, new Set<Id>());
        }

        Map<Id,Set<Id>> mapHhId2setAccountId = new Map<Id,Set<Id>>();
        Set<Id> setAccountId = new Set<Id>();

        if (set_HhIds.size() >0){
            for(households__HouseholdMember__c hhm : [SELECT households__Household__c, households__Account__c FROM households__HouseholdMember__c WHERE households__Household__c IN :set_HhIds]) {
                if(!mapHhId2setAccountId.containsKey(hhm.households__Household__c)) mapHhId2setAccountId.put(hhm.households__Household__c, new Set<Id>());
                mapHhId2setAccountId.get(hhm.households__Household__c).add(hhm.households__Account__c);
                setAccountId.add(hhm.households__Account__c);
            }
        }
        
        Map<Id,Set<Id>> mapAccountId2setUser = new Map<Id,Set<Id>>();
        if (setAccountId.size() > 0){
            for(AccountTeamMember atm : [SELECT AccountId, UserId FROM AccountTeamMember WHERE AccountId IN :setAccountId]) {
                
                Set<Id> userIDSet = new Set<Id>();

                if(mapAccountId2setUser.containsKey(atm.AccountId)) {
                    userIDSet = mapAccountId2setUser.get(atm.AccountId);
                }
                userIDSet.add(atm.UserId);
                mapAccountId2setUser.put(atm.AccountId, userIDSet);
            }
        }

        if (mapAccountId2setUser.size() > 0){
        
            for(Id hhId : mapHhId2setAccountId.keySet()) {
                //mapHhId2setUser.put(hhId, new Set<Id>());
                for(Id accountId : mapHhId2setAccountId.get(hhId)) {
                    //if(!mapHhId2setUser.containsKey(hhId)) mapHhId2setUser.put(hhId, new Set<Id>());
                    if (mapAccountId2setUser.containsKey(accountId)){
                        mapHhId2setUser.get(hhId).addAll(mapAccountId2setUser.get(accountId));
                    }
                }
            }
        }
        updateShares(mapHhId2setUser);
        
    }

    public static void updateSharesForRelationshipGroup(Id relGroupID){

        Map<Id, Set<Id>> houseHoldIDToAccountIdSet = new Map<Id, Set<Id>>();
        Set<Id> householdIDSet = new Set<Id>();

        houseHoldIDToAccountIdSet.put(relGroupID, new Set<ID>());
        householdIDSet.add(relGroupID);

        processHouseHoldMembers(householdIDSet, houseHoldIDToAccountIdSet);
    }

    public static void updateSharesForAccount(List<Account> personAccountList){

        updateSharesForAccount((new Map<Id, Account>(personAccountList)).keySet());

    }

    public static void updateSharesForAccount(Set<Id> personAccountIDset){

        Map<Id, Set<Id>> houseHoldIDToAccountIdSet = new Map<Id, Set<Id>>();
        
        List<Households__HouseholdMember__c> householdMembers = [select Id, Households__Household__c from households__HouseholdMember__c where households__Account__c in :personAccountIDset];
        Set<Id> householdIDSet = new Set<Id>();

        for (Households__HouseholdMember__c member : householdMembers){
            householdIDSet.add(member.Households__Household__c);
            houseHoldIDToAccountIdSet.put(member.Households__Household__c, new Set<Id>());
        }
        
        processHouseHoldMembers(householdIDSet, houseHoldIDToAccountIdSet);

    }

    public static void updateSharesForAccount(Id personAccountID){

        //determine what users are needed per household that this account is part of
        Set<Id> accountIDSet = new Set<Id>();
        accountIDSet.add(personAccountID);
        updateSharesForAccount(accountIDSet);
        
        //get all 
        
       

    }
    public static void processHouseHoldMembers(Set<Id> householdIDSet, Map<Id, Set<Id>> houseHoldIDToAccountIdSet){


        Map<Id, Set<Id>> accountIDToCovgTeamSet = new Map<Id, Set<Id>>();
        //get all household members, for the household
        List<Households__HouseholdMember__c> allHouseholdMembersOfGroups = [select Id, Households__Household__c, Households__Account__c from households__HouseholdMember__c where Households__Household__c in :householdIDSet];

        //get all accounts 
        Set<Id> accountIDSet = new Set<Id>();

        for (Households__HouseholdMember__c member : allHouseholdMembersOfGroups){
            accountIdSet = houseHoldIDToAccountIdSet.get(member.Households__Household__c);
            accountIdSet.add(member.Households__Account__c);
            houseHoldIDToAccountIdSet.put(member.Households__Household__c, accountIdSet);

            accountIDSet.add(member.Households__Account__c);
            accountIDToCovgTeamSet.put(member.Households__Account__c, new Set<Id>());
        }

        //get all coverate teams
        List<AccountTeamMember> covgTeamMembers = [select AccountId, UserId from AccountTeamMember where AccountId in :accountIDSet];

        for (AccountTeamMember teammember : covgTeamMembers){
            Set<Id> covgTeamSet = accountIDToCovgTeamSet.get(teammember.AccountId);
            covgTeamSet.add(teammember.UserId);   
            accountIDToCovgTeamSet.put(teammember.AccountId, covgTeamSet);         
        }

        Map<Id, Set<ID>> householdToUserIdSet = new Map<Id, Set<ID>>();
        //get all household members that this account is a memmebr of, get coverage teams members of household members
        for (Id householdIDKey : houseHoldIDToAccountIdSet.keySet()){
                Set<Id> userIDSet = new Set<Id>();
                if (householdToUserIdSet.containsKey(householdIDKey)){
                    userIDSet = householdToUserIdSet.get(householdIDKey);
                }
               //get accountidset for household
                Set<Id> accountIDForHouseholdSet = houseHoldIDToAccountIdSet.get(householdIDKey);
                //get users
                for (Id accID : accountIDForHouseholdSet){
                    userIDSet.addAll(accountIDToCovgTeamSet.get(accID));
                }
                householdToUserIdSet.put(householdIDKey,userIDSet);
        }
        

        if (householdToUserIdSet.size() > 0){
            updateShares(householdToUserIdSet);
        }

    }

    public static void updateShares(Map<Id,Set<Id>> mapHhId2setUsers_Needed) {
        
        List<households__Household__share> lstShares  = new List<households__Household__share>();
        
        Set<Id> set_UserIds = new Set<Id>();
        for(Id accountId : mapHhId2setUsers_Needed.keySet()) set_UserIds.addAll(mapHhId2setUsers_Needed.get(accountId));
        
        //Id rowCauseID = Schema.households__Household__share.RowCause.AccountCoverageSync__c;
        if (mapHhId2setUsers_Needed.size() > 0 ){
            lstShares = [
                SELECT ParentId, UserOrGroupId  //AccessLevel, RowCause, Id
                FROM households__Household__share 
                WHERE ParentId IN :mapHhId2setUsers_Needed.keySet() 
                    AND RowCause = :Schema.households__Household__share.RowCause.AccountCoverageSync__c
                    //AND UserOrGroupId IN :set_UserIds
            ];
        }
        

        Map<Id,Set<Id>> mapHhId2setUsers_Exist = new Map<Id,Set<Id>>();
        if (lstShares.size() > 0){
            for(households__Household__share hhs : lstShares) {
                if(!mapHhId2setUsers_Exist.containsKey(hhs.ParentId)) mapHhId2setUsers_Exist.put(hhs.ParentId, new Set<Id>());
                mapHhId2setUsers_Exist.get(hhs.ParentId).add(hhs.UserOrGroupId);
            }
        }
        


        // Create NEW shares
        List<households__Household__share> lstShare_toInsert = new List<households__Household__share>();
        Set<Id> curSet_Exist;
        for(Id hhId : mapHhId2setUsers_Needed.keySet()) {
            curSet_Exist = mapHhId2setUsers_Exist.get(hhId);
            //if(curSet_Exist != null) {
                for(Id userId : mapHhId2setUsers_Needed.get(hhId)) {
                    if( curSet_Exist == null || ( curSet_Exist != null && !curSet_Exist.contains(userId) ) ) {
                        // TODO Insert Record
                        households__Household__share newShare = new households__Household__share();
                        newShare.ParentId = hhId;
                        newShare.UserOrGroupId = userId;
                        newShare.AccessLevel = 'Edit';
                        newShare.RowCause =  Schema.households__Household__share.RowCause.AccountCoverageSync__c;
                        lstShare_toInsert.add(newShare);
                    }
                }
            //}
        }
        
        if(lstShare_toInsert.size() > 0) insert lstShare_toInsert;



        // Delete NOT needed shares
        Map<Id,Set<Id>> mapHhId2setUsers_prepDelete = new Map<Id,Set<Id>>();
        Set<Id> set_UserIds_prepDelete = new Set<Id>();
        Set<Id> curSet_Needed;
        for(Id hhId : mapHhId2setUsers_Exist.keySet()) {
            curSet_Needed = mapHhId2setUsers_Needed.get(hhId);
            
            //if(curSet_Needed != null) {
                for(Id userId : mapHhId2setUsers_Exist.get(hhId)) {
                    if(curSet_Needed == null || ( curSet_Needed != null && !curSet_Needed.contains(userId) ) ){
                        if(!mapHhId2setUsers_prepDelete.containsKey(hhId)) mapHhId2setUsers_prepDelete.put(hhId, new Set<Id>());
                        mapHhId2setUsers_prepDelete.get(hhId).add(userId);
                        set_UserIds_prepDelete.add(userId);
                    }
                }
            //}
        }
        
        List<households__Household__share> lstShares_toDelete = new List<households__Household__share>();
        if (set_UserIds_prepDelete.size() > 0){
            for(households__Household__share hhs :[SELECT Id, ParentId, UserOrGroupId //, AccessLevel, RowCause 
                                                    FROM households__Household__share 
                                                    WHERE RowCause = :Schema.households__Household__share.RowCause.AccountCoverageSync__c and ParentId IN :mapHhId2setUsers_prepDelete.keySet() 
                                                        AND UserOrGroupId IN :set_UserIds_prepDelete])
            {
                if( mapHhId2setUsers_prepDelete.containsKey(hhs.ParentId) && mapHhId2setUsers_prepDelete.get(hhs.ParentId).contains(hhs.UserOrGroupId) ) {
                    lstShares_toDelete.add(hhs);
                }
            }
        }
        
        if(lstShares_toDelete.size() > 0) delete lstShares_toDelete;
    }

}
I know web to case doesnt allow attachments but they is a work around using VF page from force.com sites or API
has anyone does this to achive it ? any sample code as to how to do it or any documentation on how to set all of this up would be a great help
I would like to update a check box to true when a button is pressed on a custom object, how do I do this using lightning component
Will add more records to update later, Any help is apreciated as i am ne to lightning
Trying to add a Formula field ( which is a Hyperlink) on to the list view of contacts which on clicking takes you to the "send a email" salesforce functionality
Formula field :
HYPERLINK("https://test.salesforce.com/_ui/core/email/author/EmailAuthor?p2_lkid=contact.Id&rtype=003&p3_lkid =AccountId&retURL=/003?fcf=00BV0000001B5re","Send Email" )

Everything works except contact id and account id dont get pre populated they return blank.
 
How to pop up a alert and have a check box "is alert shown " update to true once the user reads the pop - up 
so far i have 
class:
public class PopUpAlert
{
public Opportunity opp;

  public PopUpAlert(ApexPages.StandardController controller){

   Opportunity opp = (Opportunity)controller.getRecord();
    opp=[select id,isAlertShown__c from Opportunity where Id=: opp.ID];
    
  }
  public void setAlertVal(){
opp.isAlertShown__c = true;
 update opp;
  }
}
VFpage:
<apex:page standardcontroller="Opportunity" extensions="PopUpAlert" >
<html><head>
<apex:form > <apex:actionFunction name="setAlertVal" action="{!setAlertVal}" />
<script type="text/javascript"> var msg="FYI test : confidential info";
if ( {!Opportunity.isAlertShown__c} == false)
{
alert(msg); setAlertVal();
} </script> </apex:form> </head>
window.onload = throwalert;
</html> </apex:page>

this does check the box
any ideas?

 
I already have VF page which has the Save and cancel button , I want to create a new button " Save & New ".. i do not know how to make it return to the page to create a new record 

public PageReference doFullSave(){
 // this is my Save method
}
public PageReference doFullSave1(){ // this is my save and new method which has to return to the save mode again 
   doFullSave();
  PageReference retPage = new PageReference('/'+ ApexPages.currentPage().getParameters().get('retURL'));
  PageReference returnPage = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
   return returnPage;
    }

VF page :
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!doFullSave}"/>
<apex:commandButton value="Cancel" action="{!doCancel}" immediate="true"/>
<apex:commandButton value="Save and New" action="{!doFullSave1}"/>
</apex:pageBlockButtons>

This is the url on the new record page 
sandbox--c.cs4.visual.force.com/apex/CallLog?CF00N6000000268Gm=test12345&CF00N6000000268Gm_lkid=a0wP00000010bHcIAI&retURL=%2Fapex%2FSL_MassEdit_CallLog%3FpId%3Da0wP00000010bHcIAI%26justView%3Dtrue%26page%3D0%26cbf%3Dnull%26cbaf%3Dnull%26qb%3DAll%26qs%3DAll%26qct%3DAll%26qtt%3D%26sortE%3DName%26sortD%3DASC%26cb_letterFilter%3DAll&scontrolCaching=1&sfdc.override=1
Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page crosssellvf: Class.CrossSellRExtensionController.save: line 17, column 1

public class CrossSellRExtensionController {
     public Account newPersonAccount {get; set;}
     public CrossSellRExtensionController(ApexPages.StandardController controller) {
    
           Cross_Sell_Opportunity__c csr = (Cross_Sell_Opportunity__c) controller.getRecord();
            
           csr = [Select Id, Name  from Cross_Sell_Opportunity__c where Id =: csr.Id];
           RecordType personAccountRecordType =  [SELECT Id FROM RecordType WHERE Name = 'Person Account' and SObjectType = 'Account'];
           Account newPersonAccount = new Account();
           newPersonAccount.Cross_Sell_Referral__c = csr.Id;
   
          }
           
public PageReference save() {
       insert newPersonAccount; //this is line 17
        PageReference pageRef = new PageReference('/' + newPersonAccount.Cross_Sell_Referral__c);
        pageRef.setRedirect(true);
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'new *contact* created.'));
        return pageRef;
     }
public PageReference cancel() {
     return new PageReference('/'+ newPersonAccount.Cross_Sell_Referral__c);
}
}
 
my class :

public class OpportunityExtensionController {
     public Case ca {get; set;}
     public OpportunityExtensionController(ApexPages.StandardController controller) {
           Opportunity opp = (Opportunity) controller.getRecord();
           opp = [Select Id, Name, AccountId from Opportunity where Id =: opp.Id];
           ca = new Case();
           ca.Pitch__c = opp.Id;
           ca.AccountId = opp.AccountId;
          }
           
public PageReference save() {
       insert ca;
       
        PageReference pageRef = new PageReference('/' + ca.Pitch__c);
        pageRef.setRedirect(true);
        
      
        return pageRef;
       
      
     }
public PageReference cancel() {
     return new PageReference('/'+ ca.Pitch__c);
}
}

my vf page :
<apex:page standardcontroller="Opportunity" extensions="OpportunityExtensionController"> <apex:sectionHeader title="Title" subtitle="Case Helper"/> <apex:form > <apex:outputPanel > </apex:outputPanel> <apex:pageMessages /> <apex:pageBlock title="Please fill in the details for creating a Case">


Once i hit save it returns to opportunity page, now how to i pop up or a alert message on the opp record saying New case created with case Id and caseNumber xxx
My class 
public class CrossSellRExtensionController {
     public Account ca {get; set;}
     public CrossSellRExtensionController(ApexPages.StandardController controller) {
           Cross_Sell_Opportunity__c csr = (Cross_Sell_Opportunity__c) controller.getRecord();
           csr = [Select Id, Name  from Cross_Sell_Opportunity__c where Id =: csr.Id];
           
           ca = new Account();
          
           ca.Cross_Sell_Referral__c = csr.Id;
           
          }
           
public PageReference save() {
       insert ca;
        PageReference pageRef = new PageReference('/' + ca.Cross_Sell_Referral__c);
        pageRef.setRedirect(true);
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'new *contact* created.'));
        return pageRef;
        
      
     }
public PageReference cancel() {
     return new PageReference('/'+ ca.Cross_Sell_Referral__c);
}
}



And my VF page :
<apex:page standardcontroller="Cross_Sell_Opportunity__c"  extensions="CrossSellRExtensionController">
 <apex:sectionHeader title="Title" subtitle="Person Accounts"/>
    <apex:form >
      <apex:outputPanel >
  
  </apex:outputPanel>
      
        <apex:pageMessages />
        <apex:pageBlock title="Please fill in the details for creating *Contacts*">
        
      <apex:pageBlockSection >
        <apex:inputField value="{!ca.RecordTypeId}" required="true"/><br/>
        <apex:inputField value="{!Cross_Sell_Opportunity__c.Name}" required="true"/><br/>
        <apex:inputField value="{!ca.Salutation}" /> &nbsp;
            <apex:inputField value="{!ca.FirstName}"  /><br/>
            <apex:inputField value="{!ca.LastName}"  required="true"/><br/>
             <apex:inputField value="{!ca.Name}" required="true"/><br/>
             <apex:inputField value="{!ca.PersonEmail}" required="true"/><br/>
              <apex:inputField value="{!ca.Status__c}" /><br/>
     
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save" /> 
         
            <apex:commandButton action="{!cancel}" value="Cancel"/>

         
</apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>

</apex:page>  

I am having trouble to create a person account and the VF page first name and last name are not editable they dont give a box to type in values , what can be done and also before I create a new Person Account , is there a way I coyld do a vlookup on the contact ( if firstname , lastName and email Id given thru VF page already exists ) and throw error saying contact already exists 
How to create a button that opens a visual force page from the opportunity object ,which will prompt to fill fields like 
Case record type 
Subject
description
contact name ( look up field)
account name  ( pre populated from the respective opprtunity record)
opportunity ( pre populated from the respective opprtunity record)
task_c ( custom picklist data type )
save button ( this will create a new case record with the given input values for above records)
cancel button
All the above are fields from case object
How to auto -populate user look up field on the case object? using the Web Email field on case object
I have a web email or SuppliedEmail standard fiel which holds the email address of the user 
Using this field I want to auto populate the respective user lookup
 
 /*error: System.NullPointerException: Attempt to de-reference a null object 
Class.UserAccessDetailsController.getObjectLabels: line 290, column 1
line 290 is this describe.get(op.SObjectType).getDescribe().getLabel()));
*/

 public List<NameLabel> getObjectLabels() {
        if (null == xObjectLabels) {
            List<NameLabel> result = new List<NameLabel>();
            Map<String,SObjectType> describe = Schema.getGlobalDescribe();

            
            for (ObjectPermissions op : [SELECT SObjectType FROM ObjectPermissions 
                                          WHERE Parent.Profile.Name = 'System Administrator'  ]) {
                result.add(new NameLabel(op.SObjectType, 
                                         describe.get(op.SObjectType).getDescribe().getLabel()));
            }
            result.sort();
            xObjectLabels = result;
        }
        return xObjectLabels;
    }
My class 
public class CrossSellRExtensionController {
     public Account ca {get; set;}
     public CrossSellRExtensionController(ApexPages.StandardController controller) {
           Cross_Sell_Opportunity__c csr = (Cross_Sell_Opportunity__c) controller.getRecord();
           csr = [Select Id, Name  from Cross_Sell_Opportunity__c where Id =: csr.Id];
           
           ca = new Account();
          
           ca.Cross_Sell_Referral__c = csr.Id;
           
          }
           
public PageReference save() {
       insert ca;
        PageReference pageRef = new PageReference('/' + ca.Cross_Sell_Referral__c);
        pageRef.setRedirect(true);
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'new *contact* created.'));
        return pageRef;
        
      
     }
public PageReference cancel() {
     return new PageReference('/'+ ca.Cross_Sell_Referral__c);
}
}



And my VF page :
<apex:page standardcontroller="Cross_Sell_Opportunity__c"  extensions="CrossSellRExtensionController">
 <apex:sectionHeader title="Title" subtitle="Person Accounts"/>
    <apex:form >
      <apex:outputPanel >
  
  </apex:outputPanel>
      
        <apex:pageMessages />
        <apex:pageBlock title="Please fill in the details for creating *Contacts*">
        
      <apex:pageBlockSection >
        <apex:inputField value="{!ca.RecordTypeId}" required="true"/><br/>
        <apex:inputField value="{!Cross_Sell_Opportunity__c.Name}" required="true"/><br/>
        <apex:inputField value="{!ca.Salutation}" /> &nbsp;
            <apex:inputField value="{!ca.FirstName}"  /><br/>
            <apex:inputField value="{!ca.LastName}"  required="true"/><br/>
             <apex:inputField value="{!ca.Name}" required="true"/><br/>
             <apex:inputField value="{!ca.PersonEmail}" required="true"/><br/>
              <apex:inputField value="{!ca.Status__c}" /><br/>
     
        </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="Save" /> 
         
            <apex:commandButton action="{!cancel}" value="Cancel"/>

         
</apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>

</apex:page>  

I am having trouble to create a person account and the VF page first name and last name are not editable they dont give a box to type in values , what can be done and also before I create a new Person Account , is there a way I coyld do a vlookup on the contact ( if firstname , lastName and email Id given thru VF page already exists ) and throw error saying contact already exists 
LWC.js
getSelectedRec() { var selectedRecords = this.template.querySelector("lightning-datatable").getSelectedRows(); if(selectedRecords.length > 0){ console.log('selectedRecords are ', selectedRecords); let ids = ''; selectedRecords.forEach(currentItem => { ids = ids + ',' + currentItem.Id; }); this.selectedIds = ids.replace(/^,/, ''); this.lstSelectedRecords = selectedRecords; alert(this.selectedIds); } } async handleChange() { let records = this.template.querySelector('lightning-datatable') .getSelectedRows().map( // Converts the Array to desired field updates (record) => ({ ...record, [STATUS_FIELD.Role__c]: 'Actively Prospecting', sobjectType: OBJECT_NAME.Coverage_Team__c }) );
await updateRecords({ records }); }

LWC.html
  <lightning-button   variant="Neutral"
                            label="Selected Records"
                            title="Selected Records"
                            onclick={getSelectedRec} 
                            slot="actions"
                            icon-name="utility:check">
        </lightning-button>
                <lightning-button   variant="Neutral"
                            label="Update Records"
                            title="Update Records"
                            onclick={handleChange} 
                            slot="actions">
                            
        </lightning-button>
        <div style="border-top: 1px solid rgb(221 219 218);">
            <!-- datatable -->
            <lightning-datatable
                    key-field="id"
                    data={data}
                    columns={columns}
                    column-widths-mode="fixed">
            </lightning-datatable>
            <!-- /datatable -->
        </div>

Apex controller:
public with sharing class PA_WBTeam { @AuraEnabled (cacheable=true) public static List<Coverage_Team__c> getTeam(){ return [SELECT Actively_Prospecting_Team__c,Company__c,Contact_Status__c,Employee__c,Id,Location__c,My_Coverage_Team__c,Role__c,Sponsors__c,Status__c,Website__c FROM Coverage_Team__c WHERE Role__c='Suggested by ML Model' AND My_Coverage_Team__c = 'true' ]; }
@AuraEnabled public static void updateRecords(Coverage_Team__c[] records) { update records; } }
Trying to add a Formula field ( which is a Hyperlink) on to the list view of contacts which on clicking takes you to the "send a email" salesforce functionality
Formula field :
HYPERLINK("https://test.salesforce.com/_ui/core/email/author/EmailAuthor?p2_lkid=contact.Id&rtype=003&p3_lkid =AccountId&retURL=/003?fcf=00BV0000001B5re","Send Email" )

Everything works except contact id and account id dont get pre populated they return blank.
 
I already have VF page which has the Save and cancel button , I want to create a new button " Save & New ".. i do not know how to make it return to the page to create a new record 

public PageReference doFullSave(){
 // this is my Save method
}
public PageReference doFullSave1(){ // this is my save and new method which has to return to the save mode again 
   doFullSave();
  PageReference retPage = new PageReference('/'+ ApexPages.currentPage().getParameters().get('retURL'));
  PageReference returnPage = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
   return returnPage;
    }

VF page :
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!doFullSave}"/>
<apex:commandButton value="Cancel" action="{!doCancel}" immediate="true"/>
<apex:commandButton value="Save and New" action="{!doFullSave1}"/>
</apex:pageBlockButtons>

This is the url on the new record page 
sandbox--c.cs4.visual.force.com/apex/CallLog?CF00N6000000268Gm=test12345&CF00N6000000268Gm_lkid=a0wP00000010bHcIAI&retURL=%2Fapex%2FSL_MassEdit_CallLog%3FpId%3Da0wP00000010bHcIAI%26justView%3Dtrue%26page%3D0%26cbf%3Dnull%26cbaf%3Dnull%26qb%3DAll%26qs%3DAll%26qct%3DAll%26qtt%3D%26sortE%3DName%26sortD%3DASC%26cb_letterFilter%3DAll&scontrolCaching=1&sfdc.override=1
Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page crosssellvf: Class.CrossSellRExtensionController.save: line 17, column 1

public class CrossSellRExtensionController {
     public Account newPersonAccount {get; set;}
     public CrossSellRExtensionController(ApexPages.StandardController controller) {
    
           Cross_Sell_Opportunity__c csr = (Cross_Sell_Opportunity__c) controller.getRecord();
            
           csr = [Select Id, Name  from Cross_Sell_Opportunity__c where Id =: csr.Id];
           RecordType personAccountRecordType =  [SELECT Id FROM RecordType WHERE Name = 'Person Account' and SObjectType = 'Account'];
           Account newPersonAccount = new Account();
           newPersonAccount.Cross_Sell_Referral__c = csr.Id;
   
          }
           
public PageReference save() {
       insert newPersonAccount; //this is line 17
        PageReference pageRef = new PageReference('/' + newPersonAccount.Cross_Sell_Referral__c);
        pageRef.setRedirect(true);
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'new *contact* created.'));
        return pageRef;
     }
public PageReference cancel() {
     return new PageReference('/'+ newPersonAccount.Cross_Sell_Referral__c);
}
}
 
How to create a button that opens a visual force page from the opportunity object ,which will prompt to fill fields like 
Case record type 
Subject
description
contact name ( look up field)
account name  ( pre populated from the respective opprtunity record)
opportunity ( pre populated from the respective opprtunity record)
task_c ( custom picklist data type )
save button ( this will create a new case record with the given input values for above records)
cancel button
All the above are fields from case object
How to auto -populate user look up field on the case object? using the Web Email field on case object
I have a web email or SuppliedEmail standard fiel which holds the email address of the user 
Using this field I want to auto populate the respective user lookup
 
 /*error: System.NullPointerException: Attempt to de-reference a null object 
Class.UserAccessDetailsController.getObjectLabels: line 290, column 1
line 290 is this describe.get(op.SObjectType).getDescribe().getLabel()));
*/

 public List<NameLabel> getObjectLabels() {
        if (null == xObjectLabels) {
            List<NameLabel> result = new List<NameLabel>();
            Map<String,SObjectType> describe = Schema.getGlobalDescribe();

            
            for (ObjectPermissions op : [SELECT SObjectType FROM ObjectPermissions 
                                          WHERE Parent.Profile.Name = 'System Administrator'  ]) {
                result.add(new NameLabel(op.SObjectType, 
                                         describe.get(op.SObjectType).getDescribe().getLabel()));
            }
            result.sort();
            xObjectLabels = result;
        }
        return xObjectLabels;
    }