• Sangeetha T
  • NEWBIE
  • 19 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 23
    Replies
URGENT !!!! Need Help 
I have a custom search lookup modal window which will search the products and display results 
PFB for the code 
<template>
    <template if:true={isShowModal}>
        <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open slds-modal_medium">
            <div class="slds-modal__container">
                <!-- modal header start -->
                <header class="slds-modal__header">
                    <button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" title="Close" onclick={hideModalBox}>
                        <lightning-icon icon-name="utility:close" alternative-text="close" variant="inverse" size="small" ></lightning-icon>
                        <span class="slds-assistive-text">Close</span>
                    </button>
                    <h2 id="modal-heading-01" style="text-align: left;" class="slds-text-heading_medium">Product Custom Search</h2>
                </header>
                <!-- modal body start -->
                <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                    <ul class="slds-list_horizontal">
                        <li class="slds-item_detail" style="margin-left: 10px;">
                            <div style="font-weight: bold;">
                                <lightning-input type="text" label="Product Name" name="name" variant="standard" placeholder="Enter Product Name" onchange={handleChange} disabled={isnameDisable}></lightning-input>
                            </div>
                        </li>
                        <li class="slds-item_detail" style="margin-left: 10px;">
                            <div style="font-weight: bold;">
                                <lightning-input type="text" label="Product ID" name="MOLProductID" variant="standard" placeholder="Enter Product ID" onchange={handleChange} disabled={isMOLProductIDDisabled}></lightning-input>
                            </div>
                        </li>
                        <li class="slds-item_detail" style="margin-left: 10px;">
                            <div style="font-weight: bold;">
                                <lightning-input type="text" label="Old Material Number" name="MOLOldMaterialNumber" variant="standard" placeholder="Enter Old Material Number" onchange={handleChange} disabled={isMOLOldMaterialNumberDisable}></lightning-input>
                            </div>
                        </li>

                        <li class="slds-item_detail" style="margin-top: 23px;">
                            <div>
                                <lightning-button variant="brand" label="Search" title="Search" icon-name="utility:search" class="slds-m-left_x-small" onclick={handleSearch}></lightning-button>
                            </div>
                        </li>
                    </ul>
                    <div if:true={isDataTrue} style="margin-top: 20px;">
                        <div class="slds-clearfix">
                            <p class="slds-float_left"><strong>No of Records: {recordLength}</strong></p>
                            <lightning-button variant="brand" label="Save and Select" title="Save and Select" class="slds-button slds-float_right databuttons" onclick={handleSave}></lightning-button>
                            <lightning-button variant="destructive" label="Cancel" title="Cancel" class="slds-button slds-float_right databuttons" onclick={hideModalBox}></lightning-button>
                        </div>
                        <div class="fixTableHead">
                            <table>
                                <thead>
                                <tr>
                                    <th>Select</th>
                                    <th>Product Name</th>
                                    <th>Product ID</th>
                                    <th>Old Material Number</th>
                                </tr>
                                </thead>
                                <tbody>
                                    <template for:each={productList} for:item="product">
                                        <tr key={product.Id}>
                                            <td>
                                                <input type="radio" class="selectId" name="productRecord" value={product.Id} />
                                            </td>
                                            <td>{product.Name}</td>
                                            <td>{product.MOL_ProductID__c}</td>
                                            <td>{product.MOL_OldMaterialNumber__c}</td>
                                            
                                        </tr>
                                    </template>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div if:true={isDataFalse}>
                        <p><strong>No Records Found.</strong></p>
                    </div>
                </div>
                <!-- modal footer start-->
                <footer class="slds-modal__footer"></footer> 
            </div>
        </section>
        <div class="slds-backdrop slds-backdrop_open"></div>
    </template>
    <!-- modal end -->
</template>
 
import { LightningElement,track,api} from 'lwc';
import getProductRecords from '@salesforce/apex/PdrProductsearch.getProductRecords';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class PdrProductCustomSearch1 extends LightningElement {
    @api recordId;
    @track isShowModal = false;
    @track recordLength=0;
    @track isDataTrue = false;
    @track isDataFalse = false;
    @track productList = [] // added as a list
    searchType='';
    searchTerm='';

    handleChange = (event) =>{
        this.searchType = event.target.name;
        this.searchTerm = event.target.value;
    }

    get isnameDisable(){
        return ( this.searchType != 'name' && this.searchTerm != ''? true : false );
    }

    get isMOLProductIDDisabled(){
        return ( this.searchType != 'MOLProductID' && this.searchTerm != ''? true : false );
    }

    get isMOLOldMaterialNumberDisable(){
        return ( this.searchType != 'MOLOldMaterialNumber' && this.searchTerm != ''? true : false );
    }

    resetData(){
        this.productList = null;
        this.recordLength = 0;
        this.searchTerm = '';
        this.isDataTrue = false;
        this.isDataFalse = false;  
    }

    @api showModalBox() {  
        this.isShowModal = true;
    }

    hideModalBox() {
        this.resetData(0); 
        this.isShowModal = false;
    }

    getProductNameById = (obj,id) =>{
        let mapObj = new Map();
        for (let i=0; i<Object.keys(obj).length; i++){
            mapObj.set(obj[i].Id,obj[i].Name);
        }
        if (mapObj.has(id)){
            return mapObj.get(id);
        }
    }

    handleSave = (event) =>{
        let recIds = this.template.querySelectorAll('.selectId');
        let prodId = '';
        let prodName = '';
        for (let i=0; i<recIds.length; i++){
            if (recIds[i].checked){
                prodId = recIds[i].value;
                break;
            }
        }
        prodName = this.getProductNameById(this.productList,prodId);
        const customEvt = new CustomEvent(
            "pass",
            {   detail : { id: prodId, name : prodName}
            }
        );
        this.dispatchEvent(customEvt);
        this.hideModalBox(0);
    }

    handleSearch = (event) =>{
        if( this.searchTerm!='' && this.searchType!='' ){
            getProductRecords({searchTerm : this.searchTerm, searchType : this.searchType})
            .then( (response) =>{
                        console.log(response);
                        if(response!=null){
                            this.productList = JSON.parse(JSON.stringify(response));
                            let count = Object.keys(this.productList).length;
                            console.log(count);
                            this.recordLength = count;
                            if (this.recordLength>0) {
                                this.isDataTrue = true;
                                this.isDataFalse = false;
                            }else{
                                this.productList = null;
                                this.isDataFalse = true;
                                this.isDataTrue = false;
                            }
                        }
                        else{
                            this.productList = null;
                            this.isDataFalse = true;
                            this.isDataTrue = false;
                        }
                    }
            ).catch( (error) => {
                        const event = new ShowToastEvent({
                            title: 'Error',
                            variant: 'error',
                            message: error.body.message,
                        });
                        this.dispatchEvent(event);
                        this.productList = null;
                        this.isDataFalse = true;
                        this.isDataTrue = false;
                    }
            );
        }else{
            this.productList = null;
            this.isDataFalse = true;
            this.isDataTrue = false;
        }
    }
}
 
