• Mak One
  • NEWBIE
  • 70 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 24
    Questions
  • 20
    Replies

I have to customize edit, view, delete for Attachments in Opportunity Page Layout.

On delete button I have following lines in Visualforce Page:

<apex:commandLink styleClass="ankit" value="del" onclick="return confirm('Are you sure?')" action="{!delAttachAndNote}" > <apex:param name="attachId" value="{!item.Id}" assignTo="{!delId}" /> </apex:commandLink>

And below is code in Apex class which is "with sharing":

 public String delId{get;set;}
 public void delAttachAndNote(){
        Database.delete(delId);     
}

I tried changing it to delete new Attachment(Id=delId), etc. But still no luck.

Why Salesforce is not taking care of permissions here and Is there any alternative? Also, we cannot get URL for deleting Attachment or Notes.

Seeing Salesforce Procing I don't think it is possible. As anyone can join the website and we have to pay huge license fee for that new user. After that the user may post a lot  of content into Salesforce which may reach the Salesforce limit and so we need to perform additional licenses.
Just wanted to confirm that we cannot build a Social Networking site in Salesforce.
As for Site.com Free Edition if users will become more than 100 then you have to pay for that.
Why can't we track the username password and display pages accordingly and in real everytime the same user will login but as per username provided by user the different pages will be displayed?
 
I have to schedule my batch every 2nd weekday and Monday every second week (means after every 2 weeks).
It should not be like Monday Wednesday Friday of week or anything like that it should be exactly 2nd weekday (like after Friday it should be Tuesday). It should work even at the end days of month so if I provide any logic like 3rd and 4th week of each month it will fail after 28th of month.

What can be the solution for this?

I have seen suggestion with below code for catching Validation Error:

try {
   update user;
}
catch (Exception e) {
   String errorMessage = e.getMessage();
   if(!errorMessage.contains('FIELD_CUSTOM_VALIDATION_EXCEPTION')) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, errorMessage));
   }
}

Is there any better way for this as my custom error message may also contain String: 'FIELD_CUSTOM_VALIDATION_EXCEPTION'

Is there any specific Exception Type provided by Salesforce for Validation Error. Or is there any better way to catch ValidationError?

In Task creation for Opportunity I have to make sure that only certain picklist values are available (or we can restrict to Save Task from Valiation Rule on Task) in Custom Pricklist field for certain Stage field values in Opportunity.

Now, from Task in Validation Rule we can get only Parent ID (WhatID) which will be ID of Opportunity.
Now, how I can get Stage field of Opportunity in Validation Rule.
I want something like:

If (WhatId.Stage = '4 Handover', Category__c!='Order', false)

public with sharing class Utils_SDF_Methodology {
.
.
.
    public static final String BypassVar;//List of triggers that can be bypassed
    
    static{
        System.Debug('## >>> Utils_SDF_Methodology constructor :BEGIN <<< run by ' + UserInfo.getName());
        User user=[SELECT UserRole.Name,Profile.Name,BypassTriggers__c FROM User WHERE Id =:UserInfo.getUserId() LIMIT 1];
        BypassVar=';'+user.BypassTriggers__c+';';
        System.Debug('## >>> Utils_SDF_Methodology constructor : END <<<');
    }
.
.
.
}

I have to write a Test Class in which I have to user runAs(userX){ inside of which I want static init block of above class should run.}

