• Dastagiri Basha
  • NEWBIE
  • 30 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 3
    Replies

Hi all,

 please assist with how to Disable the "Transfer account owner's closed opportunities" option while changing the Account Owner.

while changing the Account it's closed opportunities owner also changing, i want to disable this option.

please give an idea to disable this option. 

User-added imageThanks.

IF( [genesis__Applications__c].Age_Of_Business__c = null, 
TEXT( FLOOR((TODAY() -  [genesis__Applications__c].genesis__Account__r.Incorporation_Date__c)/365) ) & 'y ' & TEXT(FLOOR((MOD((TODAY() -  [genesis__Applications__c].genesis__Account__r.Incorporation_Date__c),365))/30)) & 'm'
, [genesis__Applications__c].Age_Of_Business__c )
Hi developer's, i have a requirement like in the case object have RT "payment's".and status "close Completed"
if the case status updated to  close completed for that perticular record type, i need to lock other case fields(should not be editable) how can i achive this one?
I have written an validation rule but it's not working can any one help me.
AND(ISCHANGED(LeadSource), OR(ISPICKVAL(PRIORVALUE(LeadSource),'Web'),
ISPICKVAL(PRIORVALUE(LeadSource),'Other' ) ),NOT(
$Profile.Id = '%2F00e5g000002NiSg'))

Apex Class::

public static void GetIBISDataFromTrigger(map<id,Account> newMap, map<id,Account> oldMap){
        loan__Trigger_Parameters__c trigParam = loan__Trigger_Parameters__c.getInstance();
        genesis__Org_Parameters__c orgParam = genesis__Org_Parameters__c.getInstance();
        IF(orgParam.genesis__Disable_Triggers__c == False && trigParam.GetIBISDataTrigger__c == False){
            Set<Id> accountIds = new Set<Id>();
            for(Account acc : newMap.values()){
                if(acc.IBIS_Specialised_Industry__c != OldMap.get(acc.Id).IBIS_Specialised_Industry__c ||
                   acc.IBIS_Sub_Industry__c != OldMap.get(acc.Id).IBIS_Sub_Industry__c || (acc.IBIS_Industry__c=='FAST-TRACK' && acc.IBIS_Industry__c!= OldMap.get(acc.Id).IBIS_Industry__c)){
                       
                       //Store Account Ids
                       accountIds.add(acc.Id);
                   }
            }
            
            IF(accountIds.size() > 0)
            {
                //get the IBIS Data
                Map<String,IBIS_Data__c> CodeMap =  new Map<String,IBIS_Data__c>();
                List<IBIS_Data__c> conList = [Select id,
                                              Name,
                                              Code_Data__c,
                                              IBIS_Sub_Industry__c,
                                              IBIS_Specialised_Industry__c,
                                              IBIS_Industry_Type__c 
                                              From IBIS_Data__c order by createdDate DESC];
                for(IBIS_Data__c ibisData : conList){
                    
                    IF(ibisData.IBIS_Specialised_Industry__c == null){ 
                        if(!CodeMap.Containskey(ibisData.IBIS_Sub_Industry__c)){
                            CodeMap.put(ibisData.IBIS_Sub_Industry__c,ibisData);
                        }
                    }else{
                        if(!CodeMap.Containskey(ibisData.IBIS_Specialised_Industry__c)){
                            CodeMap.put(ibisData.IBIS_Specialised_Industry__c,ibisData);
                        }
                    }
                }
                
                for(ID accId : accountIds){
                    
                    if(newMap.get(accId).IBIS_Specialised_Industry__c != null){     
                        if(CodeMap.ContainsKey(newMap.get(accId).IBIS_Specialised_Industry__c)){
                            newMap.get(accId).IBIS_Code__c = CodeMap.get(newMap.get(accId).IBIS_Specialised_Industry__c).Code_Data__c;
                            newMap.get(accId).IBIS_Industry_Type__c = CodeMap.get(newMap.get(accId).IBIS_Specialised_Industry__c).IBIS_Industry_Type__c;
                            
                        }else{
                            newMap.get(accId).IBIS_Code__c = '';
                        }
                    }else if(newMap.get(accId).IBIS_Sub_Industry__c != null){
                        if(CodeMap.ContainsKey(newMap.get(accId).IBIS_Sub_Industry__c)){
                            newMap.get(accId).IBIS_Code__c = CodeMap.get(newMap.get(accId).IBIS_Sub_Industry__c).Code_Data__c;
                            newMap.get(accId).IBIS_Industry_Type__c = CodeMap.get(newMap.get(accId).IBIS_Sub_Industry__c).IBIS_Industry_Type__c;
                            
                        }else{
                            newMap.get(accId).IBIS_Code__c = '';
                        }
                    }
                    else if(newMap.get(accId).IBIS_Industry__c=='FAST-TRACK'){
                        if(CodeMap.ContainsKey(newMap.get(accId).IBIS_Industry__c)){
                            newMap.get(accId).IBIS_Code__c = CodeMap.get(newMap.get(accId).IBIS_Industry__c).Code_Data__c;
                            newMap.get(accId).IBIS_Industry_Type__c = CodeMap.get(newMap.get(accId).IBIS_Industry__c).IBIS_Industry_Type__c;
                            
                        }else{
                            newMap.get(accId).IBIS_Code__c = '';
                        }
                    }
                    else{
                        newMap.get(accId).IBIS_Code__c = '';
                    }
                }
            }
        }
    }
}

