• sksfdc221
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 9
    Replies
I have an apex class which updates the files count on custom object called Declined_Policy__c.

Below is my apex class:
 
public with sharing class Policy_FileCountClass {

    public static void updateAttachmentCountOnDps(List<ContentDocumentLink> DocuLinks) {
        Set<Id> policyids = new Set<Id>();
        for (ContentDocumentLink cdl : DocuLinks) {
            policyids.add(cdl.LinkedEntityId);
        }

        List<Declined_Policy__c> dpsToUpdate = [
            SELECT Id, Attachments__c,
                (SELECT Id FROM ContentDocumentLinks) 
            FROM Declined_Policy__c WHERE Id IN :policyids
        ];
        for (Declined_Policy__c dp : dpsToUpdate) {
            dp.Attachments__c = dp.ContentDocumentLinks.size();
        }
        update dpsToUpdate;
    }

}

Now, as per the above logic, i can able to the count in attachments__c field if there is any file attached to the record or if it is deleted. I could able to see the count in these scenarios. But the issue is that, if there is no file attached to the record when the record is inserted, the attachments__c field will be blank instead of displaying 0

Is there any way that i can update the above logic to get the attachments__c to display 0 by default if there is no file attached to it. Please suggest.
I have a requirement, where account name and account number if do not match with any other records, a custom field called alert_text__c will be updated with some text.

Below is the code snippet:
 
List<Account_Codes__c> records = [SELECT ID, Account_Name__c, Account_Number__c from Account_Codes__c where Account_Name__c != Null AND Account_Number__c != Null]; 

final String accName = newPPAs[0].Account_Name__c;
final String accNum = newPPAs[0].Account_Number__c;
for (Account_Codes__c record : records)
{
    if (record.Account_Name__c != accName && record.Account_Number__c != accNum)
    {
        record.Alert_Text__c = 'Account Number and Account Names are different';
    }
}

Now, the above logic is not working as expected and even when i provide different Account Name and Account Numbers, I am not able to populate the text in Alert_text__c field.

Can anyone please suggest changes in the above code so that i can get this done.

Thanks!
I have a VF page (standard controller) with an iframe URL and I want the page to be downloaded as pdf or a screenshot on button click.

The issue is that, when i render the page as pdf or when i update my code to capture the screenshot, all i'm seeing is the plain/blank screen instead of page content.

So, as a workaround i am using print option so that i can save the record as pdf.

Below is my VF Page:
 
<apex:page standardController="Account" showheader="false" sidebar="false">
       <apex:form >
            <apex:commandButton value="Print" onclick="window.print();"/>
        </apex:form>
  <apex:iframe src="https://app.powerbi.com/view?r=<custom-url>'" height="540" width="100%" frameborder="0">
  </apex:iframe>
</apex:page>

 Can anyone please suggest the changes to the above code so that I can download the vf page as pdf or screenshot instead of printing and saving it as pdf
I have a requirement where if the parent (Contact) has more than one child (Lead_Custom__c) and if atleast one child record has Terminated__c checked to true, the Contact's Terminated__c will be updated to true.

Can anyone please suggest the required logic so that I can get this done.

Thanks in advance!
I have a requirement to display and select child records on a selected record detail page.
This Lightning component, will be used on Account record page and that Account record's related contact records will be displayed with checkbox to select on the page.

Can anyone please suggest the possible approach w.r.t my requirement above.
I have a custom lightning component which is used to merge two duplicate leads (Lead_Custom__c).

In the component, when two leads are selected, on click of next button, process moves to next page.

 I have a requirement where if the selected 2 leads' custom field called Integrated_lead__c is true (Intergated_Lead__c = True), an error message should be displayed on click of next button

Apex Method:
@auraEnabled
    public Static List<Lead_Custom__c> processSelected(String contactstr) {
        system.debug('contactstr=======>' + contactstr);
        integer iCount;
        iCount = 0;
        String leadName;
        if (!String.isEmpty(userinp)) {
            leadName = userinp + '%' + userinput + '%';
            system.debug('if====' + leadName);
        } else {
            leadName = '%' + userinput + '%';
            system.debug('else====' + leadName);
        }
        List<Lead_Custom__c> selectedContacts = new List<Lead_Custom__c>();
        List<cContact> contactList = [select Name, First_Name__c, Integrated_Lead__c,  Last_Name__c, Id where Name like :leadName order by last_name__c, first_name__c limit 100];
        system.debug('contactList=======>' + contactList);
        if (contactList != null) {
            for (cContact cCon : contactList) {
                if (cCon.selected == true) {
                    iCount = iCount + 1;
                    selectedContacts.add(cCon.con);
                    if (iCount == 1) {
                        idParams = '?id1=' + cCon.con.id;
                    } else {
                        idParams += '&id2=' + cCon.con.id;
                    }
                }
            }
            selectedContactsstep2 = selectedContacts;
        }
        return selectedcontacts;
    }

