• salesforce sfdx
  • NEWBIE
  • 55 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 44
    Questions
  • 27
    Replies
1. Account (Standard object).
2. LoanCustomer__c(Custom Object with name, Account id (custom lookup).

Requirement:
 1.Need to add the Create Customers button on the LoanCustomer__c record page.

2. Click on the Button to display the Account records with checkboxes  with the record type Personal Loan with pagination.

3. After selecting the desired Account records and clicking on the Create Customer button i need to create the Records with LoanCustomer__C with name as Account name, phone as account phone, accountid as account id etc.

Finally After binding to display the table .

please suggest any links or comments to do with aura component.

Thanks  
Prathusya Reddy 
 
Custom Object: Product__c
Custom Fields: Name, Quantity__c, Address__c, EmiNumber__C.

If User Creates a record :

Name ='Samsung Pro Max';
Quantity=10;
Address='xxxx'.



After Save
Here i need to Create same product with ten Records.
Say...!

Name ='Samsung Pro Max';
Quantity =1;
Address='xxxx'.

Name ='Samsung Pro Max';
Quantity =1;
Address='xxxx'.

Name ='Samsung Pro Max';
Quantity =1;
Address='xxxx'.

------------->so on 10 times
including the first record  to be updated as 1
so that i can track each item seperately .
Can this action can be acheived using the flow.


Thanks 
Prathushya Reddy.




 
@RestResource (urlMapping='/DeviceObjserviceendpoint/*')
global class DeviceObj_Rest_Service {
  
    @HttpGet
    global static void doGetDevice() {
        String result = '';
        try{
        Map<string, string> paramsMap = RestContext.request.params;
      if(paramsMap!=null){
        String serialNo = paramsMap.get('serialNo');
        String lastName = paramsMap.get('lastName');
        String dateOfBirth = paramsMap.get('dateOfBirth');  
                 Date dob = date.parse(dateOfBirth);
            
       
        //Date dob = date.parse(dateOfBirth);
        List<Device__C> Devs = [Select Id, Name,Dob__c,Patient_Last_Name__c from Device__C 
                                where Name = :SerialNo and  
                                Patient_Last_Name__c =:lastName and 
                                DOB__c = :dob
                                LIMIT 1];

         if( Devs.size() > 0 ) {
             Device__C Dev = Devs[0];
            Map<String,String> resultMap = new Map<String,String> {
                'Message'  => 'Device found Sucessfully',
                'DeviceId' => Dev.Id,
                'SerialNo' => Dev.Name,
                'DateOfBirth' => string.valueof(Dev.Dob__c),
                 'lastname' =>Dev.Patient_Last_Name__c
            };
           
          result = JSON.serialize( resultMap );
       
         }
        else {
            result = 'Device with SerialNo :' + SerialNo + ' not found!';
        }
        }
        }catch(Exception ex){
            result= ex.getMessage();
        }
        RestContext.response.addHeader('Content-Type','application/json');
        RestContext.response.responseBody = Blob.valueOf(result);
    
         }
    
}

My Test Class:
@isTest
private class DeviceObj_Rest_Service_Test {
    
    static testMethod void testDoGetDevice() {
         Id stExam = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Patient').getRecordTypeId();
         system.debug(stExam);
         
         Account acc = new Account(FirstName = 'Test', LastName = 'Test22', PersonEmail = 'testaccount@test.com', RecordTypeId = stExam);
         insert acc;  
            
       
        // create a new Device record
        Device__c device = new Device__c(Name = '1234567890', type__c='Test',Patient__c= acc.id);
        insert device;
        
        // test a valid GET request
        RestRequest request = new RestRequest();
        request.requestURI = '/services/apexrest/DeviceObjserviceendpoint';
        request.addParameter('serialNo', device.Name);
        request.addParameter('lastName', device.Patient_Last_Name__c);
        request.addParameter('dateOfBirth', String.valueOf(device.DOB__c));
        RestContext.request = request;
        
        Test.startTest();
        DeviceObj_Rest_Service.doGetDevice();
        Test.stopTest();
        
        RestResponse response = RestContext.response;
      
    }
    
}

Its getting failed due to some issues , please provide some tips or any links to refer .

Thanks
Prathusha Reddy.
Assignment: Owner is a variable with  allow the multiple values.
  
{!owners} Add {!$Record.Diabetes_Specialist__r.Id}
{!owners} Add {!$Record.Sales_Specialist__r.Id}
Result
{!owners} = "[,]"
{!owners} ([,]) Does not equal null
All conditions must be true (AND)

Requirement is:
An Decision Element was added need to check if null or blank or empty values go to default out come else enter into the block.

Criteria:

i had added isnull equals
False, even though its entering in the block..

If  owners value is "[,]"  //how to check value using the isblank or isempty or is null.

Thanks
public class LeadTriggerHandler {
 //This method is called before Inserting.
 public void BeforeInsertMethod(List<Lead> LeadsRec){
       List<Lead> Leadlist = New List<Lead>();  
        //collection of the data in trigger.new
    for(Lead ld:LeadsRec){
        
        if (!ld.IsConverted){ //checking it was converted or Not
        If(ld.Referral__c != null){
           List<Account> Accountlist =[select Id,name,BillingPostalCode from Account where Id=:ld.Referral__c];
            
            If(!Accountlist.isEmpty()){
         If(Accountlist[0].BillingPostalCode != null){
                     List<Zip_Code__c> Zipcodlist = [Select Territory__c from Zip_Code__c where Name =:Accountlist[0].BillingPostalCode];
                     List<Territory__c> Territory2  =[Select id, Name from Territory__c where Name ='Whitespace'];
                    If(!Zipcodlist.isEmpty()){
               
                    ld.Territory__c = Zipcodlist[0].Territory__c;
                     
                    }else{
                     If(!Territory2.isEmpty()){
                 ld.Territory__c = Territory2[0].id;
                     }
                }
                }else If(Accountlist[0].BillingPostalCode == '' || Accountlist[0].BillingPostalCode == Null){
                    system.debug('Entered in account postal code empty loop');
         List<Zip_Code__c> Zipcodlist2 = [Select Territory__c from Zip_Code__c where Name =:ld.postalcode];
         List<Territory__c> Territory2  =[Select id, Name from Territory__c where Name ='Empty'];  
            If(!Zipcodlist2.isEmpty()){
                
                    ld.Territory__c = Zipcodlist2[0].Territory__c;
                     
                 }else{ 
                     If(!Territory2.isEmpty()){
                 ld.Territory__c = Territory2[0].id;
                     }
            } 
                }
             }    
        }
            
        else If(ld.Referral__c == null && ld.postalcode != null){ 
                  
         //Fetching the Territory name from Lead PostalCode
         List<Zip_Code__c> Zipcodlist2 = [Select Territory__c from Zip_Code__c where Name =:ld.postalcode];
         
           List<Territory__c> Territory2  =[Select id, Name from Territory__c where Name ='Empty'];
            
            If(!Zipcodlist2.isEmpty()){
                
                    ld.Territory__c = Zipcodlist2[0].Territory__c;
                        
            }else{
                     If(!Territory2.isEmpty()){
                 ld.Territory__c = Territory2[0].id;
                     }
            }
            
        }
      
    }
    }
   
    }
}

Test class:
@isTest
private class LeadTriggerHandlerTest {

    
    static testMethod void BeforeInsertMethod(){
        List<Lead> lstLead =   new List<Lead>{
                          new Lead(Company = 'JohnMiller', LastName = 'Mike', Status = 'Open'),
                          new Lead(Company = 'Nike', LastName = 'John', Status = 'Open'),
                          new Lead(Company = 'Miles', LastName = 'Davis', Status = 'Open'),
                          new Lead(Company = 'Reebok', LastName = 'Hillen', Status = 'Open'),
                          new Lead(Company = 'Addidas', LastName = 'Shrin', Status = 'Open')
                         }; 
        
                             
        LeadTriggerHandler     H= new LeadTriggerHandler ();
        H.BeforeInsertMethod(lstLead);

     //need to cover the codecoverage
    }
    
    
    
}

 
Hi Team, 
We had created a few flows in Sandbox and need to deploy them in production after the sprint, Is Test classes mandatory for the flows we created?

Thanks
Prathusha Reddy
Hi folks, 
 if i add the script code inside the Vscode, its working fine.
 but if i add the file in Index.js file and call it in HTML code, its throwing the below error.
Uncaught TypeError: Cannot read properties of null (reading 'addEventListener');


Html code:
 
<!DOCTYPE html>
<html>
    <head>
        <script src="./Index2.js"> </script>
    </head>
<body>

<h1>The Element Object</h1>
<h2>The addEventListener() Method</h2>

<p>Execute a function when a user clicks on a button:</p>

<button id="myBtn">Try it</button>

<p id="demo">



</body>
</html>

Index2.js:
const element = document.getElementById("myBtn");
element.addEventListener("click", myFunction);

function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}

 Note:
Implementing same functionality with this w3schools Url:https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_element_addeventlistener2
We have a  custom object called, Planning__c, EventTarget__c.

1. Added a  Custom button on the Record Detail Page of Planning__c.

2. Onclick on the button needs to display all the accounts whose Status__c is active as a Datatable with multiple select checkboxes.

3. After selecting the desired data Need to Create an EventTarget__c record with the Same Account data.

Please guide Some Links or references to start work with..!

Thanks
Prathusya Reddy..!
Hi All..!
1.On the Account record Detail page i  had added "Add contact" Custom button.
2.On click on  the button ,  i need to display the list  of Contact records , so that we can select multiple contacts with checkboxes and click on save
3.The selected contacts should be added to the account record related contact  list.
Please help if it's possible with flows, As iam an Administrator..!
Do I need to go with flows?
Or Do we have to write the custom code functionality to Implement functionality Only ?

Please help
thanks
Prathusha reddy
 
Hi just a small sample code .
 
public class TargetPlanController {    
        
    @AuraEnabled    
    public static List <TargetPlan__c > fetchAccts(Id recordId) {    
            
        return [SELECT Name,Account__c,No_of_Leads__c,AccountCity__c,FROM TargetPlan__c where BP_Id__c =: recordId ];
          }      
        
}