Test Class::

static testMethod void GetIBISDataFromTriggertest(){ 
         Test.startTest();
        
        loan__Trigger_Parameters__c trigParam = new loan__Trigger_Parameters__c();
        genesis__Org_Parameters__c orgParam =  new genesis__Org_Parameters__c();
        orgParam.genesis__Disable_Triggers__c = False;
        trigParam.GetIBISDataTrigger__c = False;
        update orgParam;
        update trigParam;
        List<Account> acclist = new List<Account>();
        Account acc1 = new Account(Name = 'Test with Sole Proprietor', Company_Structure__c = 'Sole Proprietor',  ABN_Status__c = 'Active', IBIS_Specialised_Industry__c ='Hydroponic Crop Farming');
        insert acc1; 
        if(acc1.id != null){
            for(Account acc : [select id, Name, Company_Structure__c, ABN_Status__c, IBIS_Specialised_Industry__c from Account where Name='Test with Sole Proprietor' limit 1]){
                acc.IBIS_Specialised_Industry__c='Coal Seam Gas Extraction';
                acclist.add(acc);
            } 
            update acclist;
        }
      test.stopTest();  
    }
    

Apex Code::
public class newPriceBookEntry {
@AuraEnabled
    public static List<Pricebook2> getAllPricebooks() {
      
        return [SELECT Id, Name FROM Pricebook2];
    }
    @AuraEnabled
    public static List<PricebookEntry> getAllPriceBookEntries(string recordId){
  List<PricebookEntry> PentryList= [select id, Name, Product2.Name, UnitPrice from PricebookEntry Where Pricebook2.Name =:recordId];
        return PentryList;
    }        
}