Component controller.js:
processrecSelected: function(component, event, helper) {
        var action = component.get('c.processSelected');
        var strData = JSON.stringify(component.get('v.contactList'));
        console.log('strData===>'+strData);
        action.setParams({ 'contactstr' : strData});
        action.setCallback(this,function(response){
            
            if (response.getState() === "SUCCESS") {
                var res = response.getReturnValue();
                console.log('res===>'+res.length);
                
                if(res.length==2){
                    redirecttoMerge(res[0].Id,res[1].Id);
                }else if(res.length>2){
                    toastEvt('Please select at most two records to proceed');
                }else if(res.length==1){
                    toastEvt('Please select at most two records to proceed');
                }else{
                    toastEvt('Please select a record to proceed.');
                }
            }
        })
        $A.enqueueAction(action);
        function toastEvt(msg){
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                "title": "Error!",
                "type":"Error",
                "message": msg
            });
            toastEvent.fire();
        }
        function redirecttoMerge(conId1, conId2){
           
             
            var evt = $A.get("e.force:navigateToComponent");
            evt.setParams({
                componentDef : "c:Merge_Component_two",
                componentAttributes: { id1 : conId1,id2 : conId2 }
                
            });
            
            evt.fire();
        }
    }

From the above controller.js code, processrecSelected fires on click of next button. Can anyone please suggest the changes in the above code so that I can display error message when the 2 leads related integrated_lead__c is true.


 
I have a lightning component which is used to merge the custom lead object which is a duplicate. Here, I have a requirement that if the two selected leads are marked as true for Integrated_Lead__c field, then when clicked on merge, an error should be displayed on the page that "Leads cannot be merged".

Below is my Apex Class method:
 
@auraEnabled
public Static List<cContact> contactsearch(String userinp, String userinput) {
    system.debug(userinput + '=======' + userinp);
    errormsg = false;
    errormsg2 = false;
    contactList = new List<cContact>();
    String query;
    String leadName;
    if (!String.isEmpty(userinp)) {
        leadName = userinp + '%' + userinput + '%';
        system.debug('if====' + leadName);
    } else {
        leadName = '%' + userinput + '%';
        system.debug('else====' + leadName);
    }
    system.debug('leadName===>' + leadName);
    
        for (Lead_Custom__c c : [select Name, First_Name__c, Last_Name__c, Integrated_Lead__c, Id, Cell_Phone__c, Mailing_Street__c, Mailing_City__c, Mailing_State_Province__c from Lead_Custom__c where Name like :leadName]) {
            contactList.add(new cContact(c));
        }
    
    return contactList;
}
@auraEnabled
public Static List<cContact> getresults() {
    return contactList;
}

Lightning Component:
 
<aura:component controller="SearchDuplicateLeads_Lightning" implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
  
    <aura:handler name="init" value="{!this}" action="{!c.SearchDuplicateLeads}"/>
    <aura:attribute name="userinput" type="String" default=""/>
    <aura:attribute name="userinp" type="String" default=""/>
    <aura:attribute name="render" type="Boolean" default="false"/>
    <aura:attribute name="Spinner" type="boolean" default="false"/>
    
    <aura:attribute name="contactList" type="String[]" />
   
                                <aura:iteration items="{!v.contactList}" var="contacts">
                                    <tr class="slds-hint-parent">
                                        <td role="gridcell" class="mycol">
                                            <lightning:input type="checkbox" aura:id="selected" label=" " value="{!contacts.selected}" onchange="{!c.singleChecked}"/>
                                        </td>
                                        <td role="gridcell">
                                            <ui:outputText value="{!contacts.con.Name}" />
                                        </td>
                                        
                                    </tr>
                                </aura:iteration>
                                </tbody>
                            </table>
                        </div>
                        <lightning:button variant="brand" onclick="{!c.processrecSelected}" label="Next" class="cus-button"/>
                        <lightning:button variant="brand" onclick="{!c.Cancel}" label="Cancel" class="cus-button"/>
                    </aura:renderIf>
                </div>
            </div>
        </div>
    </div>
</aura:component>

Js:
 
processrecSelected: function(component, event, helper) {
    var action = component.get('c.processSelected');
    var strData = JSON.stringify(component.get('v.contactList'));
    console.log('strData===>'+strData);
    action.setParams({ 'contactstr' : strData});
    action.setCallback(this,function(response){
        if (response.getState() === "SUCCESS") {
            var res = response.getReturnValue();
            console.log('res===>'+res.length);
            if(res.length==2){
                redirecttoMerge(res[0].Id,res[1].Id);
            }else if(res.length>2){
                toastEvt('Please select at most two records to proceed');
            }else if(res.length==1){
                toastEvt('Please select at most two records to proceed');
            }else{
                toastEvt('Please select a record to proceed.');
            }
        }
    })
    $A.enqueueAction(action);
    function toastEvt(msg){
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "Error!",
            "type":"Error",
            "message": msg
        });
        toastEvent.fire();
    }
},