How to write the Test Class for the Above code.. please let me know.
Thanks 
Prathusha Reddy.
 
Hi Team 
1.Added 3 users say user1, user2, user3.
2. created a record Trigger flow.
3.How to use the public group users add to recipients to send the email in Send Email action.
Please suggest any links or references
Thanks 
Prathusya Reddy
public class AccounZipCodeTriggerHandler {

    public  Id SYS_ADMIN_PROFILE_ID{get;set;}
    
  public void afterInsertMethod(List<account> NewAcc){
     //SYS_ADMIN_PROFILE_ID =  [select ProfileId from User where Profile.Name = 'System Administrator' limit 1].ProfileId;
     //Business Logic for After Insert functionality
     Id AccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('ITEmploye').getRecordTypeId();
         If(!NewAcc.isEmpty()){
         For(Account acc : NewAcc){
             If(acc.RecordTypeId == AccRecordTypeId){
                 If(acc.BillingPostalCode!= Null){
                      List<Zip_Code__c> Zipcodlist = [Select Territory__c from Zip_Code__c where Name =:acc.BillingPostalCode  ];
                 If(!Zipcodlist.isEmpty()){
                    acc.Territory_LU__c =Zipcodlist[0].Territory__c;  //assigning the value to the Account territory
                   //insert acc; 
                 }
                 
                 }
             } 
         }
         
         
     }
  }
    public void afterUpdateMethod(List<account> UpdateAcc){
          system.debug('Update Method');
       SYS_ADMIN_PROFILE_ID =  [select ProfileId from User where Profile.Name = 'System Administrator' limit 1].ProfileId;
       //If(UserInfo.getProfileId() != SYS_ADMIN_PROFILE_ID ){
     //Business Logic for After Insert functionality
     Id AccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('ITEmploye').getRecordTypeId();
        If(!UpdateAcc.isEmpty()){
            For(Account acc : UpdateAcc){
                If(acc.RecordTypeId == AccRecordTypeId){
               //if billing postalcode not null and Territory value is null
             If( acc.BillingPostalCode!= Null && acc.Territory_LU__c == NULL && acc.Run_Apex__c == FALSE ){
                 system.debug('Entered in 1');
                  List<Zip_Code__c> Zipcodlist = [Select Territory__c from Zip_Code__c where Name =:acc.BillingPostalCode AND Territory__c!=null ];
                       If(!Zipcodlist.isEmpty()){
                        acc.Territory_LU__c =Zipcodlist[0].Territory__c;  //assigning the value to the Account territory
                       
                       }
             }else If(acc.BillingPostalCode!= Null && acc.Territory_LU__c != NULL && acc.Run_Apex__c == FALSE){
                  system.debug('Entered in 2');
                    List<Zip_Code__c> Zipcodlist = [Select Territory__c from Zip_Code__c where Name =:acc.BillingPostalCode AND Territory__c!=null];
                //if the user is not system administrator
                 If(UserInfo.getProfileId() != SYS_ADMIN_PROFILE_ID ){
                   If(!Zipcodlist.isEmpty()){
                      If(Zipcodlist[0].Territory__c !=  acc.Territory_LU__c ){
                          acc.addError('Address changes are not allowed'); 
                      }
                   }  
                 //if the user is a system administrator
                }else If(UserInfo.getProfileId() == SYS_ADMIN_PROFILE_ID){
                         If(!Zipcodlist.isEmpty()){
                           acc.Territory_LU__c =Zipcodlist[0].Territory__c;  //assigning the value to the Account territory
                        }
                     }
             
             }else If(acc.Run_Apex__c ==TRUE && acc.BillingPostalCode != NULL){
                   system.debug('Entered in 3');
                  List<Zip_Code__c> Zipcodlist = [Select Territory__c from Zip_Code__c where Name =:acc.BillingPostalCode AND Territory__c!=null];
                   
                  If(!Zipcodlist.isEmpty()){
                
                        acc.Territory_LU__c =Zipcodlist[0].Territory__c;  //assigning the value to the Account territory
                        acc.Run_Apex__c=FALSE; //this is code to make true to false
                   }
              }
          }
              
        }
     }
   }
}

Trigger Handler:
 
