• Abhishek Khosla
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 8
    Replies
Hi I am not able to understand why I am not able to get the data from my wire service when I am puting the data in my serach field, when the search field is blank it do render and i can see the data , but when i put any data to search it doesnt react to that search key 

below is the code 
HTML 
<template>
    <lightning-card title="Product Search">
        <div class="slds-m-around_medium">
            <lightning-input name="enter-search" label="Search" type="search" onchange={handleSearch} is-loading={isSearching}></lightning-input><br/>
            <lightning-input name="NABTick" label="NAB Price List" type="checkbox" onchange={handleCheckbox} ></lightning-input><br/>
        <lightning-button label="Search" name="search" title="Search Products" onclick={findProductKey} variant="brand" ></lightning-button>&nbsp;&nbsp;&nbsp;
            <lightning-button label="Cancel" name="cancel" title="Cancel" onclick={handleCancle} ></lightning-button>
        
        </div>
        <div>
            This is the search key value ={searchKey}
            This is NAB Check list Value={NABcheckbox}
        </div>
        
        <template if:true={allProduct.data}>
            <div>
                <template for:each={allProduct.data} for:item=product>
                    This is the prodcut Id :{product.Id}
                  <c-product-search-result-wired key={product.Id} product={product}></c-product-search-result-wired>
                </template>
            </div>
        </template>
    </lightning-card>
    
</template>
Vchild component 
<template>
    <div class="slds-p-around_medium lgc-bg" key={product.Id}>
        <ul class="slds-has-dividers_bottom-space">
            <li class="slds-item">
                <lightning-tile label={product.Name}>
                    <ul class="slds-list_horizontal slds-has-dividers_right">
                        <li class="slds-item">Product Code: {product.ProductCode}</li>
                        <li class="slds-item">Eng Status: {product.Eng_Status__c}</li>
                        <li class="slds-item">Dark Knight</li>
                        <li class="slds-item">Dark Knight</li>
                    </ul>
                </lightning-tile>
            </li>
        </ul>
        </div>     
</template>

Parent JS
import { LightningElement,track,wire } from 'lwc';
import getProducts from '@salesforce/apex/productSearch.getProducts';

const DELAY = 300;
export default class ProductSearchWired extends LightningElement {
    @track searchKey='';
    @track NABcheckbox= false;
    @track allProduct=[];
    
    
    @wire(getProducts,{productSearchKey:'$searchKey'})
    products({data,error}){
        if(data){
            this.allProduct = data;
        }
    }

    handleSearch(event){
        window.clearTimeout(this.delayTimeout);
        const searchKey = event.target.value;
        // eslint-disable-next-line @lwc/lwc/no-async-operation
        this.delayTimeout = setTimeout(() => {
            this.searchKey = searchKey;
        }, DELAY);
    }

    handleCheckbox(){
        this.NABcheckbox = true;
    }

    get isSearching(){
        if(this.allProduct){
            return false;
        } else {
            return true;
        }
    }
}

Child JS File
import { LightningElement,api } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';

export default class ProductSearchResultWired extends NavigationMixin(LightningElement) {
    @api product;

    navigateToProduct(){
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                actionName: "view",
                recordId: this.product.Id,
                objectApiName: "Product2"
            }
        });

    }
}

Apex Class Controller
public static List<Product2> getProducts(String productSeachKey)
    {
          if( String.isNotEmpty(productSeachKey))
        {
            return [SELECT Id,Name,ProductCode,Eng_Status__c,Quotable__c,USD_Price__c FROM Product2 WHERE IsActive= true AND Eng_Status__c IN ('Production','Procurement','Prototype','Hold')
                    AND Field_Replaceable_Part__c = false AND Base_Price_List_Item__c != null AND (Name LIKE : '%'+productSeachKey+'%' OR ProductCode LIKE: '%'+productSeachKey+'%')
                    ORDER BY SBQQ__SortOrder__c ASC NULLS LAST];
        } else 
        { 
          return [SELECT Id,Name,ProductCode,Eng_Status__c,Quotable__c,USD_Price__c FROM Product2 WHERE IsActive= true AND Eng_Status__c IN ('Production','Procurement','Prototype','Hold')
          AND Field_Replaceable_Part__c = false AND Base_Price_List_Item__c != null ORDER BY SBQQ__SortOrder__c ASC NULLS LAST];
        }

    }
    
}