Now, from the above contactList, the merging will be done when two Custom Leads are selected. As per my requirement, if the selected two leads are having Integrated_Lead__c = True, then an error message should be displayed on the screen that "Leads cannot be merged" on click on next button.
​​​​​​​
Can anyone please suggest the changes so that I can get the error message displayed on screen
I found that for opprtunity, when hovered on stage, we can see total number of days that the record is in that stage. It is as follows:

User-added image

Now, when i hover on Lead status bar, I cannot able to see total number of days that the record is in that status

User-added image
Is this a standard functionality or is there any way that we can display total number of days on hover on lead record's status bar. Please suggest
I have a lightning component which inserts transfer record when clicked on Save button. Now, I have a process builder which creates 2 more records (rather clones this record) when the above record is saved. So a total of 3 records are getting inserted.

Below is my lightning component code which triggers save function

Lightning controller.js:
submitTransfer: function(component, event, helper) {
        helper.closeModelHeaderhelper(component);
            helper.submitTransferHelper(component, event, helper);
        helper.showSpinner(component);
    }
lightning helper.js:
submitTransferHelper: function(component, event, helper) {
        console.log("submitTransferHelper************************");
        var TransferRec = component.get("v.accountTransfer");       
        var action = component.get("c.insertAccountTransfer");
        action.setParams({
            accTrans: TransferRec,
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state == "SUCCESS") {
                console.log("SUCCESS*****");
                helper.showToast(
                    component,
                    event,
                    helper,
                    "success",
                    "Success!",
                    "Transfer Request was saved successfully."
                );
                helper.redirectToSobject(response.getReturnValue());
            } else if (state == "ERROR") {
                let errorMess = response.getError();
                console.log(
                    "response.getError()*****" +
                        JSON.stringify(response.getError())
                );
                helper.showToast(
                    component,
                    event,
                    helper,
                    "error",
                    "Error!",
                    errorMess[0].message
                );
            }
        });
        $A.enqueueAction(action);
    }

Now, when the save button is clicked, although there are 3 records that are getting created, the detail page of the record which is saved from lightning component is getting opened by default and for other 2 records which are inserted by process builder, I need to go back and open them from list view.

is there any way i can display list view when save button is clicked so that I can display all three records in the view and user can open any of the three records of there choice.

Please suggest
I have a requirement where the child record (Account_Transfer_Policy__c) should be updated with new Parent record (Account_Transfer__c) if the district_from__c of current parent do not match with district_Acct_Code__c of child record.

This new parent update will be done when District_from__c of any Account Transfer record and District_Acct_Code__c of child matches

Now, below is my trigger
trigger ATwithATP on Account_Transfer_Policy__c (after insert) {
    Map<Id,Account_Transfer__c> mapIDWithAccount = new Map<Id,Account_Transfer__c>();
    Map<string,Account_Transfer__c> mapATwithATP = new Map<string,Account_Transfer__c>();

    for (Account_Transfer__c acc : [select id,District_From__c from Account_Transfer__c where District_From__c != Null and createddate = TODAY ORDER BY createddate DESC ]){
       
        mapATwithATP.put(acc.District_From__c,acc);
    }
    
    list<Account_Transfer_Policy__c> ATP = new list<Account_Transfer_Policy__c>();
    for(Account_Transfer_Policy__c c : trigger.new){
        
        if(c.Account_Transfer__c !=null && c.Policy__r.District_Acct_Code__c != c.Account_Transfer__r.District_From__c){
            if(mapATwithATP.containsKey(c.Policy__r.District_Acct_Code__c)){
                c.Account_Transfer__c = mapATwithATP.get(c.Policy__r.District_Acct_Code__c).Id;
            }
        }
        ATP.add(c);
       
    }
    update ATP;
}

I'm not getting any error but the child is not updating with new parent record. Can anyone please suggest any changes in my code if I missed anything.
I have an custom object called Account_Velocity__c and it has a child object called Partner_Policies__c
Now, there is an automation in place which inserts Account_Velocity__c and its related child Partner_Policies__c. 

I have a requirement where, if the Partner_district__c field of Partner_Policies__c doesn't match with its parent's Account_District__c field, a new parent record should be created and this related Partner_Polcies__c record should go as a child record for that parent.

As of now, for a single Account_Velocity__c record, there are multiple Partner_Policies__c records which are inserting as a child irrespecive of Partner_district__c and Account_District__c field values. 

simple terms for understanding: 
Parent - Account_Velocity__c, field - Account_District__c
Child - Partner_Policies__c, field - Partner_District__c

I'm having very hard time finding appropriate logic for this requirement. Could anyone please help me out with this.  
I have a requirment where when 2 records are merged, the attachment related to merged record should be inserted to parent/master record. Below is my code related to this
 