trigger AccountZipCodeTrigger on Account (before insert , before update) {
    
   AccounZipCodeTriggerHandler  AccZipHandler = New AccounZipCodeTriggerHandler();
    //Before insert 
   if(Trigger.isBefore && Trigger.isinsert){
	 AccZipHandler.afterInsertMethod(Trigger.New);   
   }
    
    //Before update 
    if(Trigger.isBefore && Trigger.isupdate){
       AccZipHandler.afterUpdateMethod(Trigger.New);
    }
    
}

Thanks
Prathushya Reddy
 
public class TaskAccountTriggerHandler {
    
    public void afterInsertOrUpdateMethod(List<Task> NewTasks){
        List<Case>  cList = new List<Case>(); //List collection with case is created to store the case records
        //values will pass from trigger to here 
        If(!NewTasks.isEmpty()){
            for (Task t : NewTasks) {
                string id = string.valueof(t.WhatId);
                   //condition for Account Related Task
                If(t.WhatId != null && id.startsWith('001')){
                    t.Account__C = t.WhatId;
                   //Condition for Case Related Task and startsWith 500 and completed as status.
                }else If(t.WhatId != null && id.startsWith('500')&&t.Status == 'Completed'){
                    Case c = new Case();
                    c.Id = t.whatId;
                    c.Comments='Completed a task: '+t.Subject;
                    cList.add(c); //adding to the list to update
                } 
            }
            
        }
     //it will check the list empty or not for update.
      if(!cList.isEmpty())
        update cList;
      }
    
}
trigger TaskAccountTrigger on Task (before insert , before update) {
    
    TaskAccountTriggerHandler TaskHandlr = New TaskAccountTriggerHandler();
    
   //Before insert and update
   if(Trigger.isbefore && Trigger.isinsert  ){
	  TaskHandlr.afterInsertOrUpdateMethod(Trigger.New);   
   }
    
    
    //Before insert and update
   if(Trigger.isbefore && Trigger.isupdate){
	  TaskHandlr.afterInsertOrUpdateMethod(Trigger.New);   
   }
}
Please provide your suggestions or links 
Thanks
Prathusha

 
1.We have a MultiSelect Picklist field.
2.We wanna see which value is selected how many times on a report
So you need to create a report to show this.
3.Show it on dashboard,

Please suggest some reference links or valuable information .

Thanks
sfdx.
How????
whenever a user exports data using dataloader/data export wizard/third party tool, then a report need to be send them.

Please give your valuable Suggestions.
Thanks 
Sfdx.
How to add to get the serviceId and Taxid values  form the url:
what is the options to add, and how to get the multiple params :
Option:1
@RestResource(urlMapping='/Revenues/accountId={acctId}&serviceId={svcId}&TaxId={TaxId}');
OR

Option:2
@RestResource(urlMapping='/Revenues/accountId/*/serviceId/*/TaxId/');