Component::  
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" controller="newPriceBookEntry" >
    <aura:attribute name="PriceBooks" type="List" default="[]"/>
    <aura:attribute name="PriceBooksEntries" type="PricebookEntry[]" />
    <!-- <aura:attribute name="recordId" type="Id" />  -->
    
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <div class="slds-m-around_xx-large">
        <lightning:combobox name="general" label="Price Books" placeholder="Select an PriceBook" 
                            options="{!v.PriceBooks}" onchange="{!c.handleChange}"/>  
    </div>   
    <table class="slds-table slds-table_bordered slds-table_cell-buffer" >
        <thead>
            <tr class="slds-text-title_caps">
                <th scope="col">
                    <div class="slds-truncate"  title="S.no">S.no</div>
                </th>
                <th scope="col">
                    <div class="slds-truncate" title="Employee Name">PriceBookEntryName</div>
                </th>
                <th scope="col">
                    <div class="slds-truncate" title="Basic Salary">ProductName</div>
                </th>
                <th scope="col">
                    <div class="slds-truncate" title="Attendance">UnitPrice</div>
                </th>
            </tr>
        </thead>
        <tbody> 
            <aura:iteration items="{!v.PriceBooksEntries}" var="epl" indexVar="count">
                <tr>
                    <td>
                        <div class="slds-truncate">{!count + 1}</div>
                    </td>
                    <td>
                        <div class="slds-truncate"><lightning:input type="text" value="{!epl.Name}"  /></div>
                    </td>
                    <td>
                        <div class="slds-truncate"><lightning:input type="text" value="{!epl.Product2.Name}" /></div>
                    </td>
                    <td>
                        <div class="slds-truncate"><lightning:input type="number" value="{!epl.UnitPrice}" /></div>
                    </td>
                    <td>
                        <lightning:button onclick="{!c.HandleSave}" variant="brand" label="Save" />
                    </td>
                </tr>
            </aura:iteration>
        </tbody> 
    </table> 
    
</aura:component>

Controller:: 

({
    init : function(cmp, event, helper) {
        var action = cmp.get("c.getAllPricebooks");
        var options = [];        
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {                
                var arr = response.getReturnValue() ;
                arr.forEach(function(element) {
                    options.push({ value: element.Name, label: element.Name });
                });                
                cmp.set("v.PriceBooks", options);                
            }
            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);
    },
    handleChange: function (cmp, event) {
        // This will contain the string of the "value" attribute of the selected option
       var action = cmp.get("c.getAllPriceBookEntries"); 
        var selectedOptionValue = event.getParam("value");
        alert(selectedOptionValue);
        action.setParams({recordId: selectedOptionValue});                  
               action.setCallback(this,function(response){
            var state = response.getState();
            alert(state);
            if (state === "SUCCESS"){
                var methodResponse = response.getReturnValue();
                alert(methodResponse);
                component.set('v.PriceBooksEntries',methodResponse);
            }else if (state === "INCOMPLETE") {
                alert('Response is Incompleted');
            }else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        alert("Error message: " + 
                              errors[0].message);
                    }
                } else {
                    alert("Unknown error");
                }
            }
        });
         $A.enqueueAction(action);
    }
})
 

Controller apex:
public class newPriceBookEntry {
@AuraEnabled
    public static List<Pricebook2> getAllPricebooks() {
     
        return [SELECT Id, Name FROM Pricebook2];
    }
}

Component::
<aura:attribute name="PriceBooks" type="List" default="[]"/>

    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
 <div class="slds-m-around_xx-large">
    <lightning:combobox name="general" label="Many Options" placeholder="Select an PriceBook" 
                        options="{!v.PriceBooks }" onchange="{! c.handleChange }"/>
</div>

Controller:JS::

init : function(component, event, helper) {
        var items = component.get("c.getAllPricebooks");
       var Options = [{ value: "v.PriceBooks", label: items }];
        component.set("v.PriceBooks", Options);
    }, 

Batch Class:::

