• ashii
  • NEWBIE
  • 50 Points
  • Member since 2010

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 7
    Replies

Hi i m new to salesforce i just want to know the structure  of apex cde how to develop,can any one help me.Thanks in Advance

I'm getting stuck on referencing unrelated tables using a SOQL query.

 

For example I have a Leads table that has a country field, and I need to reference to a Mapping Table that contains the currency code for the country, and update the lead's currency code with the value from the Mapping table.  How would I approach this?

 

I started with a map that looks like this:  LeadMap<id, string> where the id is the lead's id and the string contains the country code.  I'm not sure how to approach the rest of the problem as I really need to end up with a map of <id,id> that contains the lead Id and the currency id.

 

Any help will be greatly appreciated.

hi all,

 

 

 

I have a scenario, please find the details below:

 

 

 

If a user record "insert" then I'll call a "trigger" (Say T1) on "after insert".

 

In trigger T1 I'll call a global class (say GC1), from this global class I'll call a Batch Apex class (say BAC1).

 

I have already put a limit to my batch (size = 50).

 

Because I have seen in forum that we can execute only 200 records in test class. So anyway this scenario is covered with my batch size limit , which is only 50.

 

 

 

eg: Database.execute(BAC1,50)

 

 

 

But then also I am getting below error

 

------------------------------------------------------

 

System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.

 

------------------------------------------------------

 

  

 

Please note that, I have already placed a global variable which will stop the recursive trigger. Otherwise you might be thinking when I update the user record it will call the trigger again and it will go to a recursive call. This is already handled using a global variable. The global variable will be NULL first time, after that it will set to TRUE. So the trigger execute only once if global variable is NULL.

 

  

 

  

 

Hope some body can help me out to solve this issue.

 

  

 

Trigger Code

 

------------

 

 trigger RollupValues on User (after insert,after update) {
    if(RollupValues.IsNoTrigger == null)
    {
        List<Profile> WaterProf = [Select Id from Profile where name = 'Profile Sales'];
        for(User us : Trigger.New)
        {
            //**** Trigger only if the profile is "Profile Sales"
            if(us.ProfileId == WaterProf[0].Id)
            {
                RollupValues.UpdateRollupValues(Trigger.New);   
            }   
        }   
    }       
}

 

---------------

 

  

 

Global Class Code

 

---------------

 

  Global class RollupValues
{
    public static Boolean IsNoTrigger{get;set;}
    //public  {get;set;}
    public static void UpdateRollupValues(User[] users)
    {
      
        //**** Check the global variable to avoid recursive trigger
        system.debug('Global value:'+RollupValues.IsNoTrigger);       
        if(RollupValues.IsNoTrigger == null)
        {
            //**** Call batch update class to update the Rollupvalues
            string bquery = 'Select id,userroleId,ManagerId from User where Profile.Name = '+ '\'' + 'Profile Sales' + '\'';
  //**** Call Batch apex class
            BatchRollupValues objbatchupdate = new BatchRollupValues();
            objbatchupdate.query = bquery;
            Database.executeBatch(objbatchupdate,50);
 }
     }
}

---------------

 

  

 

Thanks in advance!

 

  

 

ashii

 

 

 

  • December 08, 2010
  • Like
  • 0

Hello. I am running into problems trying to update a single member of a list...and wondered if anyone could point me in the right direction.

 

I am displaying an editable list of results from a search query called "recordsList".  I have inserted a CommandButton command in the VF page so a "save this record change" button is displayed next to each member of this list (I know I could simply place a button at the bottom of the overall list to resave the entire list - but I instead want to provide the ability to save individual records).

 

The below controller code works fine when just one search result is displayed - but it does not save the desired record when "recordsList" displays multiple records.

 

Below is the controller code I am using.  I had hoped that the "[0]" piece of code would allow me to address individual members of the list - but I am obviously wrong.

 

Any suggestions would be greatly appreciated.  Thanks.

 

CONTROLLER CODE

 

Public PageReference SaveThisRecord() {
{
update recordsList[0};
}
return null;
}

can any one tel me about Map in Apex code

canany one tel me structure of apex code

Hi i m new to salesforce i just want to know the structure  of apex cde how to develop,can any one help me.Thanks in Advance

I'm getting stuck on referencing unrelated tables using a SOQL query.

 

For example I have a Leads table that has a country field, and I need to reference to a Mapping Table that contains the currency code for the country, and update the lead's currency code with the value from the Mapping table.  How would I approach this?

 

I started with a map that looks like this:  LeadMap<id, string> where the id is the lead's id and the string contains the country code.  I'm not sure how to approach the rest of the problem as I really need to end up with a map of <id,id> that contains the lead Id and the currency id.

 

Any help will be greatly appreciated.

hi all,

 

 

 

I have a scenario, please find the details below:

 

 

 

If a user record "insert" then I'll call a "trigger" (Say T1) on "after insert".

 

In trigger T1 I'll call a global class (say GC1), from this global class I'll call a Batch Apex class (say BAC1).

 

I have already put a limit to my batch (size = 50).

 

Because I have seen in forum that we can execute only 200 records in test class. So anyway this scenario is covered with my batch size limit , which is only 50.

 

 

 

eg: Database.execute(BAC1,50)

 

 

 

But then also I am getting below error

 

------------------------------------------------------

 

System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.

 

------------------------------------------------------

 

  

 

Please note that, I have already placed a global variable which will stop the recursive trigger. Otherwise you might be thinking when I update the user record it will call the trigger again and it will go to a recursive call. This is already handled using a global variable. The global variable will be NULL first time, after that it will set to TRUE. So the trigger execute only once if global variable is NULL.

 

  

 

  

 

Hope some body can help me out to solve this issue.

 

  

 

Trigger Code

 

------------

 

 trigger RollupValues on User (after insert,after update) {
    if(RollupValues.IsNoTrigger == null)
    {
        List<Profile> WaterProf = [Select Id from Profile where name = 'Profile Sales'];
        for(User us : Trigger.New)
        {
            //**** Trigger only if the profile is "Profile Sales"
            if(us.ProfileId == WaterProf[0].Id)
            {
                RollupValues.UpdateRollupValues(Trigger.New);   
            }   
        }   
    }       
}

 

---------------

 

  

 

Global Class Code

 

---------------

 

  Global class RollupValues
{
    public static Boolean IsNoTrigger{get;set;}
    //public  {get;set;}
    public static void UpdateRollupValues(User[] users)
    {
      
        //**** Check the global variable to avoid recursive trigger
        system.debug('Global value:'+RollupValues.IsNoTrigger);       
        if(RollupValues.IsNoTrigger == null)
        {
            //**** Call batch update class to update the Rollupvalues
            string bquery = 'Select id,userroleId,ManagerId from User where Profile.Name = '+ '\'' + 'Profile Sales' + '\'';
  //**** Call Batch apex class
            BatchRollupValues objbatchupdate = new BatchRollupValues();
            objbatchupdate.query = bquery;
            Database.executeBatch(objbatchupdate,50);
 }
     }
}

---------------

 

  

 

Thanks in advance!

 

  

 

ashii

 

 

 

  • December 08, 2010
  • Like
  • 0