public without sharing class PdrProductsearch {
    
    @AuraEnabled(cacheable=true)
    public static List<Product2> getProductRecords(String searchTerm, String searchType){
        try {
            List<Product2> proRec = new List<Product2>();
            String searchTxt = '%'+searchTerm+'%';
            if(searchType=='name' && searchTerm!='')
            {
                proRec = [ Select Id,Name,MOL_ProductID__c,MOL_OldMaterialNumber__c From Product2 where Name like : searchTxt With SECURITY_ENFORCED];
            }
            else if(searchType=='MOLProductID' && searchTerm!='')
            {
				proRec = [ Select Id,Name,MOL_ProductID__c,MOL_OldMaterialNumber__c From Product2 where MOL_ProductID__c like : searchTxt With SECURITY_ENFORCED];
            }
            else if(searchType=='MOLOldMaterialNumber' && searchTerm!='')
            {
                proRec = [ Select Id,Name,MOL_ProductID__c,MOL_OldMaterialNumber__c From Product2 where MOL_OldMaterialNumber__c like : searchTxt With SECURITY_ENFORCED];   
            }
            else
            {
                proRec = null;
            }

            //Checking data..
            System.debug('Queried Data-->'+proRec);

            //Checking whether Record List is not null and has atleast some Records
            if( proRec!=null && proRec.size()>0 ){
                return proRec;
            }else{
                return null;
            }

        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

}

Now I'm calling this child LWC in my parent LWC which  has the Table row 
Now when I click the modal popup its opens and allows me to search and gets inserted on the first row of adding the products 
But for the second row or third row, it's not working and the selected value from the search result does not get included 

PFB for calling the child component 
<td>
                                <lightning-input type="search" data-index={indx} name="selectedProductName" value={item.selectedProductName}
                                onchange={handleAllData} onclick={handleChildModal} label="Material" variant="standard" required></lightning-input>
                                <c-pdr-product-custom-search-1 data-index={indx} onpass={handleSelectedRec} ></c-pdr-product-custom-search-1>

I'm not sure what I'm missing - Any help will be appreciated
Hi All 
I have created a Lightning component buttton to download attachments related to email message 
Now I'm able to fetch all attachment IDS as per debug log 
But only one file is downloading 
In Email Messages having more that one attachment only the first attachment is downloading. How to fix this 
Please help me with the code correction 

I have tried using various scenarios but could not achieve the mutiple attachments downloading
<aura:component controller ='DownloadAllFilesClass' implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" 
                access="global" >
       
	<lightning:button label="Download All Files" onclick ="{! c.downloadfiles }" variant ="brand" iconName = "utility:download"/>
</aura:component>
 
({
    downloadfiles : function(component, event, helper) {
        var action = component.get("c.generateDownloadFilesLines");
        console.log("This component"+component.get("v.recordId"));
        action.setParams({EmailMessageId : component.get("v.recordId")});
        action.setCallback(this,function(response){
            var state = response.getState();
            if (state === "SUCCESS"){
                if (response.getReturnValue() != 'No document available')
                {

                    var urlEvent = $A.get("e.force:navigateToURL") ;
                    urlEvent.setParams({"url":response.getReturnValue()});
                    urlEvent.fire();
                }
                else
                {
                    var toastEvent = $A.get("e.force:showToast");
                    toastEvent.setParams({
                        title : 'Error',
                        Message : 'No document available',
                        duration : '50000',
                        key : 'info_alt',
                        type : 'error',
                        mode : 'pester',
                    });
                    toastEvent.fire();
                }
                    
                
            }
            else if (state === "INCOMPLETE")
            {
                
            }
                else if (state === "ERROR"){
                    var errors = response.getError();
                    if(errors){
                        if (errors[0] && errors[0].message)
                        {
                            console.log("Error Message:"+errors[0].message);
                        }
                    }
                        else
                        {
                            console.log("Unknown Error");
                        }
                    }
            });
            
            $A.enqueueAction(action);
        }
})
 
public without sharing class DownloadAllFilesClass {
    @AuraEnabled
    public static String[] generateDownloadFilesLines(Id EmailMessageId){
    String[] URL1 =new String[]{};
    String URLInstance = String.valueOf(System.URL.getSalesforceBaseUrl().gethost());
    String URLAppend = URLInstance.SubStringBefore('.my');    
    System.debug('Appended String::'+URLAppend);
    List<ID> idslist = new List<ID>();
    List<Attachment> cdllist = [Select ID,ParentID from Attachment where ParentID =:EmailMessageId];
    System.debug('EmailMessageID:: '+EmailMessageId);
    System.debug('List of Ids related to EmailMessageID:: '+cdllist);  
    System.debug('URLInstance:: '+URLInstance); 
        if(cdllist != null && cdllist.size() > 0)
    {
             for(Attachment cdl : cdllist)
    {
             idslist.add(cdl.ID);
    }
    }
    if (idslist != null && idslist.size() > 0)
    {
        for(ID i : idslist)
        {
          String URL2 = 'https://'+URLAppend+'--c.documentforce.com/servlet/servlet.FileDownload?file='+i+'&operationContext=S1';
          system.debug('URL2::'+URL2);
          URL1.add(URL2);
        }
        system.debug('AttachmentIds:: '+idslist);
        system.debug('DownloadURL:: '+URL1); 
        
    }
        return URL1;
}
}

 
Need help in writing a component that downloads all the attachments of the email message 

Altenative of javascript to work in lightning 
Hi All 
I'm currently removing all the hard coded IDs to Custom Label
I have a formula in Process builder 
------------------------
$User.Id  <> 18 digit ID
------------------------
I captured the 18 digit ID in custom label and tried using the same in the formula field
------------------------
$User.Id  <> $Label.AAA 
------------------------
But Not working. Any help please

My goal is to replace the hardcoded ID to a custom Label 
Hi All

While inserting test records through DATABASE.INSERT in test class. I queried the inserted TEST records through System.Debug, To my surprise I could see that the field value has got changed. 
Henceforth it is not passing to the another criteria to code coverage 

for eg I inserted 
F1 = "aqsh"
F2 = "assigned"

while querying the records look like this
F1 ="aqsh"
F2 = "Open"

PLEASE HELP
Exporting more 50K record information - Out of Box functionality
Hi 

I have 56K records name in hand, I need to export their repective Record ID and other fields. If I form the SOQL query like the following I will result in QUERY size limit exceeding 20K characters 
 
SELECT ID,Name from Object__c "WHERE Name IN ('dd',dd',..................) 

Optimizing the IN with batch by batch records is tidious 

Any better out of box functionality to extract 56K records field when you have their name

Thanks in advance 
SANGEETHA T
Hi All

Please help me in defining the CRON expression for running a scheduler class for every 30th min of an hour 
For example first run should be 9 30 next should be 10 30 next should be 11 30 

 
Hi All 

PFB Code snippet 

The goal of the batch job is basically finding the relationship (AOR) record from past year and apply the sales focus value to the new year AOR record if the sales focus value for past AOR is = 'Assigned" and the new year AOR record sales focus is "OPEN"

I'm getting 37% code coverage only, Please help where I have missed thanks 

 
global class BatchSalesfocusAORRollOver implements Database.Batchable<sObject> {

        public integer getCurrentFY(){ 
        
        Integer currentFY;      
        Organization orgInfo = [SELECT FiscalYearStartMonth, UsesStartDateAsFiscalYearName
                                FROM Organization WHERE id=:Userinfo.getOrganizationId()];
        Date today = system.today();
        if (today.month() >= orgInfo.FiscalYearStartMonth) {
            if (orgInfo.UsesStartDateAsFiscalYearName) 
                currentFY = today.year();             
            else currentFY = today.year() + 1; 
        }else {
            if (orgInfo.UsesStartDateAsFiscalYearName) 
                currentFY = today.year() - 1;
            else currentFY = today.year();            
        }
        System.debug('&&&&&&&&'+currentFY);                
        return currentFY;
    }      
             
    Integer FiscalYear = getCurrentFY();
    Integer FYPlusOne = FiscalYear - 1;
    // Variable defined to check if the previous fiscal year
    String PrevYearCheck = FYPlusOne +'%';

    global database.querylocator start(Database.BatchableContext BC){   
        Integer lmt = Limits.getLimitQueryRows();
        String National = System.Label.CL_National;
        String query = 'Select Org_SFID__r.Fiscal_Year_SFID__c,fAccount_Brand_ID__c,Id,CFY_Dealer_Account_SFID__r.Brand_Group_Name__c,Integration_Key__c,';     
        query += 'Org_SFID__c,Org_SFID__r.Fiscal_Year_SFID__r.Year__c,Sales_Focus_Descr__c';
        query += ' FROM Account_Org_Relationship__c';
        query += ' WHERE Sales_Focus_Descr__c =\'Assigned\' and is_Active__c = true and fFiscal_Year__c = false and Integration_Key__c LIKE PrevYearCheck and fAccount_Brand_Name__c =: National';
        
        System.debug('query ::::'+ query);
        return Database.getQueryLocator(query);        
    }
        
    global void execute(Database.BatchableContext BC, List<Account_Org_Relationship__c> AORCurrentFYList){
        String National = System.Label.CL_National;
        map<String,Account_Org_Relationship__c> FutureFYAORMap = new  map<String,Account_Org_Relationship__c>();
        System.debug('FiscalYear ::::'+ FiscalYear + 'FYPlusOne ::::'+ FYPlusOne );

        List<String> KeyList = new List<String>();
        for (Account_Org_Relationship__c scopeAOR: AORCurrentFYList) {
            Integer Key_length = String.valueOf(scopeAOR.Integration_Key__c).length();
            String Partial_Key = String.valueOf(scopeAOR.Integration_Key__c).substring(5, Key_length);
            String Complete_Key =  FYPlusOne + '|' + Partial_Key;
            KeyList.add(Complete_Key);
        }
        system.debug('KeyList    '+ KeyList);
  /*      List<Account_Org_Relationship__c> FutureFYAORList = [Select id,
                                                                    name,
                                                                    Sales_Focus_Descr__c,
                                                                    Integration_Key__c
                                                            From Account_Org_Relationship__c
                                                            Where Org_SFID__r.Fiscal_Year_SFID__r.name =: String.valueOf(FYPlusOne)];
 */
 
        for (Account_Org_Relationship__c AOR: [Select id,name,Sales_Focus_Descr__c,Integration_Key__c From Account_Org_Relationship__c
                                               Where is_Active__c = true and Sales_Focus_Descr__c = 'Open' AND fAccount_Brand_Name__c =: National and Org_SFID__r.Fiscal_Year_SFID__r.name =: String.valueOf(FYPlusOne) and Integration_Key__c in: KeyList])
        {
            If (AOR.Integration_Key__c !=null) {
                Integer Key_length = String.valueOf(AOR.Integration_Key__c).length();
                String Partial_Key = String.valueOf(AOR.Integration_Key__c).substring(5, Key_length);
                FutureFYAORMap.put(Partial_Key, AOR);
            }
        }
        system.debug('FutureFYAORMap :::::' + FutureFYAORMap);
        
        List<Account_Org_Relationship__c> AORUpdList = new List<Account_Org_Relationship__c>();
        Integer index = 0;
        for(Account_Org_Relationship__c AORold: AORCurrentFYList) {
            If (AORold.Integration_Key__c !=null) {
                Integer Key_length = String.valueOf(AORold.Integration_Key__c).length();
                String Partial_Key = String.valueOf(AORold.Integration_Key__c).substring(5, Key_length);
        
                if(FutureFYAORMap.containsKey(Partial_Key)) {
                    Account_Org_Relationship__c AORitem = new Account_Org_Relationship__c();
                    AORitem = FutureFYAORMap.get(Partial_Key);
                    AORitem.Sales_Focus_Descr__c = 'Assigned';
                    AORUpdList.add(AORitem);
                    index = index + 1;
                }
            }
        }
        system.debug('index @@@@@@' + index);
        database.update(AORUpdList);
    }

    global void finish(Database.BatchableContext BC) {

    }
}
 
@isTest
public class BatchSalesfocusAORRollOverTest{
 
    static testMethod void testApexFiveAOR()
     {
   
        //Creating Period Data Team record
      Integer FiscalYear;      
        Organization orgInfo = [SELECT FiscalYearStartMonth, UsesStartDateAsFiscalYearName
                                FROM Organization WHERE id=:Userinfo.getOrganizationId()
                               ];
        Date today = system.today();               
        if (today.month() >= orgInfo.FiscalYearStartMonth) {
            if (orgInfo.UsesStartDateAsFiscalYearName) {
                FiscalYear = today.year();
            }else{
                FiscalYear = today.year() + 1;
            }
        }else{
            if (orgInfo.UsesStartDateAsFiscalYearName) {
                FiscalYear = today.year() - 1;
            }else{
                FiscalYear = today.year();
            }
        }
  
      Integer FiscalYearplusone = FiscalYear - 1;
      
         
        Periods__c p = new Periods__c();
        p.CFY_Offset_ID__c = -1;
        p.Name=string.valueOf(FiscalYear-1);
        p.Year__c = FiscalYearplusone;   
        p.Period_Level_Descr__c ='Year'; 
        p.Period_ID__c ='20171';      
        insert p; 
      
        Periods__c p1 = new Periods__c();
        p1.CFY_Offset_ID__c = 0;
        p1.Name=string.valueOf(FiscalYear);
        p1.Year__c = FiscalYear;   
        p1.Period_Level_Descr__c ='Year'; 
        p1.Period_ID__c ='20181';    
        insert p1;    
        
        RecordType dealerRt = [SELECT Id FROM RecordType WHERE sObjectType='Account' and DeveloperName='Dealer'];
        RecordType growerRt = [SELECT Id FROM RecordType WHERE sObjectType='Account' and DeveloperName='Grower'];    
         
        List<Monsanto_Organizations__c> MORList = new List<Monsanto_Organizations__c>();
        //Creating Monsanto Organisation Data Team record
       
        Monsanto_Organizations__c MO3 = new Monsanto_Organizations__c();
        MO3.Name='IL Central' ;       
        MO3.Market_Type_Descr__c ='Seed and Traits';      
        MO3.Brand_Family_Name__c = 'National' ;       
        MO3.Org_Key_Cd__c ='2015|ABM|C101' ;       
        MO3.Org_Cd__c ='C101' ;       
        MO3.Org_Description__c ='IL Central';       
        MO3.Fiscal_Year_SFID__c = p.Id;
        MORList.add(MO3); 
        
        Monsanto_Organizations__c MO4 = new Monsanto_Organizations__c();
        MO4.Name='Lowell Butler' ;       
        MO4.Market_Type_Descr__c ='Seed and Traits';      
        MO4.Brand_Family_Name__c = 'National' ;       
        MO4.Org_Key_Cd__c ='2015|DSM|C1D' ;       
        MO4.Org_Cd__c ='C1D' ;       
        MO4.Org_Description__c ='Lowell Butler';       
        MO4.Fiscal_Year_SFID__c = p.Id;
        MO4.Manager_Org_SFID__c = MO3.id;
        MORList.add(MO4);  
         
        Monsanto_Organizations__c MO2 = new Monsanto_Organizations__c();
        MO2.Name='2015 - AG LAND FS INC ELV GREEN VLY' ;       
        MO2.Market_Type_Descr__c ='Seed and Traits';      
        MO2.Brand_Family_Name__c = 'National' ;       
        MO2.Org_Key_Cd__c ='2015|DealerNational50540711' ;       
        MO2.Org_Cd__c ='50540711' ;       
        MO2.Org_Description__c ='AG LAND FS INC ELV GREEN VLY';       
        MO2.Fiscal_Year_SFID__c = p1.Id;    
        MO2.Manager_Org_SFID__c = MO4.id;
        MORList.add(MO2);     
        
        database.insert(MORList, false); 
        
        //Creating Business Plan record
        Business_Plan__c bp = new Business_Plan__c();      
        bp.Name = '2015 Crop Plan' ;     
        bp.Integration_Key__c = 'Acc123asdhgasd' ;      
        bp.Market_Type_Descr__c ='All' ;      
        bp.BPY_SFID__c = p1.id;            
        insert bp ;  
        
        //Creating Sales Summary By Year record
        Sales_Summary_Level_By_Year__c ss0 = new Sales_Summary_Level_By_Year__c(is_Active__c = true,
        Category_Type_Descr__c = 'Brand',
        name='ss',
        Account_Type_Descr__c = 'Location',
        Product_Type_Descr__c = 'Bulk',
        Fiscal_Year_SFID__c =p1.id,
        Product_Summary_Level_Descr__c ='WEATHERMAX');      
        insert ss0;        

        //Creating District Sales Summary Record
        District_Sales_Summary_By_Year__c d = new District_Sales_Summary_By_Year__c( name = 'dst1',
        is_Active__c = true,
        Team_BP_SFID__c = bp.id, 
        Sales_Summary_Level_SFID__c = ss0.id,
        is_BP_Submitted__c = true,
   //     BP_Submitted_By_User_SFID__c = DSMMem.id ,
        BP_Submitted_Date__c = date.today() - 3 ,
        District_Org_SFID__c = MO2.id,
        BP_Approved_Date__c = date.today() - 4,
        BP_Rejected_Date__c = date.today() - 6);
        insert d;    
          
       // Create an Account    
       Account a2  = new Account();    
       a2.Name = 'TestDealer2';    
       a2.RecordTypeId = dealerRt.Id;
       a2.Brand_Group_Name__c = 'National';
       insert a2;

       // Create an Account    
       Account a0  = new Account();    
       a0.Name = 'TestDealer';    
       a0.RecordTypeId = dealerRt.Id;
       a0.Brand_Group_Name__c = 'National';
       insert a0; 
         
       Account a1  = new Account();    
       a1.Name = 'TestGrower';    
       a1.RecordTypeId = growerRt.Id;  
       a1.Brand_Group_Name__c = 'National';  
       insert a1;
   
       Account a3  = new Account();    
       a3.Name = 'TestGrower2';    
       a3.RecordTypeId = growerRt.Id;    
       a3.Brand_Group_Name__c = 'National';
       insert a3;
       
       
        //Creating Account Sales Summary By Year record
        Account_Sales_Summary_By_Year__c as0 = new Account_Sales_Summary_By_Year__c(Name = 'as',
        Account_SFID__c = a0.id, 
        District_Sales_Summary_SFID__c = d.Id,
        CFY_GNet_Sales_Qty__c = 26);
        insert as0;
        
        Account_Sales_Summary_By_Year__c as1 = new Account_Sales_Summary_By_Year__c(Name = 'as',
        Account_SFID__c = a2.id, 
        District_Sales_Summary_SFID__c = d.Id,
        CFY_GNet_Sales_Qty__c = 68);
        insert as1;    
     
        List<Account_Org_Relationship__c> AORListToInsert = new List<Account_Org_Relationship__c>();
        List<Account_Org_Relationship__c> AORListToUpdate = new List<Account_Org_Relationship__c>();
        
        Account_Org_Relationship__c aor0 = new Account_Org_Relationship__c(
        Name = 'TestAccOrgRelationship', 
        Account_SFID__c = a1.Id, 
        Org_Account_SFID__c = a0.Id,
        Org_SFID__c = MO2.Id, 
        Sales_Focus_Descr__c = 'Open', 
        CFY_Dealer_Account_SFID__c = a0.Id,
        Corn_Acct_Sls_Summ_SFID__c = as0.Id,
        Soy_Acct_Sls_Summ_SFID__c = as1.Id,
        CFY_Grower_Account_SFID__c = a1.Id,
        Integration_Key__c = String.ValueOf(FiscalYear) +'|test1',
        is_Active__c = true);  
        AORListToInsert.add(aor0);
        aor0.Sales_Focus_Descr__c = 'Assigned';
        AORListToUpdate.add(aor0); 

        
        Account_Org_Relationship__c aor1 = new Account_Org_Relationship__c(
        Name = 'TestAccOrgRelationship1', 
        Account_SFID__c = a1.Id, 
        Org_Account_SFID__c = a0.Id,
        Org_SFID__c = MO2.Id, 
        Sales_Focus_Descr__c = 'Open', 
        CFY_Dealer_Account_SFID__c = a0.Id,
        Corn_Acct_Sls_Summ_SFID__c = as0.Id,
        Soy_Acct_Sls_Summ_SFID__c = as1.Id,
        CFY_Grower_Account_SFID__c = a1.Id,
        Integration_Key__c = String.ValueOf(FiscalYear) +'|test2',
        is_Active__c = true);  
        AORListToInsert.add(aor1);
        aor1.Sales_Focus_Descr__c = 'Assigned';
        AORListToUpdate.add(aor1);         

        
        Account_Org_Relationship__c aor2 = new Account_Org_Relationship__c(
        Name = 'TestAccOrgRelationship2', 
        Account_SFID__c = a1.Id, 
        Org_Account_SFID__c = a0.Id,
        Org_SFID__c = MO2.Id, 
        Sales_Focus_Descr__c = 'Open', 
        CFY_Dealer_Account_SFID__c = a0.Id,
        Corn_Acct_Sls_Summ_SFID__c = as0.Id,
        Soy_Acct_Sls_Summ_SFID__c = as1.Id,
        CFY_Grower_Account_SFID__c = a1.Id,
        Integration_Key__c = String.ValueOf(FiscalYear) +'|test3',
        is_Active__c = true);  
        AORListToInsert.add(aor2);
        aor2.Sales_Focus_Descr__c = 'Assigned';
        AORListToUpdate.add(aor2);         

        
        Account_Org_Relationship__c aor3 = new Account_Org_Relationship__c(
        Name = 'TestAccOrgRelationship3', 
        Account_SFID__c = a1.Id, 
        Org_Account_SFID__c = a0.Id,
        Org_SFID__c = MO2.Id, 
        Sales_Focus_Descr__c = 'Open', 
        CFY_Dealer_Account_SFID__c = a0.Id,
        Corn_Acct_Sls_Summ_SFID__c = as0.Id,
        Soy_Acct_Sls_Summ_SFID__c = as1.Id,
        CFY_Grower_Account_SFID__c = a1.Id,
        Integration_Key__c = String.ValueOf(FiscalYear) +'|test4',
        is_Active__c = true);  
        AORListToInsert.add(aor3);
        aor3.Sales_Focus_Descr__c = 'Assigned';
        AORListToUpdate.add(aor3);         

        Account_Org_Relationship__c aor4 = new Account_Org_Relationship__c(
        Name = 'TestAccOrgRelationship', 
        Account_SFID__c = a1.Id, 
        Org_Account_SFID__c = a0.Id,
        Org_SFID__c = MO2.Id, 
        Sales_Focus_Descr__c = 'Open', 
        CFY_Dealer_Account_SFID__c = a0.Id,
        Corn_Acct_Sls_Summ_SFID__c = as0.Id,
        Soy_Acct_Sls_Summ_SFID__c = as1.Id,
        CFY_Grower_Account_SFID__c = a1.Id,
        Integration_Key__c = String.ValueOf(FiscalYear) +'|test5',
        is_Active__c = true);  
        AORListToInsert.add(aor4);
        aor4.Sales_Focus_Descr__c = 'Assigned';
        AORListToUpdate.add(aor4);         

              
       Account_Org_Relationship__c aor10 = new Account_Org_Relationship__c(
       Name = 'TestAccOrgRelationship', 
       Account_SFID__c = a1.Id, 
       Org_Account_SFID__c = a0.Id,
       Org_SFID__c = MO4.Id, 
       CFY_Dealer_Account_SFID__c = a0.Id,
       Corn_Acct_Sls_Summ_SFID__c = as0.Id,
       Soy_Acct_Sls_Summ_SFID__c = as1.Id,
       CFY_Grower_Account_SFID__c = a1.Id,
       Integration_Key__c = String.ValueOf(FiscalYearplusone) +'|test1',
       IsValid__c = false,
       Sales_Focus_Descr__c = 'Open',
       is_Active__c = true);  
       AORListToInsert.add(aor10);
       
       Account_Org_Relationship__c aor11 = new Account_Org_Relationship__c(
       Name = 'TestAccOrgRelationship', 
       Account_SFID__c = a1.Id, 
       Org_Account_SFID__c = a0.Id,
       Org_SFID__c = MO4.Id, 
       CFY_Dealer_Account_SFID__c = a0.Id,
       Corn_Acct_Sls_Summ_SFID__c = as0.Id,
       Soy_Acct_Sls_Summ_SFID__c = as1.Id,
       CFY_Grower_Account_SFID__c = a1.Id,
       Integration_Key__c = String.ValueOf(FiscalYearplusone) +'|test2',
       IsValid__c = false,
       Sales_Focus_Descr__c = 'Open',
       is_Active__c = true);  
       AORListToInsert.add(aor11);
       
       Account_Org_Relationship__c aor12 = new Account_Org_Relationship__c(
       Name = 'TestAccOrgRelationship', 
       Account_SFID__c = a1.Id, 
       Org_Account_SFID__c = a0.Id,
       Org_SFID__c = MO4.Id, 
       CFY_Dealer_Account_SFID__c = a0.Id,
       Corn_Acct_Sls_Summ_SFID__c = as0.Id,
       Soy_Acct_Sls_Summ_SFID__c = as1.Id,
       CFY_Grower_Account_SFID__c = a1.Id,
       Integration_Key__c = String.ValueOf(FiscalYearplusone) +'|test3',
       IsValid__c = false,
       Sales_Focus_Descr__c = 'Open',
       is_Active__c = true);  
       AORListToInsert.add(aor12);
       
       Account_Org_Relationship__c aor13 = new Account_Org_Relationship__c(
       Name = 'TestAccOrgRelationship', 
       Account_SFID__c = a1.Id, 
       Org_Account_SFID__c = a0.Id,
       Org_SFID__c = MO4.Id, 
       CFY_Dealer_Account_SFID__c = a0.Id,
       Corn_Acct_Sls_Summ_SFID__c = as0.Id,
       Soy_Acct_Sls_Summ_SFID__c = as1.Id,
       CFY_Grower_Account_SFID__c = a1.Id,
       Integration_Key__c = String.ValueOf(FiscalYearplusone) +'|test4',
       IsValid__c = false,
       Sales_Focus_Descr__c = 'Open',
       is_Active__c = true);  
       AORListToInsert.add(aor13);
       
       Account_Org_Relationship__c aor14 = new Account_Org_Relationship__c(
       Name = 'TestAccOrgRelationship', 
       Account_SFID__c = a1.Id, 
       Org_Account_SFID__c = a0.Id,
       Org_SFID__c = MO4.Id, 
       CFY_Dealer_Account_SFID__c = a0.Id,
       Corn_Acct_Sls_Summ_SFID__c = as0.Id,
       Soy_Acct_Sls_Summ_SFID__c = as1.Id,
       CFY_Grower_Account_SFID__c = a1.Id,
       Integration_Key__c = String.ValueOf(FiscalYearplusone) +'|test5',
       IsValid__c = false,
       Sales_Focus_Descr__c = 'Open',
       is_Active__c = true);  
       AORListToInsert.add(aor14);

        Test.startTest();
        if(AORListToInsert.size() >0 ){
            database.insert(AORListToInsert, false);
            database.update(AORListToUpdate, false);
        }   
        List<Account_Org_Relationship__c> aor = [Select fAccount_Brand_Name__c,Id,Integration_Key__c,fFiscal_Year__c,
                                           Org_SFID__c,Org_SFID__r.Fiscal_Year_SFID__r.Year__c,Sales_Focus_Descr__c FROM Account_Org_Relationship__c
                                           where Account_SFID__c = :a1.id];
        system.debug('aor ^^^^^^^^^^^^^'+aor);       
        BatchSalesfocusAORRollOver bc = new BatchSalesfocusAORRollOver();
        bc.getCurrentFY();
       database.executeBatch(bc);
        Test.stopTest();          
   
    }
}



 
Hi All 

I have a batch class as follows 
 
Integer FiscalYear = getCurrentFY();
    Integer FYPlusOne = FiscalYear - 1;

    global database.querylocator start(Database.BatchableContext BC){   
        Integer lmt = Limits.getLimitQueryRows();
        String query = 'Select Org_SFID__r.Fiscal_Year_SFID__c,fAccount_Brand_ID__c,Id,CFY_Dealer_Account_SFID__r.Brand_Group_Name__c,Integration_Key__c,';     
        query += 'Org_SFID__c,Org_SFID__r.Fiscal_Year_SFID__r.Year__c,Sales_Focus_Descr__c';
        query += ' FROM Account_Org_Relationship__c';
        query += ' WHERE Sales_Focus_Descr__c =\'Assigned\' and is_Active__c = True and fFiscal_Year__c = False and fAccount_Brand_Name__c =: National';

I need to add a condition to the query like Inte__key__c like 'FYPlusOne%' 

Intekey field value will be in the format of 2017|39238shdshdhkjsoskok. I have to fetch the records of the previous fiscal year so the inteley should contain 2017(Currentfiscalyear - 1) 

Please help me how to achieve this in where condition. I have a declared a variable on top 

Thanks 
Sangeetha T
User A  belongs to a public group, A report folder is created with Editor access to the pulbic group. User A can view the dashboard but face privilieges issue when trying access the report that is related to the dashboard component (by clicking on the component prompted to report)


Whats the issue here any idea 
Hi friends I have created a trigger in salesforce to find the number of contacts associated with an account 

The trigger is not firing for the existing records ...Is der any way to sort this if so ...How 

Thanks in advance 
Trigger ContactCountTrigger on Contact(After insert,After Delete,After Undelete)
{
  Set<Id> setAccountIds = new Set<Id>();
  
  //Whenever your working with After Undelete operation you can access data through 
  //Trigger.new or Trigger.newMap but not with Trigger.old or Trigger.oldmap variables
  if(Trigger.isInsert || Trigger.isUndelete)
  {
   for(Contact con : Trigger.new)
   {
    setAccountIds.add(con.AccountId);
   }
  }
  
  if(Trigger.isDelete)
  {
   //if you use Trigger.new below in place of Trigger.old you will end up with 
   //System.NullPointerException:Attempt to de-reference a null object
   for(Contact con : Trigger.old) 
   {
    setAccountIds.add(con.AccountId);
   }
  }
  
 List<Account> listAccs = [Select id,name,Number__c,(Select id from contacts) from Account where Id in : setAccountIds];
  for(Account acc :listAccs)
  {
   acc.Number__c= acc.contacts.size();
  }
  update listAccs;
}
}

 
Hi All

I have created a VF page to create a new contact and a button to show the list of  existing contacts

But when i click show the error "required fields"

How to have both command buttons on one single page 
When i click show it should show list of contacts 
<apex:page standardcontroller="Contact" extensions="contactslist">
<apex:form >
<apex:pageBlock title="Create a new contact">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Enter the details for creating a new contact" columns="2">
<apex:inputField value="{!contact.Lastname}" />
<apex:inputField value="{!contact.email}" required="true"/>
<apex:inputField value="{!contact.phone}" required="true"/>
<apex:inputField value="{!contact.AccountId}" required="true"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="List of contacts and Accounts">
<apex:pageBlockTable value="{!conli}" var="a">
<apex:column title="lastname" value="{!a.lastname}"/>
<apex:column title="email" value="{!a.email}"/>
<apex:column title="phone" value="{!a.phone}"/>
<apex:column title="Account_name" value="{!a.Account.name}"/>
<apex:column title="Account.Type" value="{!a.Account.Type}"/>
<apex:column title="Account.Industry" value="{!a.Account.Industry}"/>
</apex:pageBlockTable>
<Apex:commandButton value="show" action="{!show}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
 
public with sharing class contactslist
{

    public contactslist(ApexPages.StandardController controller) {

    }

public list<contact> conli {get; set;}
public pageReference show()
{
conli=[select lastname,Email, phone, Account.name, Account.Type, Account.Industry from contact where Account.name != Null order by Contact.CreatedDate];
return null;
}
}

 
Need test class for the following trigger with atleast 75 code coverage 

The below trigger  : Opportunity has a field where the associated  contact name should be populated (after lead conversion to acc,contact,opp)
trigger ContactNameUpdate on Lead (after update) 
{
  for(Lead l : System.Trigger.new) 
  {
    
   if(l.IsConverted && l.ConvertedOpportunityId != null) 
   { 
       
    Opportunity opp = [SELECT Id,Contact__c FROM Opportunity WHERE Id =: l.ConvertedOpportunityId];
    If(opp.Contact__c == null)
    { 
     opp.Contact__c = l.ConvertedContactId;
     update opp;
    }
   }
    
     
      
  }
Please give me the test class to cover 75 of code coverage to migration.......Very Critical
Please give me the test class to cover 75 of code coverage to migration.......Very Critical
Need test class for the following trigger with atleast 75 code coverage 
Trigger 1
The below trigger  : Lead and Contact have same checkbox fields, both object fields should have same value 
trigger checktheLeadCheckBox on Contact (after update) 
{
  for(Contact c : Trigger.New)
  {
    List<Lead> li = [select Id, Customer_of_PubKCyber__c,Email,Customer_of_PubKLaw__c from Lead where Email =: c.Email AND IsConverted =: false]; 
    for(Lead l : li)
    {
     If(l.Id != null)
     { 
       l.Customer_of_PubKCyber__c=c.Customer_of_PubKCyber__c;
       l.Customer_of_PubKLaw__c = c.Customer_of_PubKLaw__c;
       update l;
     }
    }
  }
}
Trigger 2 
The below trigger : checking the value of the checkboxes on Contacts object based on a condition 
trigger updatecontactcheckbox on Opportunity (after insert, after update) 
{    
    for(Opportunity o : Trigger.New)
    {
  
     if( o.Contact__c != null)                 
     {      
       Contact c = [select Id, Customer_of_PubKCyber__c,Email,Customer_of_PubKLaw__c from Contact where Id =: o.Contact__c ]; 
       
if((o.Subscription_Start_Date__c <= System.Today()) && (o.Subscription_End_Date__c >= System.Today()) && (o.Product_Name__c == 'PubKCyber Newsletter'))
    {
         c.Customer_of_PubKCyber__c = True;
        
    }
    else if(o.Product_Name__c == 'PubKCyber Newsletter')
         { 
           c .Customer_of_PubKCyber__c = false;
           
         }
          
if((o.Subscription_Start_Date__c <= System.Today()) && (o.Subscription_End_Date__c >= System.Today()) && (o.Product_Name__c == 'PubKLaw Newsletter'))
        { 
          c.Customer_of_PubKLaw__c= True;
         
        }
       else if(o.Product_Name__c == 'PubKLaw Newsletter')
         { 
           c.Customer_of_PubKLaw__c = false;            
         }
       update c; 
      }   
     }  
  }

Please give me the test class to cover 75 of code coverage to migration.......Very Critical
Please give me the test class to cover 75 of code coverage to migration.......Very Critical
Hi I'm stuck up in writing the test classes for the following triggers to achieve code coverage while deployment 

What would be the test class for the following trigger 

trigger 1

trigger checktheLeadCheckBox on Contact (after update) 
{
  for(Contact c : Trigger.New)
  {
    List<Lead> li = [select Id, Customer_of_PubKCyber__c,Email,Customer_of_PubKLaw__c from Lead where Email =: c.Email AND IsConverted =: false]; 
    for(Lead l : li)
    {
     If(l.Id != null)
     {
      
      
       l.Customer_of_PubKCyber__c=c.Customer_of_PubKCyber__c;
       l.Customer_of_PubKLaw__c = c.Customer_of_PubKLaw__c;
       update l;
     }
    }
  }
}

Trigger 2

trigger updatecontactcheckbox on Opportunity (after insert, after update) 
{    
    for(Opportunity o : Trigger.New)
    {
  
     if( o.Contact__c != null)                 
     {      
       Contact c = [select Id, Customer_of_PubKCyber__c,Email,Customer_of_PubKLaw__c from Contact where Id =: o.Contact__c ]; 
       
if((o.Subscription_Start_Date__c <= System.Today()) && (o.Subscription_End_Date__c >= System.Today()) && (o.Product_Name__c == 'PubKCyber Newsletter'))
    {
         c.Customer_of_PubKCyber__c = True;
        
    }
    else if(o.Product_Name__c == 'PubKCyber Newsletter')
         { 
           c .Customer_of_PubKCyber__c = false;
           
         }
          
if((o.Subscription_Start_Date__c <= System.Today()) && (o.Subscription_End_Date__c >= System.Today()) && (o.Product_Name__c == 'PubKLaw Newsletter'))
        { 
          c.Customer_of_PubKLaw__c= True;
         
        }
       else if(o.Product_Name__c == 'PubKLaw Newsletter')
         { 
           c.Customer_of_PubKLaw__c = false;            
         }
       update c; 
      }   
     }  
  }
Hi 
I want to map a field between lead and opportunity for converted lead. But I get the following error 
Error: Lead field length of 3,900 is greater than this field's length of 255
I cant change the data type of the of the opportunity field since it is associated with one workflow and formula field
then what are the other ways to resolve it ??

Please Note : I have migrated these changesets from sandbox to production(in dev it worked fine but production creates a problem)

Critical issue 

Hi I have two custom fields subscription_start_date and subscription_end_date on Opportunity object

Have a two custom checkbox customer1 and customer2 on Contact Object (These two checkboxes are checked from another workflow)

I have a requirement to that these checkboxes should be unchecked if today date does not lies between subscription_start_date and subscription_end_date

No i have to write a trigger with the condition

if (today date should be greater than or equal to subscription_start_date) and (lesser than or equal to subscription_end_date) and (customer1 checkbox should be checked)

{customer1=true }//should be checked

else 

{customer1=false}//should not be checked

 

 

The following is my trigger but does not gives expected result 

what is wrong 

 

trigger checkthecheckbox on Contact (before insert) {

Set<id> oppids = new set<id>();

for (Contact opp: Trigger.new)
{
 oppids.add(opp.id);
}

Map<id, opportunity> oppMap = new Map<id, opportunity>();
for(opportunity o : [select Subscription_Start_Date__c,Subscription_End_Date__c from opportunity where id in: oppids])
{
 
oppMap.put(o.id, o); 
}

for (Contact opp: Trigger.new)
{
if(oppMap.get(opp.Id).Subscription_Start_Date__c>=date.Today())
{
opp.Customer_of_PubKCyber__c=False;
}
 
}
}

 



I have two checkbox fields in Lead and Contact objects  These fields would be tick marked if the customer has purchased the product in the past and the subscription period is active. . 

The requirement is 
- For every record in the Lead and Contact object, need to check if there is an opportunity and opportunity product associated with it
- If true then check if the associated Product name in the Opportunity product object contains the text "PubKLaw" or "PubKCyber" and the current date falls between start date and end date found in the Opportunity Product object
- If true then the above checkbox fields on the Lead and Contact objects for that particular customer needs to be checked
- This check needs to be dynamic that when the subscription ends the tick mark on those fields should be automatically removed 

Can i go for trigger or workflow would do a trick
I have a custom field Contact__c on Opportunity object and that field should be populated with the value of ContactID of that opportunity
This should also work for the converted leads they turn into a contact and opportunity

How to achieve this using trigger ​​.It would be great if you give me the sample code
#Newtotrigger
Hi this is the requiremnt
i have to copy the standard field(Closedate) on opportunities object to custom filed(start_date__c) on Opportunities products object
and opportunities products have another field called enddate where enddate = start_date_c + 1 year + 14 days and also check according for leap year (i.e) leap year may have 1 day extra ​
Please help me with the apex trigger
URGENT !!!! Need Help 
I have a custom search lookup modal window which will search the products and display results 
PFB for the code 
<template>
    <template if:true={isShowModal}>
        <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open slds-modal_medium">
            <div class="slds-modal__container">
                <!-- modal header start -->
                <header class="slds-modal__header">
                    <button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" title="Close" onclick={hideModalBox}>
                        <lightning-icon icon-name="utility:close" alternative-text="close" variant="inverse" size="small" ></lightning-icon>
                        <span class="slds-assistive-text">Close</span>
                    </button>
                    <h2 id="modal-heading-01" style="text-align: left;" class="slds-text-heading_medium">Product Custom Search</h2>
                </header>
                <!-- modal body start -->
                <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                    <ul class="slds-list_horizontal">
                        <li class="slds-item_detail" style="margin-left: 10px;">
                            <div style="font-weight: bold;">
                                <lightning-input type="text" label="Product Name" name="name" variant="standard" placeholder="Enter Product Name" onchange={handleChange} disabled={isnameDisable}></lightning-input>
                            </div>
                        </li>
                        <li class="slds-item_detail" style="margin-left: 10px;">
                            <div style="font-weight: bold;">
                                <lightning-input type="text" label="Product ID" name="MOLProductID" variant="standard" placeholder="Enter Product ID" onchange={handleChange} disabled={isMOLProductIDDisabled}></lightning-input>
                            </div>
                        </li>
                        <li class="slds-item_detail" style="margin-left: 10px;">
                            <div style="font-weight: bold;">
                                <lightning-input type="text" label="Old Material Number" name="MOLOldMaterialNumber" variant="standard" placeholder="Enter Old Material Number" onchange={handleChange} disabled={isMOLOldMaterialNumberDisable}></lightning-input>
                            </div>
                        </li>

                        <li class="slds-item_detail" style="margin-top: 23px;">
                            <div>
                                <lightning-button variant="brand" label="Search" title="Search" icon-name="utility:search" class="slds-m-left_x-small" onclick={handleSearch}></lightning-button>
                            </div>
                        </li>
                    </ul>
                    <div if:true={isDataTrue} style="margin-top: 20px;">
                        <div class="slds-clearfix">
                            <p class="slds-float_left"><strong>No of Records: {recordLength}</strong></p>
                            <lightning-button variant="brand" label="Save and Select" title="Save and Select" class="slds-button slds-float_right databuttons" onclick={handleSave}></lightning-button>
                            <lightning-button variant="destructive" label="Cancel" title="Cancel" class="slds-button slds-float_right databuttons" onclick={hideModalBox}></lightning-button>
                        </div>
                        <div class="fixTableHead">
                            <table>
                                <thead>
                                <tr>
                                    <th>Select</th>
                                    <th>Product Name</th>
                                    <th>Product ID</th>
                                    <th>Old Material Number</th>
                                </tr>
                                </thead>
                                <tbody>
                                    <template for:each={productList} for:item="product">
                                        <tr key={product.Id}>
                                            <td>
                                                <input type="radio" class="selectId" name="productRecord" value={product.Id} />
                                            </td>
                                            <td>{product.Name}</td>
                                            <td>{product.MOL_ProductID__c}</td>
                                            <td>{product.MOL_OldMaterialNumber__c}</td>
                                            
                                        </tr>
                                    </template>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div if:true={isDataFalse}>
                        <p><strong>No Records Found.</strong></p>
                    </div>
                </div>
                <!-- modal footer start-->
                <footer class="slds-modal__footer"></footer> 
            </div>
        </section>
        <div class="slds-backdrop slds-backdrop_open"></div>
    </template>
    <!-- modal end -->
</template>
 
import { LightningElement,track,api} from 'lwc';
import getProductRecords from '@salesforce/apex/PdrProductsearch.getProductRecords';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class PdrProductCustomSearch1 extends LightningElement {
    @api recordId;
    @track isShowModal = false;
    @track recordLength=0;
    @track isDataTrue = false;
    @track isDataFalse = false;
    @track productList = [] // added as a list
    searchType='';
    searchTerm='';

    handleChange = (event) =>{
        this.searchType = event.target.name;
        this.searchTerm = event.target.value;
    }

    get isnameDisable(){
        return ( this.searchType != 'name' && this.searchTerm != ''? true : false );
    }

    get isMOLProductIDDisabled(){
        return ( this.searchType != 'MOLProductID' && this.searchTerm != ''? true : false );
    }

    get isMOLOldMaterialNumberDisable(){
        return ( this.searchType != 'MOLOldMaterialNumber' && this.searchTerm != ''? true : false );
    }

    resetData(){
        this.productList = null;
        this.recordLength = 0;
        this.searchTerm = '';
        this.isDataTrue = false;
        this.isDataFalse = false;  
    }

    @api showModalBox() {  
        this.isShowModal = true;
    }

    hideModalBox() {
        this.resetData(0); 
        this.isShowModal = false;
    }

    getProductNameById = (obj,id) =>{
        let mapObj = new Map();
        for (let i=0; i<Object.keys(obj).length; i++){
            mapObj.set(obj[i].Id,obj[i].Name);
        }
        if (mapObj.has(id)){
            return mapObj.get(id);
        }
    }

    handleSave = (event) =>{
        let recIds = this.template.querySelectorAll('.selectId');
        let prodId = '';
        let prodName = '';
        for (let i=0; i<recIds.length; i++){
            if (recIds[i].checked){
                prodId = recIds[i].value;
                break;
            }
        }
        prodName = this.getProductNameById(this.productList,prodId);
        const customEvt = new CustomEvent(
            "pass",
            {   detail : { id: prodId, name : prodName}
            }
        );
        this.dispatchEvent(customEvt);
        this.hideModalBox(0);
    }

    handleSearch = (event) =>{
        if( this.searchTerm!='' && this.searchType!='' ){
            getProductRecords({searchTerm : this.searchTerm, searchType : this.searchType})
            .then( (response) =>{
                        console.log(response);
                        if(response!=null){
                            this.productList = JSON.parse(JSON.stringify(response));
                            let count = Object.keys(this.productList).length;
                            console.log(count);
                            this.recordLength = count;
                            if (this.recordLength>0) {
                                this.isDataTrue = true;
                                this.isDataFalse = false;
                            }else{
                                this.productList = null;
                                this.isDataFalse = true;
                                this.isDataTrue = false;
                            }
                        }
                        else{
                            this.productList = null;
                            this.isDataFalse = true;
                            this.isDataTrue = false;
                        }
                    }
            ).catch( (error) => {
                        const event = new ShowToastEvent({
                            title: 'Error',
                            variant: 'error',
                            message: error.body.message,
                        });
                        this.dispatchEvent(event);
                        this.productList = null;
                        this.isDataFalse = true;
                        this.isDataTrue = false;
                    }
            );
        }else{
            this.productList = null;
            this.isDataFalse = true;
            this.isDataTrue = false;
        }
    }
}
 
public without sharing class PdrProductsearch {
    
    @AuraEnabled(cacheable=true)
    public static List<Product2> getProductRecords(String searchTerm, String searchType){
        try {
            List<Product2> proRec = new List<Product2>();
            String searchTxt = '%'+searchTerm+'%';
            if(searchType=='name' && searchTerm!='')
            {
                proRec = [ Select Id,Name,MOL_ProductID__c,MOL_OldMaterialNumber__c From Product2 where Name like : searchTxt With SECURITY_ENFORCED];
            }
            else if(searchType=='MOLProductID' && searchTerm!='')
            {
				proRec = [ Select Id,Name,MOL_ProductID__c,MOL_OldMaterialNumber__c From Product2 where MOL_ProductID__c like : searchTxt With SECURITY_ENFORCED];
            }
            else if(searchType=='MOLOldMaterialNumber' && searchTerm!='')
            {
                proRec = [ Select Id,Name,MOL_ProductID__c,MOL_OldMaterialNumber__c From Product2 where MOL_OldMaterialNumber__c like : searchTxt With SECURITY_ENFORCED];   
            }
            else
            {
                proRec = null;
            }

            //Checking data..
            System.debug('Queried Data-->'+proRec);

            //Checking whether Record List is not null and has atleast some Records
            if( proRec!=null && proRec.size()>0 ){
                return proRec;
            }else{
                return null;
            }

        } catch (Exception e) {
            throw new AuraHandledException(e.getMessage());
        }
    }

}

Now I'm calling this child LWC in my parent LWC which  has the Table row 
Now when I click the modal popup its opens and allows me to search and gets inserted on the first row of adding the products 
But for the second row or third row, it's not working and the selected value from the search result does not get included 

PFB for calling the child component 
<td>
                                <lightning-input type="search" data-index={indx} name="selectedProductName" value={item.selectedProductName}
                                onchange={handleAllData} onclick={handleChildModal} label="Material" variant="standard" required></lightning-input>
                                <c-pdr-product-custom-search-1 data-index={indx} onpass={handleSelectedRec} ></c-pdr-product-custom-search-1>

I'm not sure what I'm missing - Any help will be appreciated

Hi,

I created a connectedApp and added that to a managed package.        I installed the managed package in another salesforce account. Somehow I cant get the consumer key and consumer secret key from the package installed account. It has only the manage option which I can get the details and edit policies. Is there a way to get the cosumer key and consumer secret key. I'm new to salesforce. Please help me regarding this matter. 

Thank you.
 

Hi All 
I have created a Lightning component buttton to download attachments related to email message 
Now I'm able to fetch all attachment IDS as per debug log 
But only one file is downloading 
In Email Messages having more that one attachment only the first attachment is downloading. How to fix this 
Please help me with the code correction 

I have tried using various scenarios but could not achieve the mutiple attachments downloading
<aura:component controller ='DownloadAllFilesClass' implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" 
                access="global" >
       
	<lightning:button label="Download All Files" onclick ="{! c.downloadfiles }" variant ="brand" iconName = "utility:download"/>
</aura:component>
 
({
    downloadfiles : function(component, event, helper) {
        var action = component.get("c.generateDownloadFilesLines");
        console.log("This component"+component.get("v.recordId"));
        action.setParams({EmailMessageId : component.get("v.recordId")});
        action.setCallback(this,function(response){
            var state = response.getState();
            if (state === "SUCCESS"){
                if (response.getReturnValue() != 'No document available')
                {

                    var urlEvent = $A.get("e.force:navigateToURL") ;
                    urlEvent.setParams({"url":response.getReturnValue()});
                    urlEvent.fire();
                }
                else
                {
                    var toastEvent = $A.get("e.force:showToast");
                    toastEvent.setParams({
                        title : 'Error',
                        Message : 'No document available',
                        duration : '50000',
                        key : 'info_alt',
                        type : 'error',
                        mode : 'pester',
                    });
                    toastEvent.fire();
                }
                    
                
            }
            else if (state === "INCOMPLETE")
            {
                
            }
                else if (state === "ERROR"){
                    var errors = response.getError();
                    if(errors){
                        if (errors[0] && errors[0].message)
                        {
                            console.log("Error Message:"+errors[0].message);
                        }
                    }
                        else
                        {
                            console.log("Unknown Error");
                        }
                    }
            });
            
            $A.enqueueAction(action);
        }
})
 
public without sharing class DownloadAllFilesClass {
    @AuraEnabled
    public static String[] generateDownloadFilesLines(Id EmailMessageId){
    String[] URL1 =new String[]{};
    String URLInstance = String.valueOf(System.URL.getSalesforceBaseUrl().gethost());
    String URLAppend = URLInstance.SubStringBefore('.my');    
    System.debug('Appended String::'+URLAppend);
    List<ID> idslist = new List<ID>();
    List<Attachment> cdllist = [Select ID,ParentID from Attachment where ParentID =:EmailMessageId];
    System.debug('EmailMessageID:: '+EmailMessageId);
    System.debug('List of Ids related to EmailMessageID:: '+cdllist);  
    System.debug('URLInstance:: '+URLInstance); 
        if(cdllist != null && cdllist.size() > 0)
    {
             for(Attachment cdl : cdllist)
    {
             idslist.add(cdl.ID);
    }
    }
    if (idslist != null && idslist.size() > 0)
    {
        for(ID i : idslist)
        {
          String URL2 = 'https://'+URLAppend+'--c.documentforce.com/servlet/servlet.FileDownload?file='+i+'&operationContext=S1';
          system.debug('URL2::'+URL2);
          URL1.add(URL2);
        }
        system.debug('AttachmentIds:: '+idslist);
        system.debug('DownloadURL:: '+URL1); 
        
    }
        return URL1;
}
}

 
Need help in writing a component that downloads all the attachments of the email message 

Altenative of javascript to work in lightning 
Hi All 
I'm currently removing all the hard coded IDs to Custom Label
I have a formula in Process builder 
------------------------
$User.Id  <> 18 digit ID
------------------------
I captured the 18 digit ID in custom label and tried using the same in the formula field
------------------------
$User.Id  <> $Label.AAA 
------------------------
But Not working. Any help please

My goal is to replace the hardcoded ID to a custom Label 
Hi All

Please help me in defining the CRON expression for running a scheduler class for every 30th min of an hour 
For example first run should be 9 30 next should be 10 30 next should be 11 30 

 
Hi All 

I have a batch class as follows 
 
Integer FiscalYear = getCurrentFY();
    Integer FYPlusOne = FiscalYear - 1;

    global database.querylocator start(Database.BatchableContext BC){   
        Integer lmt = Limits.getLimitQueryRows();
        String query = 'Select Org_SFID__r.Fiscal_Year_SFID__c,fAccount_Brand_ID__c,Id,CFY_Dealer_Account_SFID__r.Brand_Group_Name__c,Integration_Key__c,';     
        query += 'Org_SFID__c,Org_SFID__r.Fiscal_Year_SFID__r.Year__c,Sales_Focus_Descr__c';
        query += ' FROM Account_Org_Relationship__c';
        query += ' WHERE Sales_Focus_Descr__c =\'Assigned\' and is_Active__c = True and fFiscal_Year__c = False and fAccount_Brand_Name__c =: National';

I need to add a condition to the query like Inte__key__c like 'FYPlusOne%' 

Intekey field value will be in the format of 2017|39238shdshdhkjsoskok. I have to fetch the records of the previous fiscal year so the inteley should contain 2017(Currentfiscalyear - 1) 

Please help me how to achieve this in where condition. I have a declared a variable on top 

Thanks 
Sangeetha T
Need test class for the following trigger with atleast 75 code coverage 

The below trigger  : Opportunity has a field where the associated  contact name should be populated (after lead conversion to acc,contact,opp)
trigger ContactNameUpdate on Lead (after update) 
{
  for(Lead l : System.Trigger.new) 
  {
    
   if(l.IsConverted && l.ConvertedOpportunityId != null) 
   { 
       
    Opportunity opp = [SELECT Id,Contact__c FROM Opportunity WHERE Id =: l.ConvertedOpportunityId];
    If(opp.Contact__c == null)
    { 
     opp.Contact__c = l.ConvertedContactId;
     update opp;
    }
   }
    
     
      
  }
Please give me the test class to cover 75 of code coverage to migration.......Very Critical
Please give me the test class to cover 75 of code coverage to migration.......Very Critical
HELP!
I am getting the below error when I try to check my challenge:
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Update failed. First exception on row 0 with id 0016100000PUJDEAA5; first error: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 301610000005A3l. Contact your administrator for help.: []

How do I fix this?
Hi I'm stuck up in writing the test classes for the following triggers to achieve code coverage while deployment 

What would be the test class for the following trigger 

trigger 1

trigger checktheLeadCheckBox on Contact (after update) 
{
  for(Contact c : Trigger.New)
  {
    List<Lead> li = [select Id, Customer_of_PubKCyber__c,Email,Customer_of_PubKLaw__c from Lead where Email =: c.Email AND IsConverted =: false]; 
    for(Lead l : li)
    {
     If(l.Id != null)
     {
      
      
       l.Customer_of_PubKCyber__c=c.Customer_of_PubKCyber__c;
       l.Customer_of_PubKLaw__c = c.Customer_of_PubKLaw__c;
       update l;
     }
    }
  }
}

Trigger 2

trigger updatecontactcheckbox on Opportunity (after insert, after update) 
{    
    for(Opportunity o : Trigger.New)
    {
  
     if( o.Contact__c != null)                 
     {      
       Contact c = [select Id, Customer_of_PubKCyber__c,Email,Customer_of_PubKLaw__c from Contact where Id =: o.Contact__c ]; 
       
if((o.Subscription_Start_Date__c <= System.Today()) && (o.Subscription_End_Date__c >= System.Today()) && (o.Product_Name__c == 'PubKCyber Newsletter'))
    {
         c.Customer_of_PubKCyber__c = True;
        
    }
    else if(o.Product_Name__c == 'PubKCyber Newsletter')
         { 
           c .Customer_of_PubKCyber__c = false;
           
         }
          
if((o.Subscription_Start_Date__c <= System.Today()) && (o.Subscription_End_Date__c >= System.Today()) && (o.Product_Name__c == 'PubKLaw Newsletter'))
        { 
          c.Customer_of_PubKLaw__c= True;
         
        }
       else if(o.Product_Name__c == 'PubKLaw Newsletter')
         { 
           c.Customer_of_PubKLaw__c = false;            
         }
       update c; 
      }   
     }  
  }
Hi 
I want to map a field between lead and opportunity for converted lead. But I get the following error 
Error: Lead field length of 3,900 is greater than this field's length of 255
I cant change the data type of the of the opportunity field since it is associated with one workflow and formula field
then what are the other ways to resolve it ??

Please Note : I have migrated these changesets from sandbox to production(in dev it worked fine but production creates a problem)

Critical issue 

Hi I have two custom fields subscription_start_date and subscription_end_date on Opportunity object

Have a two custom checkbox customer1 and customer2 on Contact Object (These two checkboxes are checked from another workflow)

I have a requirement to that these checkboxes should be unchecked if today date does not lies between subscription_start_date and subscription_end_date

No i have to write a trigger with the condition

if (today date should be greater than or equal to subscription_start_date) and (lesser than or equal to subscription_end_date) and (customer1 checkbox should be checked)

{customer1=true }//should be checked

else 

{customer1=false}//should not be checked

 

 

The following is my trigger but does not gives expected result 

what is wrong 

 

trigger checkthecheckbox on Contact (before insert) {

Set<id> oppids = new set<id>();

for (Contact opp: Trigger.new)
{
 oppids.add(opp.id);
}

Map<id, opportunity> oppMap = new Map<id, opportunity>();
for(opportunity o : [select Subscription_Start_Date__c,Subscription_End_Date__c from opportunity where id in: oppids])
{
 
oppMap.put(o.id, o); 
}

for (Contact opp: Trigger.new)
{
if(oppMap.get(opp.Id).Subscription_Start_Date__c>=date.Today())
{
opp.Customer_of_PubKCyber__c=False;
}
 
}
}

 

I have a custom field Contact__c on Opportunity object and that field should be populated with the value of ContactID of that opportunity
This should also work for the converted leads they turn into a contact and opportunity

How to achieve this using trigger ​​.It would be great if you give me the sample code
#Newtotrigger
Hi this is the requiremnt
i have to copy the standard field(Closedate) on opportunities object to custom filed(start_date__c) on Opportunities products object
and opportunities products have another field called enddate where enddate = start_date_c + 1 year + 14 days and also check according for leap year (i.e) leap year may have 1 day extra ​
Please help me with the apex trigger
I am using a Mydomain enabled dev org on gs0 (Winter 16) and going throught the exercise in Trailhead. 

Follwed every step and when i click on Preview it takes me to my app (looks right) - https://skypeforbiz-dev-ed.lightning.force.com/c/Sfb.app

But it errors out with -

Lightning components require My Domain. Please contact your system administrator for more information.

Any idea what I might be missing? My org is defenitely provisioned with MyDomin.