When SearchKey is blank the component renders and show all the products
Hello Everyone,

I am trying to creat a custom button on Account object to create a new case. I have created a LWC component and hosted it in an Aura component so that it can be used as a quick Action. Now when a user click on create button i want it to navigate to another LWC component which has my record edit form to create case. This compoenent is also hosted in Aura component. Can somebody help me how to achieve the same. 

below is my code 
Aura Component 

<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,lightning:isUrlAddressable" >
    <c:caseRecordType recordId="{!v.recordId}"/>
</aura:component>

Lwc Comonent 

<template>
    <lightning-card title="Record Type Selector in Lightning Web Component">
            <lightning-layout multiple-rows="true" vertical-align="end">
                <lightning-layout-item size="6" small-device-size="2" medium-device-size="4" large-device-size="4" padding="around-small">
                        <div class="slds-form-element">
                            <div class="slds-form-element__control">
                                <lightning-combobox name="recordTypes"
                                                    label="Case Record Types"
                                                    value={selectedValue}
                                                    placeholder="-Select-"
                                                    options={options}
                                                    onchange={handleChange} ></lightning-combobox>
                            </div>
                        </div>
                </lightning-layout-item>
            </lightning-layout><br/>
            Selected Account Id : {recordId}
        <div style="margin-left:3%;">
            <div if:true={selectedValue}>
                Selected Record Type Id: <b>{selectedValue}</b><br/>
                
            </div>
        </div>
        <div style="margin-left:3%;">
            <lightning-button label="Create" name="Create" title="Create a New Case" variant="brand"
            onclick={createNewCase} ></lightning-button>
        </div>
    </lightning-card>
    
</template>