List<Attachment> attObj = [SELECT body, bodylength, contenttype, description, isprivate, name, ownerid FROM Attachment WHERE ParentId = :id2];
            List<Attachment> newAttObj = new List<Attachment>();
            // Loop through the list and update the Name field
            for (Attachment a : attObj) {
                Attachment ax = new Attachment();
                ax.Body = a.Body;
                ax.contenttype = a.contenttype;
                ax.description = a.description;
                ax.isprivate = a.isprivate;
                ax.ParentId = id1;
                ax.name = a.name;
                ax.ownerid = a.ownerid;
                newAttObj.add(ax);
            }
            //Update the database
            insert newAttObj;

here id2 is the merged record and id1 is the master record.

So now, the issue here is that the attachment is not getting inserted to parent/master record after the merge. Even when I hardcode the id as ax.ParentId = '16 digit ID', the record is not getting inserted to parent record.

Now, as per my research, I understood that attachments are depricated in lightning. So as per that, I have updated my code as follows
 
List<ContentDocumentLink> newAttObj = new List<ContentDocumentLink>();
            
            list<ContentDocumentLink> contdoclink = [SELECT Id, LinkedEntityId, ContentDocumentId,Visibility, IsDeleted, ShareType,ContentDocument.Title,ContentDocument.createdDate, ContentDocument.FileType FROM ContentDocumentLink WHERE LinkedEntityId =:id2];
            //list<ContentDocument> contDoc = [Select Id ,Title from ContentDocument Where ID = :contdoclink];
            // Loop through the list and update the Name field
            for (ContentDocumentLink a : contdoclink) {
                ContentDocumentLink ax = new ContentDocumentLink();
                ax.ContentDocumentId = a.ContentDocumentId;
                ax.Visibility = a.Visibility;
                ax.ShareType = a.ShareType;
                ax.ContentDocument.Title = a.ContentDocument.Title;
                ax.LinkedEntityId = id1;
               // ax.ContentDocument.FileType = a.ContentDocument.FileType;
                //ax.ownerid = a.ownerid;
                newAttObj.add(ax);
            }
            //Update the database
            insert newAttObj;

Even now, I attachment is not getting updated to the master record Id.
Can anyone please suggest any changes if i missed anything
Below is my apex method where I'm updating Account_Transfer__c Records
private static void linkPoliciesAndHandleApprovalFlds(
    List<string> selectedPoliciesSet,
    Account_Transfer__c accTrans,
    Office__c toOffice,
    Office__c fromOffice
) {
    Map<Id, Account_Transfer__c> AcctransMap = new Map<Id, Account_Transfer__c>(); 
    String districtAccountCode = '';
    List<Policy__c> selectedPolicies = new List<Policy__c>(
        [
            SELECT
                Id,
                District_Acct_code__c,
                Account_Transfer__c,
                Plan_Code__c
            FROM Policy__c
            WHERE ID IN :selectedPoliciesSet
        ]
    );
    List<Account_Transfer_Policy__c> accTransferPolicy = new List<Account_Transfer_Policy__c>();
    for (Policy__c pol : selectedPolicies) {
        Account_Transfer_Policy__c atp = new Account_Transfer_Policy__c();
        atp.Account_Transfer__c = accTrans.Id;
        atp.Policy__c = pol.Id;
        accTransferPolicy.add(atp);
      
        
    }
    

    

    accTrans.District_To__c = districtAccountCode;
    AcctransMap.put(accTrans.id, accTrans);
    
    update AcctransMap.values();
    
    insert accTransferPolicy;
    
    Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
    req.setObjectId(accTrans.Id);
    req.setSubmitterId(UserInfo.getUserId());
    Approval.process(req);
    
}
Now this code isn't throwing me any errors but in the record page, I'm getting the error as
 
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
I am using Map here to get the ids of Account Transfer records and using them to update by calling map.values(). I'm wondering why it is mentioning that Ids are not specified in the update call.

Can anyone please suggest if there is anything missing
I have a requirement to enable a component based on selection in the page. Below is the screenshot of my page

LookupControllerImageFrom the above image, when a radio button is clicked, below lookup box should be enabled and when these two selections are made, next button should be enabled.

As of now, they are not dependent on any selections.

Below is my LWC code:

LookupController apex class:
public with sharing class LookupController {
    public LookupController() {

    }

    @AuraEnabled(cacheable=true)
    public static List<SObJectResult> getResults(String ObjectName, String fieldName, String value) {
        List<SObJectResult> sObjectResultList = new List<SObJectResult>();
        system.debug(fieldName+'-------------'+ObjectName+'---++----------'+value);
        if(String.isNotEmpty(value))
            for(sObject so : Database.Query('Select '+fieldName+' FROM '+ObjectName+' WHERE '+fieldName+' LIKE \'%' + value + '%\'')) {
                String fieldvalue = (String)so.get(fieldName);
                sObjectResultList.add(new SObjectResult(fieldvalue, so.Id));
            }
        
        return sObjectResultList;
    }
    
    public class SObJectResult {
        @AuraEnabled
        public String recName;
        @AuraEnabled
        public Id recId;
        
        public SObJectResult(String recNameTemp, Id recIdTemp) {
            recName = recNameTemp;
            recId = recIdTemp;
        }
    }
}

