• Geetanjali Sharma 9
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies
Hi Guys,
i am creating Batch apex class to insert/update/delete records in my custom object emploee_profile from Profiles. I am able to insert but delete/update not working.

please see my code and guide me where i am wrong..actually i am beginner in salesforce:


global class ProfilesSync implements database.batchable<sObject>,Database.Stateful{
    
    global map<ID,Profile> ProfileRegMap=new map<ID,Profile>();
    global Database.QueryLocator start(Database.BatchableContext BC){
        System.debug('in start');
        try{
            return database.getQueryLocator([select ID,Name from Profile order by ID]);
        }
        catch(Exception e){
            System.debug('Error=='+e.getStackTraceString());
        }
        return null;
    }
    global void execute(Database.BatchableContext BC, List<Profile> ProfilesList)
    {
        System.debug('ProfileList=='+ProfilesList.size());
        if(ProfilesList!=NULL)
        {
            for(Profile rl:ProfilesList){
                ProfileRegMap.put(rl.ID,rl);
            }
        }
    }
    global void finish(Database.batchableContext BC){
        System.debug('UserProfileList=='+ProfileRegMap);
        List<Employee_Profile__c> Employee_Profile_list1 = new List<Employee_Profile__c>([select Profile_ID__c,Profile_Name__c from Employee_Profile__c order by Profile_ID__c]);
        List<Employee_Profile__c> Employee_Profile_list_Insert = new List<Employee_Profile__c>();
        List<Employee_Profile__c> Employee_Profile_list_update = new List<Employee_Profile__c>();
        List<Employee_Profile__c> Employee_Profile_list_delete = new List<Employee_Profile__c>();
        
        map<ID,Employee_Profile__c> custRoleMap=new map<ID,Employee_Profile__c>();
        for(Employee_Profile__c us:Employee_Profile_list1){
            custRoleMap.put(us.Profile_ID__c,us);
        }
 
            for(Profile urs:ProfileRegMap.values()){
                if(!custRoleMap.containsKey(urs.id)){
                  system.debug('New records');
                        Employee_Profile__c urs2 = new Employee_Profile__c();
                        urs2.Profile_ID__c=urs.id;
                        urs2.name=urs.id;
                        urs2.Profile_Name__c=urs.name;
                       Employee_Profile_list_Insert.add(urs2); 
              
                }
                
            }
            system.debug('size of cust list'+Employee_Profile_list_Insert.size());
            insert Employee_Profile_list_Insert;
           update Employee_Profile_list_update;
           delete Employee_Profile_list_delete;
    }
}
Hi To Everyone,

I am new to salesforce so not much aware about all the apex class coding and visula force. so sorry if i am asking something is silly.

My issue is that.
I have created custom object sat name Registration where i have created 1 field name "Profile_Form" .
now on  Registration layout i want to show all Profile list (profile that we craeted in user) on field "Profile_Form" to select. 
If i am using picklist, there i can list out onlt current available all profile list ,but in future  new profile could be added and old could be edited ,in that condition custom picklist will not work.

So i want the way to show list of all profiles on my custom field.


Please suggest.

​Thanks in advance,
Hi To Everyone,

I am new to salesforce so not much aware about all the apex class coding and visula force. so sorry if i am asking something is silly.

My issue is that.
I have created custom object sat name Registration where i have created 1 field name "Profile_Form" .
now on  Registration layout i want to show all Profile list (profile that we craeted in user) on field "Profile_Form" to select. 
If i am using picklist, there i can list out onlt current available all profile list ,but in future  new profile could be added and old could be edited ,in that condition custom picklist will not work.

So i want the way to show list of all profiles on my custom field.


Please suggest.

Thanks in advance,
Hi I have integrated BOT commands utility bar in my app. where we have list of bot commands like add two numbers, find contact, find opportunity. Now i want to add 1 more command by which if i give reset password it just reset the passowrd of loginned user. below is code..i beleive who used bOT command in app can understand it..please help where is am wrong..i am learner
**************************************************************************************
public with sharing class HandlerResetUserP implements BotHandler {
   
     public BotResponse handle(String utterance, String[] params, Map<String, String> session) {
        String key = '%' + params[0] + '%';
        List<User> users =
            [SELECT Id, name, alias FROM user where  Id = : UserInfo.getUserId()
             ORDER BY Name
             LIMIT 5];
       
        List<BotRecord> records = new List<BotRecord>();
       
        for (user u : users) {
           
           
           // List<System.ResetPasswordResult> passwords = new //list<System.ResetPasswordResult>;
            system.resetPassword(u.ID,true);
           
          
        }
        return new BotResponse(new BotMessage('Bot', 'Here is a list of contacts matching "' + params[0] + '":'));
       
    }
   
}
Hi To Everyone,

I am new to salesforce so not much aware about all the apex class coding and visula force. so sorry if i am asking something is silly.

My issue is that.
I have created custom object sat name Registration where i have created 1 field name "Profile_Form" .
now on  Registration layout i want to show all Profile list (profile that we craeted in user) on field "Profile_Form" to select. 
If i am using picklist, there i can list out onlt current available all profile list ,but in future  new profile could be added and old could be edited ,in that condition custom picklist will not work.

So i want the way to show list of all profiles on my custom field.


Please suggest.

​Thanks in advance,