LWC Js 
import { LightningElement,api,track,wire } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import CASE_OBJECT from '@salesforce/schema/Case';
import {NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
export default class CaseRecordType extends NavigationMixin(LightningElement) {
    @api recordId;
    @track selectedValue;
    @track options = [];
    @wire(getObjectInfo, { objectApiName: CASE_OBJECT })
    accObjectInfo({data, error}) {
        if(data) {
            let optionsValues = [];
            // map of record type Info
            const rtInfos = data.recordTypeInfos;
            // getting map values
            let rtValues = Object.values(rtInfos);
            for(let i = 0; i < rtValues.length; i++) {
                if(rtValues[i].name !== 'Master') {
                    optionsValues.push({
                        label: rtValues[i].name,
                        value: rtValues[i].recordTypeId
                    })
                }
            }
            this.options = optionsValues;
        }
        else if(error) {
            window.console.log('Error ===> '+JSON.stringify(error));
        }
    }
     
    // Handling on change value
    handleChange(event) {
        this.selectedValue = event.detail.value;
    }
    createNewCase(){
        const defaultValues = encodeDefaultFieldValues({
            AccountId: this.recordId
        });
        let temp = {
            type: 'standard__component',
           //type: 'standard__objectPage',
            attributes: {
                componentName: 'c__caseNavigation'
                //objectApiName: 'Case',
                //actionName: 'new'
            },
            state:{
            }
            /*state : {
                recordTypeId: this.selectedValue,
                nooverride: '1',
                defaultFieldValues: defaultValues
            }*/
        };
        this[NavigationMixin.Navigate](temp);
    }
}

LWC Record edit form 

template>
    <lightning-card title = "Create New Case">
        <lightning-record-edit-form id="recordViewForm"                    
                                object-api-name="Case">
            <lightning-messages></lightning-messages>
            <lightning-input-field field-name="AccountId"></lightning-input-field>
            <lightning-input-field field-name="RecordTypeId"></lightning-input-field>
            <lightning-input-field field-name="Status"></lightning-input-field>
            <!-- submit -->
            <lightning-button type="submit" label="Update record"></lightning-button>
        </lightning-record-edit-form>
    </lightning-card>
</template>

Aura Compoent 

<aura:component implements="lightning:isUrlAddressable" >  
    <c:caseForm />
</aura:component>



 
Hi,

I am trying to call a Static method from Custom Button but getting the error " missing ) after argument List. Can somebody guide me how I can recitfy the same 

Here is my Apex code :
global class ProductGroupFamilyAddOrderTarget {
    
    webservice static void addOrderTarget(){
        List<Sales_Target__c> newSalesTarget = new List<Sales_Target__c>();
        
        List<Product_Group__c> productGrpFamilywithSeries =[SELECT Id,Name,Short_Name__c,
                                                            (SELECT Id,Parent__c,Short_Name__c FROM Children_Groups__r WHERE Group_Level__c='Series' AND isActive__c = True ) 
                                                            FROM Product_Group__c WHERE Group_Level__c='Family'AND isActive__c = True];
        
        SFDC_Fiscal_Year__c currentFiscalYear = [SELECT Id,Name FROM SFDC_Fiscal_Year__c WHERE Current__c= true];
        List<Region__c> region = [SELECT Id FROM Region__c WHERE Is_Active__c = true AND isRegion__c = true];
        List<Sales_Target__c> existOrderTarget =[SELECT Id,Product_Group__c,Region__c,SFDC_Fiscal_Year__c FROM Sales_Target__c WHERE Region__c IN :region AND SFDC_Fiscal_Year__c =: currentFiscalYear.Id];
        Map<String,Id> TargetOrder = new Map<String,Id>();
        if(existOrderTarget !=null && !existOrderTarget.isEmpty()){
            for(Sales_Target__c st : existOrderTarget){
                TargetOrder.put(String.valueOf(st.Product_Group__c)+String.valueOf(st.Region__c),st.Id);
            }
            
        }
        System.debug('Is there any Target Group Created by Error '+TargetOrder.values());
        if(productGrpFamilywithSeries != null && !productGrpFamilywithSeries.isEmpty()){
            for(Product_Group__c prdGrp : productGrpFamilywithSeries){
                if(prdGrp.Children_Groups__r !=null && !prdGrp.Children_Groups__r.isEmpty()){
                    for(Product_Group__c prdGrpChild : prdGrp.Children_Groups__r){
                        if(region !=null && !region.isEmpty()){
                            for(Region__c r : region){
                                if(!TargetOrder.containsKey(String.valueOf(prdGrpChild.id)+String.valueOf(r.Id))){
                                    Sales_Target__c newOrderTarget = new Sales_Target__c();
                                    newOrderTarget.Name = 'Newtarget2020';
                                    newOrderTarget.Target_Type__c ='Product Group';
                                    newOrderTarget.Product_Group__c = prdGrpChild.Id;
                                    newOrderTarget.Region__c = r.Id;
                                    newOrderTarget.SFDC_Fiscal_Year__c = currentFiscalYear.Id;
                                    newSalesTarget.add(newOrderTarget);
                                }
                            }
                        }
                    }
                }
            }
        }
        
        if(newSalesTarget !=null && !newSalesTarget.isEmpty()) insert newSalesTarget;
    }
    
}


And My Custom Button 

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

var result = sforce.apex.execute("ProductGroupFamilyAddOrderTarget","addOrderTarget",{});
alert(result);
Dear All,

Our steelbrick CPQ licence has expried and we are moving away from Steelbrick CPQ. I have disabled the trigger from config section of Steelbrick. Now when I am running my trigger there Steelbrick trigger are still coming into picture and my test class is showing an error. Can somebody guide me how to reslove this issue 
Hi All,

I have a custom object User Region which has a field called RSM Number and RSM__c which is the owner of that region. I want this field to be updated in Opportunity split whose Split owner is unigue and matches RSM__c . Opportunity split  is having a look up relationship with User region object. This is the tirgger I have written. But I am stuck after I have got All the USER region which have same Account region ID and RSM__C is = Split Owner ID. Because there is a ask that id Split Owner is hared between two User region then it should not update only Split owner which are not shared their RSM number should get updated through this trigger. 

Can you all please help me how to write this trigger 
Sample Code : 
Trigger RSMnumberUpdate on OpportunitySplit (before insert,before update){
if(Trigger.isbefore && (Trigger.isinsert || Trigger.isupdate)){
List<id> SplitownerID = new List<id> ();
List<String> OppAccountRegionID = new List<String>();
    For(OpportunitySplit Opsp : Trigger.new){
          SplitownerID.add(Opsp.Splitowner);
          OppAccountRegionID.add(Opsp.AccountRegionID);
}

List<ID> AllUserRegionsID = [SELECT id FROM UserRegion__c WHERE RSM__c IN : SplitownerID AND Parent_Region__c IN : OppAccountRegionID];
     
        

}
}
 
Dear All
I have a pardot/Marketo error : can you please let me know why this error is happening 

Cannot execute flow trigger: We can't save this record because the “Lead Field Updates” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to update records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: DaScoopComposer.normalizeLeadPhone: System.LimitException: Apex CPU time limit exceeded. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 439015404-11929 (-282202459)

Cannot execute flow trigger: We can't save this record because the “Lead Field Updates” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to update records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: TracRTC.RealtimeClean: System.LimitException: Apex CPU time limit exceeded. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 1901721386-13326 (-282202459)

These is a process builder in the system which name as lead field updates and it is ticked as when created or edidted 
Dear All,
I am going to install few 3rd party tool into salesforce like talk desk. When i am going to app exchange to install the package they asked me to install in production or sandbox and which user i should give access to. I am little confused here shall i install it in sandbox or production. I went through lot of forum to check the same and they told me to go for production first but i want to test the application in the test environment then push it to production. If i installed the package in production then how i can test in sandbox. Second question what use i should give the access I want to know what is the best practice so during testing phase shall i give the access to only Admin and the extend it to all  the users. Or while installing the package i should giver the access to users 
hello everyone i am trying to transfer the records to a new user. I need to transfer all the leads, Accounts, Contacts, Opportunity, Activity etc.. . Can you please share your expert advice step by step process . I am going to use data loader.

My plan is to update the lead first. Then All accounts owned by user A. Then account with contacts whose owner is User A. Then Account with Opportunities whose owner is User A. Then run report of all other opportunities whose owner is User A. Please let me know if this is the right approach or there is a faster way to do the same. I am allowed to use only data loader and want to test my skill hence need an ideal solution 
Dear All,

I am getting the below error when my process builder is trying to create a new record. Can you please help me to undersatnd why I am getting this error.

First I will expalin what is the logic behid the same so that I can understand the problem 

1) We use Zoom Info to push the leads to Salesforce. When the lead is pushed from Zoominfo the LeadSource values goes as Zoominfo. Which is not required as per the business logic. Hence I created a process builder to update the LeadSource field as List import and lead source detail( Custom Filed ) as ZoomInfo. When I created the process builder i chose the option Created and edited. The logic is if LeadSource = Zoominfo then update LeadSource = Listimport and Lead Source Detail as Zoominfo. 
2) Validation rule : There is a validation rule on the lead object. The objective is that once the lead source is updated then it cannot be changed. Below is the rule formula :
AND( 
ISCHANGED(LeadSource), 
NOT(ISBLANK(TEXT(PRIORVALUE(LeadSource))) 


&& 
$Profile.Name <> "System Administrator"

Now below is the error I am getting 


Error element myRule_1_A1 (FlowRecordUpdate).
The flow tried to update these records: null. This error occurred: FIELD_CUSTOM_VALIDATION_EXCEPTION: Lead Source cannot be edited once a value has been set.. You can look up ExceptionCode values in the SOAP API Developer Guide.

Flow Details
Flow API Name: Zoominfo_Lead_to_Campaign
Type: Record Change Process
Version: 4
Status: Active
Org: TrackTik (00D610000006k9b)

Flow Interview Details
Interview Label: Zoominfo_Lead_to_Campaign-4_InterviewLabel
Current User: Dominic O'Toole (005610000038BU6)
Start time: 29/04/2019 12:18 PM
Duration: 0 seconds

How the Interview Started
Dominic O'Toole (005610000038BU6) started the flow interview.
Some of this flow's variables were set when the interview started.
myVariable_old = null
myVariable_current = Lead (00Q4N00000Y5b95UAB)

ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!$Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = "29/04/2019 12:18 PM"

DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: 
{!formula_myRule_1} (true) Equals true

RECORD UPDATE: myRule_1_A1
Find all Lead records where:
Id Equals {!myVariable_current.Id} (00Q4N00000Y5b95UAB)
Update the records’ field values.
LeadSource = List Import
Lead_Source_Detail__c = Zoominfo
Result
Failed to update records that meet the filter criteria.

Error Occurred: The flow tried to update these records: null. This error occurred: FIELD_CUSTOM_VALIDATION_EXCEPTION: Lead Source cannot be edited once a value has been set.. You can look up ExceptionCode values in the SOAP API Developer Guide.


Salesforce Error ID: 1737613578-24183 (798020834)
ReplyForward
Dear All,

I am new to SFDC. I have been gudied that it is a best practicse to write an apex class and then call that class in a trigger. I want to udersatnd how we can use trigger.oldmap or trigger.newmap in an Apex class. Can anyone help me with an example or provide me a link 
 My previous problem is not resolved I have a Custom filed in accounts which is name as No of contacts now i have to write trigger after update which follows the logic of if I put no of contacts more than the present value then the difference should create a contact( for ex Old value of contact = 8 new value 10 then 2 new contacts should be created ) if ( Old valve of contact = 10 and new value = 8 then 2 contact should be deleted ) how can I achieve this. I wrote the below trigger but it is not working correctly ( if old was 12 and new value 10 it is giving me an exception error ) ( if old value 12 and new value is 13 it creates 1 extra contact but if i update again the new value to 12 all contact gets deleted)

Ideal i want the same no of contacts should be there in the contact related list as per the No.of contacts mentioned in the account custom filed value

trigger trigger17 on Account (after update) {
    for(Account a:trigger.new){
        if(trigger.oldmap.get(a.id).Number_of_contacts__c <a.Number_of_contacts__c){
            System.debug(a.Number_of_contacts__c- trigger.oldmap.get(a.id).Number_of_contacts__c);
            for(Decimal i=1;i<=(a.Number_of_contacts__c- trigger.oldmap.get(a.id).Number_of_contacts__c);i++){
                contact c = new contact();
                c.AccountId =a.Id;
                c.LastName = a.Name;
                Insert c;
            }
        }
        if(trigger.oldmap.get(a.id).Number_of_contacts__c >a.Number_of_contacts__c){
            List<Contact> con = [Select id,name,accountid from contact where accountid =: a.id];
            System.debug(con);
            Decimal Diff = trigger.oldmap.get(a.id).Number_of_contacts__c - a.Number_of_contacts__c;
            System.debug(Diff);
            For(Contact c : Con){
                for(Integer i = 1 ; i<= Diff; i++){
                    Delete c;
                }
            }
        }
    }
     }

I also want the reverse if an contact related to that particular ID is deleted then in the No of Contact filed it should reduce if any new contact created on the same account then the no of contact field should increase 
Hi I am not able to understand why I am not able to get the data from my wire service when I am puting the data in my serach field, when the search field is blank it do render and i can see the data , but when i put any data to search it doesnt react to that search key 

below is the code 
HTML 
<template>
    <lightning-card title="Product Search">
        <div class="slds-m-around_medium">
            <lightning-input name="enter-search" label="Search" type="search" onchange={handleSearch} is-loading={isSearching}></lightning-input><br/>
            <lightning-input name="NABTick" label="NAB Price List" type="checkbox" onchange={handleCheckbox} ></lightning-input><br/>
        <lightning-button label="Search" name="search" title="Search Products" onclick={findProductKey} variant="brand" ></lightning-button>&nbsp;&nbsp;&nbsp;
            <lightning-button label="Cancel" name="cancel" title="Cancel" onclick={handleCancle} ></lightning-button>
        
        </div>
        <div>
            This is the search key value ={searchKey}
            This is NAB Check list Value={NABcheckbox}
        </div>
        
        <template if:true={allProduct.data}>
            <div>
                <template for:each={allProduct.data} for:item=product>
                    This is the prodcut Id :{product.Id}
                  <c-product-search-result-wired key={product.Id} product={product}></c-product-search-result-wired>
                </template>
            </div>
        </template>
    </lightning-card>
    
</template>
Vchild component 
<template>
    <div class="slds-p-around_medium lgc-bg" key={product.Id}>
        <ul class="slds-has-dividers_bottom-space">
            <li class="slds-item">
                <lightning-tile label={product.Name}>
                    <ul class="slds-list_horizontal slds-has-dividers_right">
                        <li class="slds-item">Product Code: {product.ProductCode}</li>
                        <li class="slds-item">Eng Status: {product.Eng_Status__c}</li>
                        <li class="slds-item">Dark Knight</li>
                        <li class="slds-item">Dark Knight</li>
                    </ul>
                </lightning-tile>
            </li>
        </ul>
        </div>     
</template>

Parent JS
import { LightningElement,track,wire } from 'lwc';
import getProducts from '@salesforce/apex/productSearch.getProducts';

const DELAY = 300;
export default class ProductSearchWired extends LightningElement {
    @track searchKey='';
    @track NABcheckbox= false;
    @track allProduct=[];
    
    
    @wire(getProducts,{productSearchKey:'$searchKey'})
    products({data,error}){
        if(data){
            this.allProduct = data;
        }
    }

    handleSearch(event){
        window.clearTimeout(this.delayTimeout);
        const searchKey = event.target.value;
        // eslint-disable-next-line @lwc/lwc/no-async-operation
        this.delayTimeout = setTimeout(() => {
            this.searchKey = searchKey;
        }, DELAY);
    }

    handleCheckbox(){
        this.NABcheckbox = true;
    }

    get isSearching(){
        if(this.allProduct){
            return false;
        } else {
            return true;
        }
    }
}

Child JS File
import { LightningElement,api } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';

export default class ProductSearchResultWired extends NavigationMixin(LightningElement) {
    @api product;

    navigateToProduct(){
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                actionName: "view",
                recordId: this.product.Id,
                objectApiName: "Product2"
            }
        });

    }
}