LookupController LWC HTML:
<template>
    <br>
    <fieldset class="slds-form-element">
        <legend class="slds-form-element__legend slds-form-element__label">Operation</legend>
        <div class="slds-form-element__control">
    <span class="slds-radio">
      <input type="radio" id="radio-43" value="radio-43" name="default" checked="" />
      <label class="slds-radio__label" for="radio-43">
        <span class="slds-radio_faux"></span>
        <span class="slds-form-element__label">Insert</span>
      </label>
    </span>
            <span class="slds-radio">
      <input type="radio" id="radio-44" value="radio-44" name="default" />
      <label class="slds-radio__label" for="radio-44">
        <span class="slds-radio_faux"></span>
        <span class="slds-form-element__label">Update</span>
      </label>
    </span>
        </div>
    </fieldset>
    <br><br>
    <lightning-card>
        <h3 slot="title">
            <lightning-icon icon-name="utility:search" size="small"></lightning-icon>
            Search Objects below
        </h3>
        <div slot="footer">

        </div>
        <div>

            <div class="slds-form-element">


                <div class="slds-form-element__control">
                    <div class="slds-combobox_container">

                        <div class={txtclassname} data-id="resultBox" aria-expanded="False" aria-haspopup="listbox" role="combobox">
                            <div class="slds-form-element__control slds-input-has-icon slds-input-has-icon slds-input-has-icon_left-right" role="none">

                                <div>
                                    <span class="slds-icon_container slds-icon-utility-search slds-input__icon iconheight">
                                        <lightning-icon class="slds-icon slds-icon slds-icon_small slds-icon-text-default" icon-name={iconName} size="x-small" alternative-text="icon" ></lightning-icon>
                                    </span>
                                </div>
                                <lightning-input required={required} read-only={inputReadOnly} data-id="userinput" label={Label} name="searchText" onchange={searchField} value={selectRecordName} class="leftspace"></lightning-input>

                                <div if:true={iconFlag}>
                                    <span class="slds-icon_container slds-icon-utility-search slds-input__icon slds-input__icon_right iconheight">
                                        <lightning-icon class="slds-icon slds-icon slds-icon_small slds-icon-text-default" icon-name="utility:search" size="x-small" alternative-text="icon" ></lightning-icon>
                                    </span>
                                </div>
                                <div if:true={clearIconFlag}>
                                    <button class="slds-input__icon slds-input__icon_right slds-button slds-button_icon iconheight" onclick={resetData}>
                                        <lightning-icon class="slds-icon slds-icon slds-icon_small slds-icon-text-default" icon-name="utility:clear" size="x-small" alternative-text="icon" ></lightning-icon>
                                        <span class="slds-assistive-text">Clear</span></button>
                                </div>
                            </div>

                            <!-- Second part display result -->
                            <div id="listbox-id-1" class="slds-dropdown slds-dropdown_length-with-icon-7 slds-dropdown_fluid" role="listbox">
                                <ul class="slds-listbox slds-listbox_vertical" role="presentation">
                                    <template for:each={searchRecords} for:item="serecord">
                                        <li role="presentation" class="slds-listbox__item" key={serecord.recId}>

                                            <div data-id={serecord.recId} data-name={serecord.recName} onclick={setSelectedRecord} class="slds-media slds-listbox__option slds-listbox__option_entity slds-listbox__option_has-meta" role="option">
                                                <span class="slds-media__figure">
                                                    <span class="slds-icon_container slds-icon-standard-account">
                                                        <lightning-icon icon-name={iconName} class="slds-icon slds-icon slds-icon_small slds-icon-text-default" size="x-small"></lightning-icon>
                                                    </span>
                                                </span>
                                                <span class="slds-media__body">
                                                    <span class="slds-listbox__option-text slds-listbox__option-text_entity">{serecord.recName}</span>
                                                    <span class="slds-listbox__option-meta slds-listbox__option-meta_entity">{objectName} • {serecord.recName}</span>
                                                </span>
                                            </div>
                                        </li>
                                    </template>
                                </ul>
                            </div>
                            <div if:true={messageFlag}>
                                No result found.
                            </div>
                            <div if:true={LoadingText}>
                                Loading...
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </lightning-card>
    <br> <br>
    <a class="slds-button slds-button_brand" href="javascript:void(0);">Next</a>
</template>

JS Code:
import { LightningElement,wire,api,track } from 'lwc';
import getResults from '@salesforce/apex/LookupController.getResults';


export default class LwcCustomLookup extends LightningElement {
    @api objectName = 'EntityDefinition';
    @api fieldName = 'QualifiedApiName';
    @api selectRecordId = '';
    @api selectRecordName;
    @api Label;
    @api searchRecords = [];
    @api required = false;
   //   @api iconName = 'standard:event'
    @api LoadingText = false;
    @track txtclassname = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click';
    @track messageFlag = false;
    @track iconFlag =  true;
    @track clearIconFlag = false;
    @track inputReadOnly = false;