I have created below code in my TEST method:

        User LCRTestUser = Utils_TestMethods.createStandardUser('LCROwner');
        LCRTestUser.BypassTriggers__c = 'AP33;AP20;AP_Case_CaseHandlerCaseBeforeInsert;AP10;AP41'; 
        System.debug('LCRTestUser.BypassTriggers__c:'+LCRTestUser.BypassTriggers__c);
        //Insert LCRTestUser ;
        System.debug('UserInfo.getName():'+UserInfo.getName());
    system.runas(LCRTestUser) {
        Test.startTest();
        System.debug('runAs Started');
//        Test.startTest();
            System.debug('UserInfo.getName():'+UserInfo.getName());
                System.debug('Utils_SDF_Methodology.PAD_BypassTrigger:'+Utils_SDF_Methodology.PAD_BypassTrigger);

        Test.stopTest();

But still it is initializing with main user, Not the user which is in runAs().
            System.debug('UserInfo.getName():'+UserInfo.getName()); in TEST method is providing name of the user who is in runAs. Static init block is executing after runAs but before this debug and is considering actual user.

Can I do anything so that it will consider user mentioned in runAs in static initialization block?
I want to get data from external system by calling it's Web Service. And insert records in Salesforce with that data.
Now, the problem is there is limit of 10 Web Service call outs per Transaction. But in my scenario I have to create a Scheulable which will do too many call outs. (say 500 Web Service call outs). Like for each Account I want to get Billing Details for that account. So, in request I will be sending Account Details and in response I will be getting Billing Details for that account. So, if there are 500 accounts for which I have to get billing details then I have to call Web Service 500 times.
It has to be programmatic, not through CSV file, Data Loader, etc.

Is it even doable?
Nowhere I am able to get answer what Master Password is and what it is for. All other details are provided for master password but not what it is for.
Can someone please clarify why is it used for and will new master password will be generated eveytimr we start eclipse?
  Suppose we have an Object X and want that whenever user creates new record of this object or edit any record of this Object, after clicking on Save it should goto a Visualforce Page. Can this be done using Visual Workflow (Flow)?
Like when we click on column of pageblockTable to popup to filter or sort will come.

<apex:pageBlockTable value="{!wrapKey}" var="wrapKey1" width="20%" >
                            <apex:column headerValue="{!currField}" width="5%" onclick="showFilterPopUp(this)">
                                      <apex:outputField id="outputId" value="{!wrapKey1.sObj}" rendered="{! readOnly}"/>
                            </apex:column> 
</apex:pageBlockTable>

Here I want to click on Column header with apex:column where onclick is not working.
How to achieve it?
As I need coloring and styles of Case Tab to be in a Visualforce Page I am using tabStyle. Requirement is that when that page is loaded Home Tab should be selected (Not Case Tab). So I have used below pageBlock which is working:

<apex:pageBlock tabStyle="Case">

Now the problem is that if the user is not having access to Case Tab. The Page will throw an error mentioning user does not have permission to access Case Tab.

What can be the solution or workaround for this?
Can I somehow make Visualforce page to display this pageBlock without taking user permissions into consideration?
  • September 14, 2014
  • Like
  • 0
global class CustomIterable
   implements Iterator<Account>{

   List<Account> accs {get; set;}
   Integer i {get; set;}

   public CustomIterable(){
       accs =
       [SELECT Id, Name,
       NumberOfEmployees
       FROM Account
       WHERE Name = 'false'];
       i = 0;
   }  

   global boolean hasNext(){
       if(i >= accs.size()) {
           return false;
       } else {
           return true;
       }
   }   

   global Account next(){
       // 8 is an arbitrary
       // constant in this example
       // that represents the
       // maximum size of the list.
       //if(i == 8){return null;}
       i++;
       return accs[i-1];
   }
}

I have taking this from example and commented line: if(i == 8){return null;}
What this line is for?

Also below statement in constructor:
accs =
       [SELECT Id, Name,
       NumberOfEmployees
       FROM Account
       WHERE Name = 'false'];

will NOT select all records at once? If it fetches all records at once then there is no sense of using custom Iterator in Batch class.
  • September 12, 2014
  • Like
  • 0
I am getting numbers in respective language in Visualforce page from controller. Now I have to do fast calculations using those numbers. I am using javascript for that. Now, the problem is ho to read those numbers if user changes it. Suppose it is in Hindi.3500 will be displayed as ३,५०० and user can change it to ३,५५५ (3555). So what can I use to convert ३,५५५ to 3555.

If I do:

var number = 3500;
alert(number.toLocaleString("hi-IN"));
I will get ३,५०० in Hindi.

But how can I convert it back to 3500. I want something like:

var str='३,५००';
alert(str.toLocaleNumber("en-US"));
So, that it can give 3500.

Is it possible by javascript, jquery or any other free or paid library?

I tried jquery.numberformatter which is not working for this.
  • September 04, 2014
  • Like
  • 0
I have a search page where user use to search for products. There are lot of check boxes which help to perform correct search.
So, as user clicks on 1 product in search result next page is displayed with details of that particular code.
I have to create 1 back button from which previous search page will display with search result with chackboxes checked however they were, text fields have values whatever there was.  I don't want to use Query String.
Are there any other ways?
Suppose we have object ChildOfCase__c which has lookup to Case.
And an Object ToCreate__c have to get some values from case and then needs to be inserted after inserting any record in ChildOfCase__c.

So, can we do like: childOfCase.case__r.CaseSymptom1__c?
But when I am doing like this the records in ToCreate__c are not getting updated (just null values are there).

So, to get values from case then can we use

Below is the code in Trigger on ChildOfCase(after Insert):

List<ToCreate__c> rsList=new List<ToCreate__c>();
    for (ChildOfCase__c cr:Trigger.NEW) {
        if (cr.case__c!=null){
            ToCreate__c rs = new ToCreate__c(ChildOfCase__c=cr.id, Symptom1__c=cr.case__r.CaseSymptom1__c, Symptom2__c=cr.case__r.CaseSymptom2__c);
            rsList.add(rs);
        }
    }
   
    if (rsList.size()>0){
        insert rsList;
    }


Will it come in Trigger or we have to query separately for case?
Suppose I have Object Parent1 and Child1. Child1 is having lookup to Parent1.
Parent1 is having Standard Page Layout (Not Visualforce). Now, I want that whenever the user click on Save, with creating new Record of Parent1 it should also create new Record for Child1.

By default it will create record of Parent1 only. But with Parent1 I also want 1 record of Child1 to be created.

I don't want to convert whole Page to Visualforce Page.

What will be the best way to achieve this?
Is Trigger is the best way?
What are the other ways?

For NEW button we can goto Visualforce page which can forward you to standard page but for SAVE this thing we cannot do? Like when we click on Save it will save record and goto one Visualforce Page which will do it's processing then return back to Created Record or any default Page.

We cannot provide functionality in Standard Page Layout only? By Declarative approach or anything?
Below is my script to disable/enable commandButton:

<script>
function func(){
if (document.getElementById('{!$Component.form1.orderedCheckBox}').checked
     || document.getElementById('{!$Component.form1.receivedCheckBox}').checked) {
         document.getElementById('{!$Component.form1.cButton}').disabled=false
         document.getElementById('{!$Component.form1.cButton}').setAttribute('class','btn');
} else {
         document.getElementById('{!$Component.form1.cButton}').disabled=true
         document.getElementById('{!$Component.form1.cButton}').setAttribute('class','btnDisabled');
}
}
</script>

So, indirectly is is disabling HTML commandButton (to which apex:commandButton is converted but Salesforce Controller will not know that).
Suppose if we do:

<apex:commandButton id="cButton" value="Click Here" action="{!method1}"
            disabled="true"/>

In this case javaScript will make it visible and clickable on HTML page if we check any checkbox but it will never call method method1() of Controller because according to Salesforce it is disabled and so redirect to same page without showing anything (any error or debug or anything).

So, it doesn't seem to be correct method and I don't want to use actionSupport for this as the effect will be delayed. Like when we uncheck a checkbox. It will take little time to make button disable. Also, I don't want to make communication through Salesforce happen only for this thing.

JQuery will also be doing same thing. It will not be changing real <apex:commandButton> but commandButton in HTML which Salesforce Server will not consider.

Also, I know from javaScript Console that we have to change class to 'btnDisabled' or 'btn'.
If in future Salesforce change the class names it uses my code will fail. So, assigning class to it also doesn't seem to be correct but without it the appearance will not change. Disabled commandButton will look like Enabled.

So, Is there any better/correct way to do this?
I am writing a wrapper class to to show atmost 100 elements of list using offset:

class Pg{
    public Integer displayLimit{get;set;}
    public Integer displayOffset{get;set;}
    public Boolean disableNext{get;set;}
    public Boolean disablePrev{get;set;}
    List collection;
   
    public Pg(){}
    public Pg(List collection){
        this.collection=collection;
        this.displayOffset=0;
        this.displayLimit=100;
        this.disablePrev=true;
        if (this.collection.size()>displayLimit) {
            this.disableNext=false;
        } else {
            this.disableNext=true;
        }
    }
   
    public void next(){
        this.displayOffset=this.displayOffset+displayLimit;
        if (this.collection.size()<displayOffset+displayLimit) {
            this.disableNext=true;
        }
        this.disablePrev=false;
    }

    public void prev(){
        this.displayOffset=this.displayOffset-displayLimit;
        if (this.displayOffset==0) {
            this.disablePrev=true;
        }
        this.disableNext=false;
    }
   
}

But here it is not allowing me to give List collection;
It needs something like List<Object> collection. Expecting Angle bracket after List.

But I want that I should able to pass List of any collection in constructor.

How to achieve this?
Suppose Object Obj__c having 3 fields: Field1__c, Field2__c and Field3__c.
Suppose we do Obj__c obj1=[select Field1__c from Obj1__c where id=:someId]; //Suppose all fields are hainvg value.
obj1.Field2='ABCD';
update obj1;

Now, problem here is Field3__c is nullified.

So, do we have to give all fields in SOQL if we want to update that object (even for 1 field)?
Any solution is there if I don't want to select all fields? Or any other way is there?

I have to customize edit, view, delete for Attachments in Opportunity Page Layout.

On delete button I have following lines in Visualforce Page:

<apex:commandLink styleClass="ankit" value="del" onclick="return confirm('Are you sure?')" action="{!delAttachAndNote}" > <apex:param name="attachId" value="{!item.Id}" assignTo="{!delId}" /> </apex:commandLink>

And below is code in Apex class which is "with sharing":

 public String delId{get;set;}
 public void delAttachAndNote(){
        Database.delete(delId);     
}

I tried changing it to delete new Attachment(Id=delId), etc. But still no luck.

Why Salesforce is not taking care of permissions here and Is there any alternative? Also, we cannot get URL for deleting Attachment or Notes.

Seeing Salesforce Procing I don't think it is possible. As anyone can join the website and we have to pay huge license fee for that new user. After that the user may post a lot  of content into Salesforce which may reach the Salesforce limit and so we need to perform additional licenses.
Just wanted to confirm that we cannot build a Social Networking site in Salesforce.
I am getting numbers in respective language in Visualforce page from controller. Now I have to do fast calculations using those numbers. I am using javascript for that. Now, the problem is ho to read those numbers if user changes it. Suppose it is in Hindi.3500 will be displayed as ३,५०० and user can change it to ३,५५५ (3555). So what can I use to convert ३,५५५ to 3555.

If I do:

var number = 3500;
alert(number.toLocaleString("hi-IN"));
I will get ३,५०० in Hindi.

But how can I convert it back to 3500. I want something like:

var str='३,५००';
alert(str.toLocaleNumber("en-US"));
So, that it can give 3500.

Is it possible by javascript, jquery or any other free or paid library?

I tried jquery.numberformatter which is not working for this.
  • September 04, 2014
  • Like
  • 0
Suppose we have object ChildOfCase__c which has lookup to Case.
And an Object ToCreate__c have to get some values from case and then needs to be inserted after inserting any record in ChildOfCase__c.

So, can we do like: childOfCase.case__r.CaseSymptom1__c?
But when I am doing like this the records in ToCreate__c are not getting updated (just null values are there).

So, to get values from case then can we use

Below is the code in Trigger on ChildOfCase(after Insert):

List<ToCreate__c> rsList=new List<ToCreate__c>();
    for (ChildOfCase__c cr:Trigger.NEW) {
        if (cr.case__c!=null){
            ToCreate__c rs = new ToCreate__c(ChildOfCase__c=cr.id, Symptom1__c=cr.case__r.CaseSymptom1__c, Symptom2__c=cr.case__r.CaseSymptom2__c);
            rsList.add(rs);
        }
    }
   
    if (rsList.size()>0){
        insert rsList;
    }


Will it come in Trigger or we have to query separately for case?
Suppose I have Object Parent1 and Child1. Child1 is having lookup to Parent1.
Parent1 is having Standard Page Layout (Not Visualforce). Now, I want that whenever the user click on Save, with creating new Record of Parent1 it should also create new Record for Child1.

By default it will create record of Parent1 only. But with Parent1 I also want 1 record of Child1 to be created.

I don't want to convert whole Page to Visualforce Page.

What will be the best way to achieve this?
Is Trigger is the best way?
What are the other ways?

For NEW button we can goto Visualforce page which can forward you to standard page but for SAVE this thing we cannot do? Like when we click on Save it will save record and goto one Visualforce Page which will do it's processing then return back to Created Record or any default Page.

We cannot provide functionality in Standard Page Layout only? By Declarative approach or anything?
Below is my script to disable/enable commandButton:

<script>
function func(){
if (document.getElementById('{!$Component.form1.orderedCheckBox}').checked
     || document.getElementById('{!$Component.form1.receivedCheckBox}').checked) {
         document.getElementById('{!$Component.form1.cButton}').disabled=false
         document.getElementById('{!$Component.form1.cButton}').setAttribute('class','btn');
} else {
         document.getElementById('{!$Component.form1.cButton}').disabled=true
         document.getElementById('{!$Component.form1.cButton}').setAttribute('class','btnDisabled');
}
}
</script>

So, indirectly is is disabling HTML commandButton (to which apex:commandButton is converted but Salesforce Controller will not know that).
Suppose if we do:

<apex:commandButton id="cButton" value="Click Here" action="{!method1}"
            disabled="true"/>

In this case javaScript will make it visible and clickable on HTML page if we check any checkbox but it will never call method method1() of Controller because according to Salesforce it is disabled and so redirect to same page without showing anything (any error or debug or anything).

So, it doesn't seem to be correct method and I don't want to use actionSupport for this as the effect will be delayed. Like when we uncheck a checkbox. It will take little time to make button disable. Also, I don't want to make communication through Salesforce happen only for this thing.

JQuery will also be doing same thing. It will not be changing real <apex:commandButton> but commandButton in HTML which Salesforce Server will not consider.

Also, I know from javaScript Console that we have to change class to 'btnDisabled' or 'btn'.
If in future Salesforce change the class names it uses my code will fail. So, assigning class to it also doesn't seem to be correct but without it the appearance will not change. Disabled commandButton will look like Enabled.

So, Is there any better/correct way to do this?
I am writing a wrapper class to to show atmost 100 elements of list using offset:

class Pg{
    public Integer displayLimit{get;set;}
    public Integer displayOffset{get;set;}
    public Boolean disableNext{get;set;}
    public Boolean disablePrev{get;set;}
    List collection;
   
    public Pg(){}
    public Pg(List collection){
        this.collection=collection;
        this.displayOffset=0;
        this.displayLimit=100;
        this.disablePrev=true;
        if (this.collection.size()>displayLimit) {
            this.disableNext=false;
        } else {
            this.disableNext=true;
        }
    }
   
    public void next(){
        this.displayOffset=this.displayOffset+displayLimit;
        if (this.collection.size()<displayOffset+displayLimit) {
            this.disableNext=true;
        }
        this.disablePrev=false;
    }

    public void prev(){
        this.displayOffset=this.displayOffset-displayLimit;
        if (this.displayOffset==0) {
            this.disablePrev=true;
        }
        this.disableNext=false;
    }
   
}

But here it is not allowing me to give List collection;
It needs something like List<Object> collection. Expecting Angle bracket after List.

But I want that I should able to pass List of any collection in constructor.

How to achieve this?
Suppose Object Obj__c having 3 fields: Field1__c, Field2__c and Field3__c.
Suppose we do Obj__c obj1=[select Field1__c from Obj1__c where id=:someId]; //Suppose all fields are hainvg value.
obj1.Field2='ABCD';
update obj1;

Now, problem here is Field3__c is nullified.

So, do we have to give all fields in SOQL if we want to update that object (even for 1 field)?
Any solution is there if I don't want to select all fields? Or any other way is there?
I have to do something like this:

Object__c obj;    //Initiated in Constructor
List<String> fieldNames=new List<String>{'Field1__c, Field2__c, Field3__c};

for (String str: fieldNames) {
obj.<str>=null
}
update obj;

So, it will be obj.Field1__c=null; obj.Field2__c=null ...

Can we do this in Salesforce Apex?
I have to iterate through each element in pageBlockTable and if no element's checkbox is checked then I have to disable Submit Button in runtime without submitting the form.

Below is my snippet of Visualforce page:
The line:
var curr=document.getElementbyID('{!$Component.formId.pageBlockId.pageBlockTableId[i].headerId.checkBoxId}').value;
is having error: Unknown property 'StandardController.i'
Then how to get checked of each element in pageBlockTable.
What is the correct way rather than work around solution? Without changing pageBlockTable and without using any 3rd party tool.

<apex:form id="formId">
                <apex:pageBlock id="pageBlockId">
                   <apex:pageBlockTable value="{!displayToSelect}" var="disp" id="pageBlockTableId">
                       <apex:column headerValue="Commercial Reference" style="text-align:center;">
                                <apex:outputLabel value="{!disp.cr.Field1__c}"/>
                       </apex:column>

                       <apex:column headerValue="Status">
                                <apex:outputText value="{!disp.status}"/>
                       </apex:column>
                     
                       <apex:column headerValue="Add This?" id="headerId">
                            <apex:inputCheckbox value="{!disp.check}" onChange="checkEnableDisable()" id="checkboxId"/>
                       </apex:column>

                   </apex:pageBlockTable>
                 
             </apex:pageBlock>
                   <apex:commandButton value="Submit" action="{!submitRecords}" disabled="{!disableSubmit}" id="submitId"/>
</apex:form>

<script>

checkEnableDisable(){
    var allUnchecked=true;
    var list=document.getElementbyID('{!$Component.formId.pageBlockId.pageBlockTableId}');
    for (var i=0;i<list.length;i++){
        var curr=document.getElementbyID('{!$Component.formId.pageBlockId.pageBlockTableId[i].headerId.checkBoxId}').value;
        if (curr==true){
            allunchecked=false;
        }
    }
    document.getElementbyID('{!$Component.formId.submitId}').setAttribute('disabled',alluNchecked);
}

</script>
For a Master-Detail or Look Up relationship. First query simply matches ID (for lookup or master-detail field) whereas second one gets all records of detail from Master ID record. So, at last both will return same records. Only fetching them will be little different. So, which one should I use and which one will give better performance?

[select id, DetailObjField__c from DetailObj__c where Master__c=:MasterId]

OR

[select id,(select DetailObjField__c from DetailObj__r) from Master__c where Master__c.id=:MasterId]

how to create composite key pls help me.

  • September 24, 2013
  • Like
  • 0

Dear All,

 

Could you help by providing a test class for my trigger and APEX classes ?

 

I can't get any coverage when i run my test class.

 

Trigger:

 

trigger UserCreationBeforeUpdate on UserCreationDetail__c (before update) {
    System.Debug('## >>> User before update <<< run by ' + UserInfo.getName());

    /*********************************************************************************************
     AP41UserCreation 
        Create/Update . Designed for VF40_UserRequestProcess
    **********************************************************************************************/
    if(PAD.canTrigger('AP64')){
        System.Debug('## AP64UserProcess begin prepare');   
        List<UserCreationDetail__c> ap64UserCreation = new List<UserCreationDetail__c>();
        
        //List<UserCreationDetail__c> ap64UserUpdate = new List<UserCreationDetail__c>();
        
        Set<Id> ap64UserUpdate = new Set<Id>();
            
        for(UserCreationDetail__c usr: Trigger.new) {
            if (usr.Status__c != Trigger.OldMap.get(usr.id).Status__c && usr.Status__c == 'Implemented') {
                if (usr.Type__c == 'Creation') {
                    ap64UserCreation.add(usr);
                } else {
                    //ap64UserUpdate.add(usr);
                    ap64UserUpdate.add(usr.id);
                }
            }
        }
            
        System.Debug('## AP64UserProcess end prepare');
        
        if(ap64UserCreation.size() > 0)
            AP64UserManagementProcess.createUser(ap64UserCreation);
                
        if(ap64UserUpdate.size() > 0)
            AP64UserManagementProcess.updateUser(ap64UserUpdate);
    
        System.Debug('## >>> User Creation before update : END <<<');
    }
}

 APEX:

 

public class AP64UserManagementProcess {
    //static List<User> usersToUpdate = new List<User>();
    public static void createUser(List<UserCreationDetail__c> users) {
        List<User> usersToInsert = new List<User>();
        try {
            for (UserCreationDetail__c userRequest: users) {
                User user = new User();
                user.EmployeeNumber             =             userRequest.EmployeeNumber__c ;
                user.FirstName                  =             userRequest.FirstName__c ;
                user.LastName                   =             userRequest.LastName__c ;
                user.Email                      =             userRequest.Email__c ;
                user.username                   =             userRequest.username__c ;
                user.UserRoleId                 =             userRequest.RoleId__c ;               
                user.ProfileId                  =             userRequest.ProfileId__c ;
                user.TechManagerId__c           =             userRequest.Manager__c ;
                user.Title                      =             userRequest.Title__c ;
                user.CompanyName                =             userRequest.CompanyName__c ;
                user.Department                 =             userRequest.Department__c ;
                user.Division                   =             userRequest.Division__c ;
                user.EmailEncodingKey           =             userRequest.EmailEncoding__c ;
                user.userCountry__c             =             userRequest.userMainCountry__c ;
                user.userArea__c                =             userRequest.userMainArea__c ;
                user.ISORegion__c               =             userRequest.userMainRegion__c ;
                user.userMainCountrySubArea__c  =             userRequest.userMainCountrySubArea__c ;
                user.userSubRegion__c           =             userRequest.userMainSubRegion__c ;
                user.OtherRegions__c            =             userRequest.OtherRegions__c ;
                user.KeyuserType__c             =             userRequest.KeyuserType__c ;
                user.Champion__c                =             userRequest.Champion__c ;
                user.userProductLine__c         =             userRequest.userMainProductLine__c ;
                user.userUnit__c                =             userRequest.userMainUnit__c ;
                user.FinancialUnitId__c         =             userRequest.FinancialUnitId__c ;
                user.eLearning__c               =             userRequest.eLearning__c ;
                user.OtherProductLines__c       =             userRequest.OtherProductLines__c ;
                user.TimeZoneSidKey             =             userRequest.TimeZone__c ;
                user.LocaleSidKey               =             userRequest.Language__c ;
                user.LanguageLocaleKey          =             userRequest.Locale__c ;
                user.CurrencyIsoCode            =             userRequest.Currency__c ;
                user.CarveOutComments__c        =             userRequest.Comments__c ;
                user.Alias                      =             userRequest.Alias__c ;
                user.CommunityNickname          =             userRequest.CommunityNickname__c ;
                user.UserPermissionsMobileUser = false;
                usersToInsert.add(user);
            }
                
            //Create users
            insert usersToInsert;
            
            //RESET PASSWORD
            for (User u: usersToInsert)
                System.resetPassword(u.Id, true);
        } catch (DmlException e) {
            system.debug(Logginglevel.ERROR, e);
        } 
    }
    
    @future
    public static void updateUser(Set<Id> userDetail) {
        try {
            for (Id userId : userDetail) {
                UserCreationDetail__c userRequest = [SELECT Email__c,EmployeeNumber__c,FirstName__c,LastName__c,RoleId__c,ProfileId__c,
                                                    Manager__c,Title__c,CompanyName__c,Department__c,Division__c,EmailEncoding__c,userMainCountry__c,
                                                    userMainArea__c,userMainRegion__c,userMainCountrySubArea__c,userMainSubRegion__c,OtherRegions__c,
                                                    KeyuserType__c,Champion__c,userMainProductLine__c,userMainUnit__c,FinancialUnitId__c,eLearning__c,
                                                    OtherProductLines__c,TimeZone__c,Language__c,Locale__c,Currency__c,Comments__c,Alias__c,CommunityNickname__c
                                                     FROM UserCreationDetail__c WHERE Id = :userId];
                User user = [SELECT Id FROM User WHERE Email = :userRequest.Email__c LIMIT 1];
                user.EmployeeNumber             =             userRequest.EmployeeNumber__c ;
                user.FirstName                  =             userRequest.FirstName__c ;
                user.LastName                   =             userRequest.LastName__c ;
                //user.Email                      =             userRequest.Email__c ;
                //user.username                   =             userRequest.username__c ;
                user.UserRoleId                 =             userRequest.RoleId__c ;               
                user.ProfileId                  =             userRequest.ProfileId__c ;
                user.TechManagerId__c           =             userRequest.Manager__c ;
                user.ManagerId                  =             userRequest.Manager__c ;
                user.Title                      =             userRequest.Title__c ;
                user.CompanyName                =             userRequest.CompanyName__c ;
                user.Department                 =             userRequest.Department__c ;
                user.Division                   =             userRequest.Division__c ;
                user.EmailEncodingKey           =             userRequest.EmailEncoding__c ;
                user.userCountry__c             =             userRequest.userMainCountry__c ;
                user.userArea__c                =             userRequest.userMainArea__c ;
                user.ISORegion__c               =             userRequest.userMainRegion__c ;
                user.userMainCountrySubArea__c  =             userRequest.userMainCountrySubArea__c ;
                user.userSubRegion__c           =             userRequest.userMainSubRegion__c ;
                user.OtherRegions__c            =             userRequest.OtherRegions__c ;
                user.KeyuserType__c             =             userRequest.KeyuserType__c ;
                user.Champion__c                =             userRequest.Champion__c ;
                user.userProductLine__c         =             userRequest.userMainProductLine__c ;
                user.userUnit__c                =             userRequest.userMainUnit__c ;
                user.FinancialUnitId__c         =             userRequest.FinancialUnitId__c ;
                user.eLearning__c               =             userRequest.eLearning__c ;
                user.OtherProductLines__c       =             userRequest.OtherProductLines__c ;
                user.TimeZoneSidKey             =             userRequest.TimeZone__c ;
                user.LocaleSidKey               =             userRequest.Language__c ;
                user.LanguageLocaleKey          =             userRequest.Locale__c ;
                user.CurrencyIsoCode            =             userRequest.Currency__c ;
                user.CarveOutComments__c        =             userRequest.Comments__c ;
                user.Alias                      =             userRequest.Alias__c ;
                user.CommunityNickname          =             userRequest.CommunityNickname__c ;
                user.IsActive = true;
                
                update user;
            }
                
            //RESET PASSWORD
            /*for (User u: usersToUpdate)
                System.resetPassword(u.Id, true);*/
        } catch (DmlException e) {
            system.debug(Logginglevel.ERROR, e);
        } 
    }
}

 

Thank's for help,

 

All the best,

 

Anzar.

  • September 22, 2012
  • Like
  • 0