Apex Class Controller
public static List<Product2> getProducts(String productSeachKey)
    {
          if( String.isNotEmpty(productSeachKey))
        {
            return [SELECT Id,Name,ProductCode,Eng_Status__c,Quotable__c,USD_Price__c FROM Product2 WHERE IsActive= true AND Eng_Status__c IN ('Production','Procurement','Prototype','Hold')
                    AND Field_Replaceable_Part__c = false AND Base_Price_List_Item__c != null AND (Name LIKE : '%'+productSeachKey+'%' OR ProductCode LIKE: '%'+productSeachKey+'%')
                    ORDER BY SBQQ__SortOrder__c ASC NULLS LAST];
        } else 
        { 
          return [SELECT Id,Name,ProductCode,Eng_Status__c,Quotable__c,USD_Price__c FROM Product2 WHERE IsActive= true AND Eng_Status__c IN ('Production','Procurement','Prototype','Hold')
          AND Field_Replaceable_Part__c = false AND Base_Price_List_Item__c != null ORDER BY SBQQ__SortOrder__c ASC NULLS LAST];
        }

    }
    
}

When SearchKey is blank the component renders and show all the products
Hi All,

I have a custom object User Region which has a field called RSM Number and RSM__c which is the owner of that region. I want this field to be updated in Opportunity split whose Split owner is unigue and matches RSM__c . Opportunity split  is having a look up relationship with User region object. This is the tirgger I have written. But I am stuck after I have got All the USER region which have same Account region ID and RSM__C is = Split Owner ID. Because there is a ask that id Split Owner is hared between two User region then it should not update only Split owner which are not shared their RSM number should get updated through this trigger. 