    searchField(event) {
        var currentText = event.target.value;
        this.LoadingText = true;

        getResults({ ObjectName: this.objectName, fieldName: this.fieldName, value: currentText  })
            .then(result => {
                this.searchRecords= result;
                this.LoadingText = false;

                this.txtclassname =  result.length > 0 ? 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-is-open' : 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click';
                if(currentText.length > 0 && result.length == 0) {
                    this.messageFlag = true;
                }
                else {
                    this.messageFlag = false;
                }

                if(this.selectRecordId != null && this.selectRecordId.length > 0) {
                    this.iconFlag = false;
                    this.clearIconFlag = true;
                }
                else {
                    this.iconFlag = true;
                    this.clearIconFlag = false;
                }
            })
            .catch(error => {
                console.log('-------error-------------'+error);
                console.log(error);
            });

    }

    setSelectedRecord(event) {
        var currentRecId = event.currentTarget.dataset.id;
        var selectName = event.currentTarget.dataset.name;
        this.txtclassname =  'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click';
        this.iconFlag = false;
        this.clearIconFlag = true;
        this.selectRecordName = event.currentTarget.dataset.name;
        this.selectRecordId = currentRecId;
        this.inputReadOnly = true;
        const selectedEvent = new CustomEvent('selected', { detail: {selectName, currentRecId}, });
        // Dispatches the event.
        this.dispatchEvent(selectedEvent);
    }

    resetData(event) {
        this.selectRecordName = "";
        this.selectRecordId = "";
        this.inputReadOnly = false;
        this.iconFlag = true;
        this.clearIconFlag = false;

    }

}