global class BatchclasstoSendMail implements Database.Batchable <Sobject> {

     global Database.QueryLocator start(Database.BatchableContext bc){

     string query = 'select name,Email, Birthdate from Contact where Email != null';
     system.debug('******'+query);
     return Database.getQueryLocator(query);
     }

     global  void execute(Database.BatchableContext bc, List<Contact> lst){
  list<Messaging.SingleEmailMessage> mail = new list<Messaging.SingleEmailMessage>();
          for(Contact c: lst){
            Messaging.SingleEmailMessage objEmail = new Messaging.SingleEmailMessage();
            list<string> toadd=new list<string>();
            toadd.add(c.Email);
            system.debug('*****'+c.Email);
            objEmail.setToAddresses(toadd);
            system.debug('*****'+toadd);
            objEmail.setsubject('Your contact was registered successfully');
            objEmail.setplaintextbody('you are most valuable person we will contact you  as soon as possible');
            mail.add(objEmail); 
              system.debug('*****AllMails'+objEmail);
          }           
   Messaging.SendEmailResult[]  result =Messaging.sendEmail(mail);
         
      } 

     global void finish(Database.BatchableContext BC){
     System.debug(BC);
       
     }
   

Scheduled Class::

global class ScheduledBatchToSendMail implements schedulable {
global  void execute(SchedulableContext sc){
        BatchclasstoSendMail myBatchClass = new BatchclasstoSendMail();
            database.executeBatch(myBatchClass);
    }
}

Excecution scheduled class form DevConsole:::

ScheduledBatchToSendMail m = new ScheduledBatchToSendMail();
String sch = '0 30 18 ? * WED *';
String jobID = system.schedule('Merge Job', sch, m);
 
This is my apex Class
public class employeeDateSearch {
 
    @AuraEnabled
    public static List<Employee_Payroll__c> getEmployeeData(string monthYear){
        List<Employee_Payroll__c> returnList = new List<Employee_Payroll__c>();
        Set<Id> empIds = new Set<Id>();
     List<Employee_Payroll__c> empl = [SELECT Id, Name__c, Attendence__c,Employee_Name__c, Allowances__c, Holidays__c, Advance__c, Visa__c, Iqama__c, Insurance__c, Ticket__c, Others__c, Start_Date__c, End_Date__c, Ot__c, Sick_Leave__c, Basic_Salary__c FROM Employee_Payroll__c WHERE Month_and_year__c=:monthYear];
        if(empl.size() >0){
         
            for(Employee_Payroll__c epl : empl){
                
                empIds.add(epl.Name__c);
                returnList.add(epl);
            }
        }
        
        List<Employee__c> empList;
        AggregateResult[] atteList;
        AggregateResult[] LeaveList;
        if(empIds.size() >0){
            empList = [SELECT Id,Name,Basic_Salary__c,Employee_ID__c FROM Employee__c WHERE Not (Id IN :empIds)];
            atteList  = [SELECT Count(Id)cnt,Employee__c FROM Attendance__c WHERE Month_and_year__c=:monthYear AND (NOT (Employee__c IN : empIds))  GROUP BY Employee__c];
            LeaveList  = [SELECT SUM(No_of_Days__c)noL,Employee__c FROM Leave__c WHERE Month_and_year__c=:monthYear AND (NOT (Employee__c IN : empIds)) AND (Approval_Status__c ='Accept' OR Approval_Status__c ='Edit & Accept')  GROUP BY Employee__c];
        }else{
            empList = [SELECT Id,Name,Basic_Salary__c,Employee_ID__c FROM Employee__c];
            atteList  = [SELECT Count(Id)cnt,Employee__c FROM Attendance__c WHERE Month_and_year__c=:monthYear GROUP BY Employee__c];
             LeaveList  = [SELECT SUM(No_of_Days__c)noL,Employee__c FROM Leave__c WHERE Month_and_year__c=:monthYear AND (Approval_Status__c ='Accept' OR Approval_Status__c ='Edit & Accept')  GROUP BY Employee__c];
        }
       
            for(Employee__c est : empList){
                Employee_Payroll__c epll = new Employee_Payroll__c();
                epll.Name__c = est.Id;
                epll.Basic_Salary__c = est.Basic_Salary__c;
                epll.Employee_Name__c = est.Name;
                for(AggregateResult agat : atteList){
                    if((id)agat.get('Employee__c') == est.Id){
                        epll.Attendence__c = (decimal)agat.get('cnt');
                    }
                }
                 for(AggregateResult agls : LeaveList){
                    if((id)agls.get('Employee__c') == est.Id){
                        epll.Sick_Leave__c = (decimal)agls.get('noL');
                    }
                }
                returnList.add(epll);
                
            }
        
        return returnList;
        
    }
    @AuraEnabled
    public static List<Employee_Payroll__c> savePayroll( List<Employee_Payroll__c> emplList, string monthName, string yearName){
        List<Employee_Payroll__c> updateList = new List<Employee_Payroll__c>();
        for(Employee_Payroll__c empl : emplList){
            Employee_Payroll__c epl = new Employee_Payroll__c();
            if(empl.Id !=null ){
                epl.Id = empl.Id;
            }
            epl.Month__c = monthName;
            epl.Year__c = yearName;
            epl.Name__c = empl.Name__c;
            epl.Basic_Salary__c = empl.Basic_Salary__c;
            epl.Ot__c = empl.Ot__c;
            epl.Attendence__c = empl.Attendence__c;
            epl.Sick_Leave__c = empl.Sick_Leave__c;
            epl.Advance__c = empl.Advance__c;
            epl.Visa__c = empl.Visa__c;
            epl.Iqama__c = empl.Iqama__c;
            epl.Insurance__c = empl.Insurance__c;
             epl.Ticket__c = empl.Ticket__c;
            updateList.add(epl);
        }
        upsert updateList;
        
        return updateList;
    }

This is my Test Class::

@isTest
public class employeeDateSearchTest {
    public static testMethod void getEmployeeDataTest(){
        Test.startTest();
        Set<Id> empIds = new Set<Id>();
        List<Employee_Payroll__c> UpPayroll = new List<Employee_Payroll__c>();
        Employee_Payroll__c empPayroll = new Employee_Payroll__c();
        empPayroll.Name__c = 'a0h1s000001uiHZAAY';        
        empPayroll.Basic_Salary__c = 2000;
        empPayroll.Ot__c = 2;
        empPayroll.Attendence__c = 23;
        empPayroll.Sick_Leave__c = 2;
        empPayroll.Advance__c = 200;
        empPayroll.Visa__c = 250;
        empPayroll.Iqama__c = 300;
        empPayroll.Insurance__c = 100;
        empPayroll.Ticket__c = 200;
        empPayroll.Holidays__c =4;
        empPayroll.Allowances__c=400;
        empPayroll.Others__c= 200;
        empIds.add(empPayroll.Name__c);
        //empPayroll.Month_and_year__c='' ;
        UpPayroll.add(empPayroll);
        insert UpPayroll;              
        employeeDateSearch.getEmployeeData('system.today');
        test.stopTest();
    }
    
    
    public static testMethod void  SavePayrollTest(){  
        test.startTest();
        List<Employee_Payroll__c> updList = new List<Employee_Payroll__c>();
        Employee_Payroll__c emproll = new Employee_Payroll__c();  
        // emproll.id = empList.id;
        // emproll.Month__c = 'November';
        // emproll.Year__c = '2021';
        emproll.Name__c = 'a0h1s000001uiHZAAY';
        emproll.Basic_Salary__c = 2000;
        emproll.Ot__c = 2;
        emproll.Attendence__c = 23;
        emproll.Sick_Leave__c = 2;
        emproll.Advance__c = 200;
        emproll.Visa__c = 250;
        emproll.Iqama__c = 300;
        emproll.Insurance__c = 100;
        emproll.Ticket__c = 200;       
        updList.add(emproll);  
        upsert updList; 
        
        employeeDateSearch.savePayroll( updList, 'November', '2021');
        test.stopTest();
    }   
    
}

With this Test class i have coverd 60% and I am a Begginer Can any one help me with the Test Class.

    
List<Employee__c> empList;
        AggregateResult[] atteList;
        AggregateResult[] LeaveList;
        if(empIds.size() >0){
            empList = [SELECT Id,Name,Basic_Salary__c,Employee_ID__c FROM Employee__c WHERE Not (Id IN :empIds)];
            atteList  = [SELECT Count(Id)cnt,Employee__c FROM Attendance__c WHERE Month_and_year__c=:monthYear AND (NOT (Employee__c IN : empIds))  GROUP BY Employee__c];
            LeaveList  = [SELECT SUM(No_of_Days__c)noL,Employee__c FROM Leave__c WHERE Month_and_year__c=:monthYear AND (NOT (Employee__c IN : empIds)) AND (Approval_Status__c ='Accept' OR Approval_Status__c ='Edit & Accept')  GROUP BY Employee__c];
        }
 
List<Employee__c> empList;
        AggregateResult[] atteList;
        AggregateResult[] LeaveList;
        if(empIds.size() >0){
            empList = [SELECT Id,Name,Basic_Salary__c,Employee_ID__c FROM Employee__c WHERE Not (Id IN :empIds)];
            atteList  = [SELECT Count(Id)cnt,Employee__c FROM Attendance__c WHERE Month_and_year__c=:monthYear AND (NOT (Employee__c IN : empIds))  GROUP BY Employee__c];
            LeaveList  = [SELECT SUM(No_of_Days__c)noL,Employee__c FROM Leave__c WHERE Month_and_year__c=:monthYear AND (NOT (Employee__c IN : empIds)) AND (Approval_Status__c ='Accept' OR Approval_Status__c ='Edit & Accept')  GROUP BY Employee__c];
        }__c WHERE Not (Id IN :empIds)];
IF( [genesis__Applications__c].Age_Of_Business__c = null, 
TEXT( FLOOR((TODAY() -  [genesis__Applications__c].genesis__Account__r.Incorporation_Date__c)/365) ) & 'y ' & TEXT(FLOOR((MOD((TODAY() -  [genesis__Applications__c].genesis__Account__r.Incorporation_Date__c),365))/30)) & 'm'
, [genesis__Applications__c].Age_Of_Business__c )

Controller apex:
public class newPriceBookEntry {
@AuraEnabled
    public static List<Pricebook2> getAllPricebooks() {
     
        return [SELECT Id, Name FROM Pricebook2];
    }
}

Component::
<aura:attribute name="PriceBooks" type="List" default="[]"/>

    <aura:handler name="init" value="{! this }" action="{! c.init }"/>
 <div class="slds-m-around_xx-large">
    <lightning:combobox name="general" label="Many Options" placeholder="Select an PriceBook" 
                        options="{!v.PriceBooks }" onchange="{! c.handleChange }"/>
</div>

Controller:JS::

init : function(component, event, helper) {
        var items = component.get("c.getAllPricebooks");
       var Options = [{ value: "v.PriceBooks", label: items }];
        component.set("v.PriceBooks", Options);
    }, 

Batch Class:::

global class BatchclasstoSendMail implements Database.Batchable <Sobject> {

     global Database.QueryLocator start(Database.BatchableContext bc){

     string query = 'select name,Email, Birthdate from Contact where Email != null';
     system.debug('******'+query);
     return Database.getQueryLocator(query);
     }

     global  void execute(Database.BatchableContext bc, List<Contact> lst){
  list<Messaging.SingleEmailMessage> mail = new list<Messaging.SingleEmailMessage>();
          for(Contact c: lst){
            Messaging.SingleEmailMessage objEmail = new Messaging.SingleEmailMessage();
            list<string> toadd=new list<string>();
            toadd.add(c.Email);
            system.debug('*****'+c.Email);
            objEmail.setToAddresses(toadd);
            system.debug('*****'+toadd);
            objEmail.setsubject('Your contact was registered successfully');
            objEmail.setplaintextbody('you are most valuable person we will contact you  as soon as possible');
            mail.add(objEmail); 
              system.debug('*****AllMails'+objEmail);
          }           
   Messaging.SendEmailResult[]  result =Messaging.sendEmail(mail);
         
      } 

     global void finish(Database.BatchableContext BC){
     System.debug(BC);
       
     }
   

Scheduled Class::

global class ScheduledBatchToSendMail implements schedulable {
global  void execute(SchedulableContext sc){
        BatchclasstoSendMail myBatchClass = new BatchclasstoSendMail();
            database.executeBatch(myBatchClass);
    }
}

Excecution scheduled class form DevConsole:::

ScheduledBatchToSendMail m = new ScheduledBatchToSendMail();
String sch = '0 30 18 ? * WED *';
String jobID = system.schedule('Merge Job', sch, m);