Can you all please help me how to write this trigger 
Sample Code : 
Trigger RSMnumberUpdate on OpportunitySplit (before insert,before update){
if(Trigger.isbefore && (Trigger.isinsert || Trigger.isupdate)){
List<id> SplitownerID = new List<id> ();
List<String> OppAccountRegionID = new List<String>();
    For(OpportunitySplit Opsp : Trigger.new){
          SplitownerID.add(Opsp.Splitowner);
          OppAccountRegionID.add(Opsp.AccountRegionID);
}

List<ID> AllUserRegionsID = [SELECT id FROM UserRegion__c WHERE RSM__c IN : SplitownerID AND Parent_Region__c IN : OppAccountRegionID];
     
        

}
}
 
hello everyone i am trying to transfer the records to a new user. I need to transfer all the leads, Accounts, Contacts, Opportunity, Activity etc.. . Can you please share your expert advice step by step process . I am going to use data loader.

My plan is to update the lead first. Then All accounts owned by user A. Then account with contacts whose owner is User A. Then Account with Opportunities whose owner is User A. Then run report of all other opportunities whose owner is User A. Please let me know if this is the right approach or there is a faster way to do the same. I am allowed to use only data loader and want to test my skill hence need an ideal solution 
Dear All,

I am getting the below error when my process builder is trying to create a new record. Can you please help me to undersatnd why I am getting this error.