Is there any way I can enable the components based on other component selections. Please suggest
I have a requirement where I need to display list of salesforce objects as a picklist when a radio button is clicked.
Being new to LWC development, I could not figure out what is the right approach to do so. I have come across this code (https://developer.salesforce.com/docs/component-library/tools/playground/QWa-zfwxW/60/edit) from Salesforce articles where we can display radio buttons but as per my scenario, i need to display list of all salesforce objects as picklist when a radio button option is selected.
Can anyone please suggest the right approach to do so.
I have a requirement that when an account record is opened, a pop up should be displayed with few fields of account like phone, name, type with ok button. When ok button is closed, the pop up should be closed and record detail page should be displayed.

Is there any way to do it. I went through lot of answers but I found custom applications displaying pop up rather than on standard detail page. Being new to lightning development, I could not able to figure it out on how to do so.

Can anyone please help me with the requirement.

Thank you in advance
SK
I have a VF page (standard controller) with an iframe URL and I want the page to be downloaded as pdf or a screenshot on button click.

The issue is that, when i render the page as pdf or when i update my code to capture the screenshot, all i'm seeing is the plain/blank screen instead of page content.

So, as a workaround i am using print option so that i can save the record as pdf.

Below is my VF Page:
 
<apex:page standardController="Account" showheader="false" sidebar="false">
       <apex:form >
            <apex:commandButton value="Print" onclick="window.print();"/>
        </apex:form>
  <apex:iframe src="https://app.powerbi.com/view?r=<custom-url>'" height="540" width="100%" frameborder="0">
  </apex:iframe>
</apex:page>

 Can anyone please suggest the changes to the above code so that I can download the vf page as pdf or screenshot instead of printing and saving it as pdf
I have an apex class which updates the files count on custom object called Declined_Policy__c.

Below is my apex class:
 
public with sharing class Policy_FileCountClass {

    public static void updateAttachmentCountOnDps(List<ContentDocumentLink> DocuLinks) {
        Set<Id> policyids = new Set<Id>();
        for (ContentDocumentLink cdl : DocuLinks) {
            policyids.add(cdl.LinkedEntityId);
        }

        List<Declined_Policy__c> dpsToUpdate = [
            SELECT Id, Attachments__c,
                (SELECT Id FROM ContentDocumentLinks) 
            FROM Declined_Policy__c WHERE Id IN :policyids
        ];
        for (Declined_Policy__c dp : dpsToUpdate) {
            dp.Attachments__c = dp.ContentDocumentLinks.size();
        }
        update dpsToUpdate;
    }

}

Now, as per the above logic, i can able to the count in attachments__c field if there is any file attached to the record or if it is deleted. I could able to see the count in these scenarios. But the issue is that, if there is no file attached to the record when the record is inserted, the attachments__c field will be blank instead of displaying 0

Is there any way that i can update the above logic to get the attachments__c to display 0 by default if there is no file attached to it. Please suggest.
I have a requirement, where account name and account number if do not match with any other records, a custom field called alert_text__c will be updated with some text.

Below is the code snippet:
 
List<Account_Codes__c> records = [SELECT ID, Account_Name__c, Account_Number__c from Account_Codes__c where Account_Name__c != Null AND Account_Number__c != Null]; 

final String accName = newPPAs[0].Account_Name__c;
final String accNum = newPPAs[0].Account_Number__c;
for (Account_Codes__c record : records)
{
    if (record.Account_Name__c != accName && record.Account_Number__c != accNum)
    {
        record.Alert_Text__c = 'Account Number and Account Names are different';
    }
}

Now, the above logic is not working as expected and even when i provide different Account Name and Account Numbers, I am not able to populate the text in Alert_text__c field.

Can anyone please suggest changes in the above code so that i can get this done.

Thanks!
I have a VF page (standard controller) with an iframe URL and I want the page to be downloaded as pdf or a screenshot on button click.

The issue is that, when i render the page as pdf or when i update my code to capture the screenshot, all i'm seeing is the plain/blank screen instead of page content.

So, as a workaround i am using print option so that i can save the record as pdf.

Below is my VF Page:
 
<apex:page standardController="Account" showheader="false" sidebar="false">
       <apex:form >
            <apex:commandButton value="Print" onclick="window.print();"/>
        </apex:form>
  <apex:iframe src="https://app.powerbi.com/view?r=<custom-url>'" height="540" width="100%" frameborder="0">
  </apex:iframe>
</apex:page>

 Can anyone please suggest the changes to the above code so that I can download the vf page as pdf or screenshot instead of printing and saving it as pdf
I have a lightning component which is used to merge the custom lead object which is a duplicate. Here, I have a requirement that if the two selected leads are marked as true for Integrated_Lead__c field, then when clicked on merge, an error should be displayed on the page that "Leads cannot be merged".

Below is my Apex Class method:
 
@auraEnabled
public Static List<cContact> contactsearch(String userinp, String userinput) {
    system.debug(userinput + '=======' + userinp);
    errormsg = false;
    errormsg2 = false;
    contactList = new List<cContact>();
    String query;
    String leadName;
    if (!String.isEmpty(userinp)) {
        leadName = userinp + '%' + userinput + '%';
        system.debug('if====' + leadName);
    } else {
        leadName = '%' + userinput + '%';
        system.debug('else====' + leadName);
    }
    system.debug('leadName===>' + leadName);
    
        for (Lead_Custom__c c : [select Name, First_Name__c, Last_Name__c, Integrated_Lead__c, Id, Cell_Phone__c, Mailing_Street__c, Mailing_City__c, Mailing_State_Province__c from Lead_Custom__c where Name like :leadName]) {
            contactList.add(new cContact(c));
        }
    
    return contactList;
}
@auraEnabled
public Static List<cContact> getresults() {
    return contactList;
}

Lightning Component:
 
<aura:component controller="SearchDuplicateLeads_Lightning" implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
  
    <aura:handler name="init" value="{!this}" action="{!c.SearchDuplicateLeads}"/>
    <aura:attribute name="userinput" type="String" default=""/>
    <aura:attribute name="userinp" type="String" default=""/>
    <aura:attribute name="render" type="Boolean" default="false"/>
    <aura:attribute name="Spinner" type="boolean" default="false"/>
    
    <aura:attribute name="contactList" type="String[]" />
   
                                <aura:iteration items="{!v.contactList}" var="contacts">
                                    <tr class="slds-hint-parent">
                                        <td role="gridcell" class="mycol">
                                            <lightning:input type="checkbox" aura:id="selected" label=" " value="{!contacts.selected}" onchange="{!c.singleChecked}"/>
                                        </td>
                                        <td role="gridcell">
                                            <ui:outputText value="{!contacts.con.Name}" />
                                        </td>
                                        
                                    </tr>
                                </aura:iteration>
                                </tbody>
                            </table>
                        </div>
                        <lightning:button variant="brand" onclick="{!c.processrecSelected}" label="Next" class="cus-button"/>
                        <lightning:button variant="brand" onclick="{!c.Cancel}" label="Cancel" class="cus-button"/>
                    </aura:renderIf>
                </div>
            </div>
        </div>
    </div>
</aura:component>

Js:
 
processrecSelected: function(component, event, helper) {
    var action = component.get('c.processSelected');
    var strData = JSON.stringify(component.get('v.contactList'));
    console.log('strData===>'+strData);
    action.setParams({ 'contactstr' : strData});
    action.setCallback(this,function(response){
        if (response.getState() === "SUCCESS") {
            var res = response.getReturnValue();
            console.log('res===>'+res.length);
            if(res.length==2){
                redirecttoMerge(res[0].Id,res[1].Id);
            }else if(res.length>2){
                toastEvt('Please select at most two records to proceed');
            }else if(res.length==1){
                toastEvt('Please select at most two records to proceed');
            }else{
                toastEvt('Please select a record to proceed.');
            }
        }
    })
    $A.enqueueAction(action);
    function toastEvt(msg){
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "Error!",
            "type":"Error",
            "message": msg
        });
        toastEvent.fire();
    }
},

Now, from the above contactList, the merging will be done when two Custom Leads are selected. As per my requirement, if the selected two leads are having Integrated_Lead__c = True, then an error message should be displayed on the screen that "Leads cannot be merged" on click on next button.
​​​​​​​
Can anyone please suggest the changes so that I can get the error message displayed on screen
I have a requirement where the child record (Account_Transfer_Policy__c) should be updated with new Parent record (Account_Transfer__c) if the district_from__c of current parent do not match with district_Acct_Code__c of child record.