Option:3
@RestResource (urlMapping='/DeviceObjserviceendpoint/*')
global class DeviceObj_Rest_Service {
  
    // @HttpGet
    global static void doGet() {
        String result = '';
        RestRequest request = RestContext.request;
       
String accountId = request.requestURI.substringAfter( '/DeviceObjserviceendpoint/' );

String accountId = ??? //how to get the value of Serviceid
String TaxId = ??? //how to get the value of TaxId




        List<Account> accs = [Select Id, Status__c from Account where Id = :accountId && <serviceidvalue> && <Taxidvalue> LIMIT 1];
    
    }
@RestResource (urlMapping='/DeviceObjserviceendpoint/*')
global class HC_DeviceObj_Rest_Service {
  
     @HttpGet
    global static void doGet() {
        String result = '';
        RestRequest request = RestContext.request;
        String accountId = request.requestURI.substringAfter( '/DeviceObjserviceendpoint/' );
        List<Account> accs = [Select Id, Status__c from Account where Id = :accountId LIMIT 1];
        if( accs.size() > 0 ) {
            Account acc = accs[0];
            Map<String,String> resultMap = new Map<String,String> {
                'Message'  => 'Account found Sucessfully',
                'accountId' => acc.Id,
                'accountStatus' => acc.Status__c
            };

            result = JSON.serialize( resultMap );
        } else {
            result = 'Account with ID ' + accountId + ' not found!';
        }

        RestContext.response.addHeader('Content-Type','application/json');
        RestContext.response.responseBody = Blob.valueOf(result);
    }

Above code is working fine : need to add the parameters 
https://testingorg--dev.sandbox.my.salesforce.com/services/apexrest/DeviceObjserviceendpoint/1234/DateofJoiningValue/TaxNoValue


Soql should have to add  where condition of DateofJoining__c ,tax_no__c  of customfields.

How to add extra parameters other than the AccountId:
 String accountId = request.requestURI.substringAfter( '/DeviceObjserviceendpoint/' ); //got 1234
//string DateofJoining= ???   //How to get the dateofJoiningvalue??
 //string TaxNo= ???  //How to get the TaxNo???



List<Account> accs = [Select Id, Status__c from Account where Id = :accountId  && DateofJoining__c =: DateofJoining && tax_no__c =: TaxNo LIMIT 1];



Best Regards
Sfdx 
 
Hi Team,
Object:Account
CustomFields in account:Birthdate , SerialNo(unique one).
UseCase:
I have a requirement to Create and share a api from Salesforce to the client that,
When the user enters the accountname, birthdate and serialNo, if the data is there then we need to send  response that "Record Found" else  "Record not found in response".
Any links or documents to go through it.
        As iam new to Integration, can any one plase help me out for this requirement.

Thanks
Sfdx 
 
Scenario:
 User 1 :full access profile
User 2 : Limited access Profile with limited access license.

Step 1:Once the User 1 , submits the Record for Approval to User 2,
Step 2: User2 gets the Record to approve or Reject or Reassign
Step 3: User2 clicks on the Approve button and add an comment as approved.
Step 4: It was throwing an errror that "user dont have permissions to Perform Dml Operation on that Particular Custom object.

Need to Bypass that error,what will be the solution for it.  any custom functionality.

Please provide the Solution if you have faced the same scenario

Thanks
Sfdx
I have a custom object , After Clicking on  Submit For approval it is submited to Approver.

In the Home page of the Approver,
We have three buttons like.
1.Approve
2.Reject
3.ReAssign 

Can i add any custom button on the detail page of the record , so that to call the apex class or any other flow form the button any other custom functionality in the page.


Thanks and Regards
Sfdx.
 
on the Standard record page,
When ever i select status as closed , i need to display the three dynamic fileds in a popup or in a screen which are already created in the lead object, need to fill that dynamic fileds and then it should saving.

Note: The dynamic fileds are not displayed in the pagelayout , its just created in the lead object, and dynamic fileds should display only if the status is selected as closed in the standard record page.

Any suggestions to achieve it in standard record page functionality

Thanks 
salesforce sfdx
@RestResource (urlMapping='/DeviceObjserviceendpoint/*')
global class DeviceObj_Rest_Service {
  
    @HttpGet
    global static void doGetDevice() {
        String result = '';
        try{
        Map<string, string> paramsMap = RestContext.request.params;
      if(paramsMap!=null){
        String serialNo = paramsMap.get('serialNo');
        String lastName = paramsMap.get('lastName');
        String dateOfBirth = paramsMap.get('dateOfBirth');  
                 Date dob = date.parse(dateOfBirth);
            
       
        //Date dob = date.parse(dateOfBirth);
        List<Device__C> Devs = [Select Id, Name,Dob__c,Patient_Last_Name__c from Device__C 
                                where Name = :SerialNo and  
                                Patient_Last_Name__c =:lastName and 
                                DOB__c = :dob
                                LIMIT 1];

         if( Devs.size() > 0 ) {
             Device__C Dev = Devs[0];
            Map<String,String> resultMap = new Map<String,String> {
                'Message'  => 'Device found Sucessfully',
                'DeviceId' => Dev.Id,
                'SerialNo' => Dev.Name,
                'DateOfBirth' => string.valueof(Dev.Dob__c),
                 'lastname' =>Dev.Patient_Last_Name__c
            };
           
          result = JSON.serialize( resultMap );
       
         }
        else {
            result = 'Device with SerialNo :' + SerialNo + ' not found!';
        }
        }
        }catch(Exception ex){
            result= ex.getMessage();
        }
        RestContext.response.addHeader('Content-Type','application/json');
        RestContext.response.responseBody = Blob.valueOf(result);
    
         }
    
}

My Test Class:
@isTest
private class DeviceObj_Rest_Service_Test {
    
    static testMethod void testDoGetDevice() {
         Id stExam = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Patient').getRecordTypeId();
         system.debug(stExam);
         
         Account acc = new Account(FirstName = 'Test', LastName = 'Test22', PersonEmail = 'testaccount@test.com', RecordTypeId = stExam);
         insert acc;  
            
       
        // create a new Device record
        Device__c device = new Device__c(Name = '1234567890', type__c='Test',Patient__c= acc.id);
        insert device;
        
        // test a valid GET request
        RestRequest request = new RestRequest();
        request.requestURI = '/services/apexrest/DeviceObjserviceendpoint';
        request.addParameter('serialNo', device.Name);
        request.addParameter('lastName', device.Patient_Last_Name__c);
        request.addParameter('dateOfBirth', String.valueOf(device.DOB__c));
        RestContext.request = request;
        
        Test.startTest();
        DeviceObj_Rest_Service.doGetDevice();
        Test.stopTest();
        
        RestResponse response = RestContext.response;
      
    }
    
}

Its getting failed due to some issues , please provide some tips or any links to refer .

Thanks
Prathusha Reddy.
Hi All..!
1.On the Account record Detail page i  had added "Add contact" Custom button.
2.On click on  the button ,  i need to display the list  of Contact records , so that we can select multiple contacts with checkboxes and click on save
3.The selected contacts should be added to the account record related contact  list.
Please help if it's possible with flows, As iam an Administrator..!
Do I need to go with flows?
Or Do we have to write the custom code functionality to Implement functionality Only ?

Please help
thanks
Prathusha reddy
 
Hi just a small sample code .
 
public class TargetPlanController {    
        
    @AuraEnabled    
    public static List <TargetPlan__c > fetchAccts(Id recordId) {    
            
        return [SELECT Name,Account__c,No_of_Leads__c,AccountCity__c,FROM TargetPlan__c where BP_Id__c =: recordId ];
          }      
        
}

How to write the Test Class for the Above code.. please let me know.
Thanks 
Prathusha Reddy.
 
public class AccounZipCodeTriggerHandler {

    public  Id SYS_ADMIN_PROFILE_ID{get;set;}
    
  public void afterInsertMethod(List<account> NewAcc){
     //SYS_ADMIN_PROFILE_ID =  [select ProfileId from User where Profile.Name = 'System Administrator' limit 1].ProfileId;
     //Business Logic for After Insert functionality
     Id AccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('ITEmploye').getRecordTypeId();
         If(!NewAcc.isEmpty()){
         For(Account acc : NewAcc){
             If(acc.RecordTypeId == AccRecordTypeId){
                 If(acc.BillingPostalCode!= Null){
                      List<Zip_Code__c> Zipcodlist = [Select Territory__c from Zip_Code__c where Name =:acc.BillingPostalCode  ];
                 If(!Zipcodlist.isEmpty()){
                    acc.Territory_LU__c =Zipcodlist[0].Territory__c;  //assigning the value to the Account territory
                   //insert acc; 
                 }
                 
                 }
             } 
         }
         
         
     }
  }
    public void afterUpdateMethod(List<account> UpdateAcc){
          system.debug('Update Method');
       SYS_ADMIN_PROFILE_ID =  [select ProfileId from User where Profile.Name = 'System Administrator' limit 1].ProfileId;
       //If(UserInfo.getProfileId() != SYS_ADMIN_PROFILE_ID ){
     //Business Logic for After Insert functionality
     Id AccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('ITEmploye').getRecordTypeId();
        If(!UpdateAcc.isEmpty()){
            For(Account acc : UpdateAcc){
                If(acc.RecordTypeId == AccRecordTypeId){
               //if billing postalcode not null and Territory value is null
             If( acc.BillingPostalCode!= Null && acc.Territory_LU__c == NULL && acc.Run_Apex__c == FALSE ){
                 system.debug('Entered in 1');
                  List<Zip_Code__c> Zipcodlist = [Select Territory__c from Zip_Code__c where Name =:acc.BillingPostalCode AND Territory__c!=null ];
                       If(!Zipcodlist.isEmpty()){
                        acc.Territory_LU__c =Zipcodlist[0].Territory__c;  //assigning the value to the Account territory
                       
                       }
             }else If(acc.BillingPostalCode!= Null && acc.Territory_LU__c != NULL && acc.Run_Apex__c == FALSE){
                  system.debug('Entered in 2');
                    List<Zip_Code__c> Zipcodlist = [Select Territory__c from Zip_Code__c where Name =:acc.BillingPostalCode AND Territory__c!=null];
                //if the user is not system administrator
                 If(UserInfo.getProfileId() != SYS_ADMIN_PROFILE_ID ){
                   If(!Zipcodlist.isEmpty()){
                      If(Zipcodlist[0].Territory__c !=  acc.Territory_LU__c ){
                          acc.addError('Address changes are not allowed'); 
                      }
                   }  
                 //if the user is a system administrator
                }else If(UserInfo.getProfileId() == SYS_ADMIN_PROFILE_ID){
                         If(!Zipcodlist.isEmpty()){
                           acc.Territory_LU__c =Zipcodlist[0].Territory__c;  //assigning the value to the Account territory
                        }
                     }
             
             }else If(acc.Run_Apex__c ==TRUE && acc.BillingPostalCode != NULL){
                   system.debug('Entered in 3');
                  List<Zip_Code__c> Zipcodlist = [Select Territory__c from Zip_Code__c where Name =:acc.BillingPostalCode AND Territory__c!=null];
                   
                  If(!Zipcodlist.isEmpty()){
                
                        acc.Territory_LU__c =Zipcodlist[0].Territory__c;  //assigning the value to the Account territory
                        acc.Run_Apex__c=FALSE; //this is code to make true to false
                   }
              }
          }
              
        }
     }
   }
}

Trigger Handler:
 
trigger AccountZipCodeTrigger on Account (before insert , before update) {
    
   AccounZipCodeTriggerHandler  AccZipHandler = New AccounZipCodeTriggerHandler();
    //Before insert 
   if(Trigger.isBefore && Trigger.isinsert){
	 AccZipHandler.afterInsertMethod(Trigger.New);   
   }
    
    //Before update 
    if(Trigger.isBefore && Trigger.isupdate){
       AccZipHandler.afterUpdateMethod(Trigger.New);
    }
    
}

Thanks
Prathushya Reddy
 
public class TaskAccountTriggerHandler {
    
    public void afterInsertOrUpdateMethod(List<Task> NewTasks){
        List<Case>  cList = new List<Case>(); //List collection with case is created to store the case records
        //values will pass from trigger to here 
        If(!NewTasks.isEmpty()){
            for (Task t : NewTasks) {
                string id = string.valueof(t.WhatId);
                   //condition for Account Related Task
                If(t.WhatId != null && id.startsWith('001')){
                    t.Account__C = t.WhatId;
                   //Condition for Case Related Task and startsWith 500 and completed as status.
                }else If(t.WhatId != null && id.startsWith('500')&&t.Status == 'Completed'){
                    Case c = new Case();
                    c.Id = t.whatId;
                    c.Comments='Completed a task: '+t.Subject;
                    cList.add(c); //adding to the list to update
                } 
            }
            
        }
     //it will check the list empty or not for update.
      if(!cList.isEmpty())
        update cList;
      }
    
}
trigger TaskAccountTrigger on Task (before insert , before update) {
    
    TaskAccountTriggerHandler TaskHandlr = New TaskAccountTriggerHandler();
    
   //Before insert and update
   if(Trigger.isbefore && Trigger.isinsert  ){
	  TaskHandlr.afterInsertOrUpdateMethod(Trigger.New);   
   }
    
    
    //Before insert and update
   if(Trigger.isbefore && Trigger.isupdate){
	  TaskHandlr.afterInsertOrUpdateMethod(Trigger.New);   
   }
}
Please provide your suggestions or links 
Thanks
Prathusha

 
Scenario:
 User 1 :full access profile
User 2 : Limited access Profile with limited access license.

Step 1:Once the User 1 , submits the Record for Approval to User 2,
Step 2: User2 gets the Record to approve or Reject or Reassign
Step 3: User2 clicks on the Approve button and add an comment as approved.
Step 4: It was throwing an errror that "user dont have permissions to Perform Dml Operation on that Particular Custom object.

Need to Bypass that error,what will be the solution for it.  any custom functionality.

Please provide the Solution if you have faced the same scenario

Thanks
Sfdx
I have to covert the report to csv and   schedule a apex  class to run every 5mintes :
i had tried using a batch, 
First error: Too many callouts: 1.
please let me know your comments if any other approach:
BatchApex:
global with sharing class SampleBatchApexClass implements Database.batchable<sObject>
{
   //Retrieve only the records which needs to be processed
    global Database.QueryLocator start(Database.BatchableContext bc)
    {
        //Starting query goes here
        String query = 'SELECT Id,Name FROM Account limit 1';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext bc, List<sObject> scope)
    {
        //Batch class business logic goes here
        //
       
    }
        
    global void finish(Database.BatchableContext bc)
    {
        
         List<Messaging.EmailFileAttachment> attachments=new List<Messaging.EmailFileAttachment>();
            List<Report>reportList = [SELECT Id,DeveloperName,Name FROM Report where DeveloperName ='flow_screen_prebuilt_report' limit 1];
            if(reportList.size()>0){
                for(Report report:reportList){
                    String reportId = (String)report.Id;     
                    string reportName=(String)report.Name;     
                    ApexPages.PageReference objPage = new ApexPages.PageReference('/'+reportId+'?csv=1&isdtp=p1');                    
                    Messaging.EmailFileAttachment objMsgEmailAttach = new Messaging.EmailFileAttachment();
                    Date dt = System.today().toStartOfMonth().addMonths(-1);
                    System.debug(dt.format());
                    objMsgEmailAttach.setFileName(reportName+' '+dt.format()+' '+'.csv');
                    //if(!Test.isRunningTest())
                    objMsgEmailAttach.setBody(objPage.getContent());
                    objMsgEmailAttach.setContentType('text/csv');
                    attachments.add(objMsgEmailAttach);
                }
            }  
            
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
           
            mail.setUseSignature(false);
            mail.setToAddresses(new List<String>{'test.test@gmail.com'});
            mail.setSubject('Daily Report from Salesforce');
            mail.setHtmlBody('<br/><br/>Please review daily reports attached.<br/><br/><br/><br/>');
            mail.setFileAttachments(attachments);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        //here scheduling starts
        Datetime dt = system.now().addMinutes(5);
        String day = string.valueOf(dt.day());
        String month = string.valueOf(dt.month());
        String hour = string.valueOf(dt.hour());
        String minute = string.valueOf(dt.minute());
        String second = '00';
        String year = string.valueOf(system.now().year());
        String strJobName = 'SampleSchedulingClass  -' + year + '-' + month + '-' + 
        day + ' ' + hour + ':' + minute + ':' + second;
        String strSchedule = '00 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
        System.schedule(strJobName, strSchedule, new SampleSchedulingClass  ());
    }
}

Schedulable class:
global class SampleSchedulingClass  implements Schedulable 
{
    global void execute(SchedulableContext ctx) 
    {
        SampleBatchApexClass renewalOppBatch = new SampleBatchApexClass();
        Database.executeBatch(renewalOppBatch, 5);    
        System.abortJob(ctx.getTriggerID());
    }
}

ConExpression for starting:
Datetime dt = system.now().addMinutes(2);
        String day = string.valueOf(dt.day());
        String month = string.valueOf(dt.month());
        String hour = string.valueOf(dt.hour());
        String minute = string.valueOf(dt.minute());
        String second = '00';
        String year = string.valueOf(system.now().year());
        String strJobName = 'SampleSchedulingClass  -' + year + '-' + month + '-' + 
        day + ' ' + hour + ':' + minute + ':' + second;
        String strSchedule = '00 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
        System.schedule(strJobName, strSchedule, new SampleSchedulingClass  ());

 
Created an apex class and added schedulable.
1.Need to run it every one hour 
2.Need to run it in office time like 6am to 6pm.
3.Need to run it to work only for 1st 10 days of starting of every month.
so, i have added the below Code, 
scheduledMerge m = new scheduledMerge();
String sch = '0 6-18 1-10 * *';
String jobID = system.schedule('Merge Job', sch, m);

Getting the error of below:

System.StringException: Unexpected end of expression.

Can you please suggest your  valuable suggestions.

Thanks 
Thanks in advance.
Hi team, i have a requirement that,
we have to send one email , Apex class is Ready and working fine.
Requirements:
1.Need to schedule it every one hour.
2.Need to schedule it in office time like 6am to 6pm.
3.Need to schedule it to work only for 1st 10 days of starting of every month.
Can any one give your valuable suggestion to perform this task.
Thanks in advance.
Hi team, i have a requirement that,
we have to send one email , for every one hour from 6am to 6pm eastern pacific for only 1st 10 days only.

Say Example : 01-08-2022 to 10-08-2022 only.//6am to 6pm 

How to write the expression of below.

How to Execute below code from developer console :-
ApexScheduledClass  m = new ApexScheduledClass ();
String sch = ??????? //need to add to fire at 1st 10days of every month form 6am to 6pm,
String jobID = system.schedule('Merge Job', sch, m);
How add the time for the particular specific scenario. 
Please suggest your suggestions.
Thanks
Sfdx
 
Hi Team, As i have an idea that yes, we can schedule the Report in Salesforce.

But Requirement is :
We have a report in salesforce ,  in the business hours for every one hour we have send the fresh Report of exported to CSV File and send to the specified User Email address .

How can i automate it that Report get automatically downloaded as csv and attached to an email and sent to specific user, 
Is that functionality Available in Salesforce.

Thanks 
Sfdx
 
I have a requirement that i have an Report , that   Report automatically Exported as CSV file to and send to  Email Address ,this functionality should run for every 3hrs in the business hours only. say(10am-7pm)

Any idea how can i acheive it.
Thanks
Sfdx.
Requirement using a Flow: but flow is not Working.

UseCase:
When the lead record is converted.
lead record  details are to be updated in the account object.
created a same fields in both objects but when we run the flow it was showing Error.

 
Result
Failed to update records that meet the filter criteria.

Error Occurred: 
This error occurred when the flow tried to update records: SELECT Id FROM Account WHERE ((Id = ' 0012h00000oEq2cAAC')) LIMIT ^ ERROR at Row:1:Column:32 invalid ID field: 0012h00000oEq2cAAC. You can look up ExceptionCode values in the SOAP API Developer Guide.


 
Flow Steps :

Step 1: Start
a.Created a Record -Triggered Flow on lead
b.A record is Created or Update
c.optimize for: Actions and Related Records.

Step 2: Decision
a)Yes
b)All conditions met
c)Conditon:
{!$Record.IsConverted}   Equals  {!$GlobalConstant.True}


Step 3: update the lead data on the convertedAccountid Record.
a)Specify conditions to identify records, and set fields individually
b)Object: Account.
c)All conditions met.
d)Conditon:
Id  Equals   {!$Record.ConvertedAccountId}

e)Set Field Values for the Account Records

Manufacturer__c  <-- {!$Record.Manufacturer__c}

Step 4:End.

Note: Manufacturer__c   is a custom field in the salesforce.

Please  suggest a better way to handle it , 
thanks
sfdx