First I will expalin what is the logic behid the same so that I can understand the problem 

1) We use Zoom Info to push the leads to Salesforce. When the lead is pushed from Zoominfo the LeadSource values goes as Zoominfo. Which is not required as per the business logic. Hence I created a process builder to update the LeadSource field as List import and lead source detail( Custom Filed ) as ZoomInfo. When I created the process builder i chose the option Created and edited. The logic is if LeadSource = Zoominfo then update LeadSource = Listimport and Lead Source Detail as Zoominfo. 
2) Validation rule : There is a validation rule on the lead object. The objective is that once the lead source is updated then it cannot be changed. Below is the rule formula :
AND( 
ISCHANGED(LeadSource), 
NOT(ISBLANK(TEXT(PRIORVALUE(LeadSource))) 


&& 
$Profile.Name <> "System Administrator"

Now below is the error I am getting 


Error element myRule_1_A1 (FlowRecordUpdate).
The flow tried to update these records: null. This error occurred: FIELD_CUSTOM_VALIDATION_EXCEPTION: Lead Source cannot be edited once a value has been set.. You can look up ExceptionCode values in the SOAP API Developer Guide.

Flow Details
Flow API Name: Zoominfo_Lead_to_Campaign
Type: Record Change Process
Version: 4
Status: Active
Org: TrackTik (00D610000006k9b)

Flow Interview Details
Interview Label: Zoominfo_Lead_to_Campaign-4_InterviewLabel
Current User: Dominic O'Toole (005610000038BU6)
Start time: 29/04/2019 12:18 PM
Duration: 0 seconds

How the Interview Started
Dominic O'Toole (005610000038BU6) started the flow interview.
Some of this flow's variables were set when the interview started.
myVariable_old = null
myVariable_current = Lead (00Q4N00000Y5b95UAB)

ASSIGNMENT: myVariable_waitStartTimeAssignment
{!myVariable_waitStartTimeVariable} Equals {!$Flow.CurrentDateTime}
Result
{!myVariable_waitStartTimeVariable} = "29/04/2019 12:18 PM"

DECISION: myDecision
Executed this outcome: myRule_1
Outcome conditions: 
{!formula_myRule_1} (true) Equals true

RECORD UPDATE: myRule_1_A1
Find all Lead records where:
Id Equals {!myVariable_current.Id} (00Q4N00000Y5b95UAB)
Update the records’ field values.
LeadSource = List Import
Lead_Source_Detail__c = Zoominfo
Result
Failed to update records that meet the filter criteria.

Error Occurred: The flow tried to update these records: null. This error occurred: FIELD_CUSTOM_VALIDATION_EXCEPTION: Lead Source cannot be edited once a value has been set.. You can look up ExceptionCode values in the SOAP API Developer Guide.


Salesforce Error ID: 1737613578-24183 (798020834)
ReplyForward
Dear All,

I am new to SFDC. I have been gudied that it is a best practicse to write an apex class and then call that class in a trigger. I want to udersatnd how we can use trigger.oldmap or trigger.newmap in an Apex class. Can anyone help me with an example or provide me a link 
 My previous problem is not resolved I have a Custom filed in accounts which is name as No of contacts now i have to write trigger after update which follows the logic of if I put no of contacts more than the present value then the difference should create a contact( for ex Old value of contact = 8 new value 10 then 2 new contacts should be created ) if ( Old valve of contact = 10 and new value = 8 then 2 contact should be deleted ) how can I achieve this. I wrote the below trigger but it is not working correctly ( if old was 12 and new value 10 it is giving me an exception error ) ( if old value 12 and new value is 13 it creates 1 extra contact but if i update again the new value to 12 all contact gets deleted)

Ideal i want the same no of contacts should be there in the contact related list as per the No.of contacts mentioned in the account custom filed value

trigger trigger17 on Account (after update) {
    for(Account a:trigger.new){
        if(trigger.oldmap.get(a.id).Number_of_contacts__c <a.Number_of_contacts__c){
            System.debug(a.Number_of_contacts__c- trigger.oldmap.get(a.id).Number_of_contacts__c);
            for(Decimal i=1;i<=(a.Number_of_contacts__c- trigger.oldmap.get(a.id).Number_of_contacts__c);i++){
                contact c = new contact();
                c.AccountId =a.Id;
                c.LastName = a.Name;
                Insert c;
            }
        }
        if(trigger.oldmap.get(a.id).Number_of_contacts__c >a.Number_of_contacts__c){
            List<Contact> con = [Select id,name,accountid from contact where accountid =: a.id];
            System.debug(con);
            Decimal Diff = trigger.oldmap.get(a.id).Number_of_contacts__c - a.Number_of_contacts__c;
            System.debug(Diff);
            For(Contact c : Con){
                for(Integer i = 1 ; i<= Diff; i++){
                    Delete c;
                }
            }
        }
    }
     }

I also want the reverse if an contact related to that particular ID is deleted then in the No of Contact filed it should reduce if any new contact created on the same account then the no of contact field should increase