This new parent update will be done when District_from__c of any Account Transfer record and District_Acct_Code__c of child matches

Now, below is my trigger
trigger ATwithATP on Account_Transfer_Policy__c (after insert) {
    Map<Id,Account_Transfer__c> mapIDWithAccount = new Map<Id,Account_Transfer__c>();
    Map<string,Account_Transfer__c> mapATwithATP = new Map<string,Account_Transfer__c>();

    for (Account_Transfer__c acc : [select id,District_From__c from Account_Transfer__c where District_From__c != Null and createddate = TODAY ORDER BY createddate DESC ]){
       
        mapATwithATP.put(acc.District_From__c,acc);
    }
    
    list<Account_Transfer_Policy__c> ATP = new list<Account_Transfer_Policy__c>();
    for(Account_Transfer_Policy__c c : trigger.new){
        
        if(c.Account_Transfer__c !=null && c.Policy__r.District_Acct_Code__c != c.Account_Transfer__r.District_From__c){
            if(mapATwithATP.containsKey(c.Policy__r.District_Acct_Code__c)){
                c.Account_Transfer__c = mapATwithATP.get(c.Policy__r.District_Acct_Code__c).Id;
            }
        }
        ATP.add(c);
       
    }
    update ATP;
}

I'm not getting any error but the child is not updating with new parent record. Can anyone please suggest any changes in my code if I missed anything.
I have an custom object called Account_Velocity__c and it has a child object called Partner_Policies__c
Now, there is an automation in place which inserts Account_Velocity__c and its related child Partner_Policies__c. 

I have a requirement where, if the Partner_district__c field of Partner_Policies__c doesn't match with its parent's Account_District__c field, a new parent record should be created and this related Partner_Polcies__c record should go as a child record for that parent.

As of now, for a single Account_Velocity__c record, there are multiple Partner_Policies__c records which are inserting as a child irrespecive of Partner_district__c and Account_District__c field values. 

simple terms for understanding: 
Parent - Account_Velocity__c, field - Account_District__c
Child - Partner_Policies__c, field - Partner_District__c

I'm having very hard time finding appropriate logic for this requirement. Could anyone please help me out with this.  
Below is my apex method where I'm updating Account_Transfer__c Records
private static void linkPoliciesAndHandleApprovalFlds(
    List<string> selectedPoliciesSet,
    Account_Transfer__c accTrans,
    Office__c toOffice,
    Office__c fromOffice
) {
    Map<Id, Account_Transfer__c> AcctransMap = new Map<Id, Account_Transfer__c>(); 
    String districtAccountCode = '';
    List<Policy__c> selectedPolicies = new List<Policy__c>(
        [
            SELECT
                Id,
                District_Acct_code__c,
                Account_Transfer__c,
                Plan_Code__c
            FROM Policy__c
            WHERE ID IN :selectedPoliciesSet
        ]
    );
    List<Account_Transfer_Policy__c> accTransferPolicy = new List<Account_Transfer_Policy__c>();
    for (Policy__c pol : selectedPolicies) {
        Account_Transfer_Policy__c atp = new Account_Transfer_Policy__c();
        atp.Account_Transfer__c = accTrans.Id;
        atp.Policy__c = pol.Id;
        accTransferPolicy.add(atp);
      
        
    }
    

    

    accTrans.District_To__c = districtAccountCode;
    AcctransMap.put(accTrans.id, accTrans);
    
    update AcctransMap.values();
    
    insert accTransferPolicy;
    
    Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
    req.setObjectId(accTrans.Id);
    req.setSubmitterId(UserInfo.getUserId());
    Approval.process(req);
    
}
Now this code isn't throwing me any errors but in the record page, I'm getting the error as
 
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
I am using Map here to get the ids of Account Transfer records and using them to update by calling map.values(). I'm wondering why it is mentioning that Ids are not specified in the update call.

Can anyone please suggest if there is anything missing
I have a requirement where I need to display list of salesforce objects as a picklist when a radio button is clicked.
Being new to LWC development, I could not figure out what is the right approach to do so. I have come across this code (https://developer.salesforce.com/docs/component-library/tools/playground/QWa-zfwxW/60/edit) from Salesforce articles where we can display radio buttons but as per my scenario, i need to display list of all salesforce objects as picklist when a radio button option is selected.
Can anyone please suggest the right approach to do so.
I have a requirement that when an account record is opened, a pop up should be displayed with few fields of account like phone, name, type with ok button. When ok button is closed, the pop up should be closed and record detail page should be displayed.

Is there any way to do it. I went through lot of answers but I found custom applications displaying pop up rather than on standard detail page. Being new to lightning development, I could not able to figure it out on how to do so.

Can anyone please help me with the requirement.

Thank you in advance
SK