• devendra dhaka
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 28
    Replies

 

I want to add a record to my object BD which is having a single field 'Name' using apex class.

The Scenario is like this -

A object 'Employee' is having field 'Emp_name' and 'Date' and if the Date for a particular record is equal to TODAY's date then a record should be added in object 'BD' with the matching name from Employee.

I will perform the scheduling using 'Schedule Apex' for daily .

 

Actually i have to do scheduling thats why i have to use Apex Class.

 

Thanks in Advance.

Pranay

  • April 16, 2012
  • Like
  • 0

I am using action function as a function to load on the pageLOAD.

 

If i use a normal javascript function, it's working fine.

 

but with this actionFunction, 'm getting a blank page.

 

Correct me :)

 

 

<apex:form >
    <apex:actionFunction name="currentMonthLoad" reRender="Caption1">
    
    alert("was here once");
    </apex:actionFunction>
    </apex:form>

 

 

    function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  {
     window.onload = func;
  }
  else
  {
      window.onload = function()
      {
        if (oldonload)
        {
           oldonload();
        }
        func();
      }
   }
}
   
addLoadEvent(function()     
{
 
   currentMonthLoad();
  
});

<apex:page showHeader="false" sidebar="false" >

 

When I put showHeader and sidebar = True

 

onLoad of BODY tag stopped working, otherwise it's working fine.

 

Why is this happening ??

I have written a vf page.

 

Initally I used normal HTML button, so it was working properly. But as per my functionality need I changed it to commandbutton. Now 'm calling a method using ACTION and simultaneously a onclick javascript method.

 

It first performs the javascript method and then does the action call.

 

The issue 'm facing that it reloads the page and all the javascript variable gets reinitialized.

 

How can I prevent that ??

I have to store the variables to their states.

 

Thanks in advance.

global class InsertDefaultLeaveBalanceForNewUserClass
   {
    
    Static List<Leave_Balance__c> leaveBalanceList = new List<Leave_Balance__c>();
    
    @future
     Global Static void createLeaveBalance(Id userId,Decimal defaultLeave,ID leaveTypeID)
      {
          Leave_Balance__c lb = new Leave_Balance__c();
                lb.Employee_Name__c=userId;
                lb.LeaveType__c=leaveTypeID;
                lb.Leave_Credit__c=defaultLeave;
                  
                leaveBalanceList.add(lb);
                system.debug(leaveBalanceList.Size());     // it always gives list size to 1
               
      
      }
   
    Global Static void insertLeaveBalance()
       {
         system.debug(leaveBalanceList.size());      // here always the list size is 0
         insert leaveBalanceList;
       
       }
   
   }

 

 

How can I modify this code to insert the records ??

I have to convert GMT time to local time as per timezonekey

 

datetime GMTDate = datetime.now();
 String strConvertedDate = GMTDate.format('MM/dd/yyyy hh:mm a',TimeZoneSidKey );

 

 

Using above approch I can create a String, But not DateTime.

 

If I use format or value methods, they convert back this String to GMT time.

 


 


trigger DeleteAllLeaveBalanceRecordForThisLeaveType on LeaveType__c (before delete) {
 
  set<id> ltList = Trigger.oldMap.keyset();
     
   if(trigger.isDelete)
   {
      
     
      List<Leave_Balance__c> LBList = [SELECT id FROM Leave_Balance__c WHERE LeaveType__c IN : ltList ];
      delete LBList;  
     
   }
 
}

 

 

This is my code for delete leave balance rows. If I undelete the leave_type record , how can i undelete the leave balance records??

 

 

 

if(trigger.isunDelete)
   {
      
     
      List<Leave_Balance__c> LBList = [SELECT id FROM Leave_Balance__c WHERE LeaveType__c IN : ltList ];
      undelete LBList;  
     
   }

 

Will this code work if I attach it to the trigger ??

I have to create a custom button to print the record.

 

Any suggestions ??

 

Can I create a custom button to print a record ??

 

I have to allow my customers to print their records .

 

We can achieve this in standard salesforce layout using ' printable view '

 

Thanks in advance  :)

 

 

 

 List<Id> ltFromLeavePolicy = new List<Id>();
                  for(Leave_Policy__c lp :additionalLeavePolicy)
                           ltFromLeavePolicy.add(lp.LeaveType__c);

 

List<Leave_Balance__c> lbList = [SELECT Leave_Credit__c FROM Leave_Balance__c WHERE LeaveType__c in : ltFromLeavePolicy];

 

 

Above SOQL query is fetching a large amout of records which is bursting limits. Can we fetch records in batches ??

I am tryin to create a MAP

 

Map<LeaveType__c,Leave_Policy__c> additionalLeavePolicy =new Map<LeaveType__c,Leave_Policy__c>([ SELECT Maximum_Allowed_Credit_for_Leave_Type__c,LeaveType__c,Next_Execution_Date__c,Action_Taken__c FROM Leave_Policy__c WHERE RecordType.Name='Additional Leave Policy']);

 Set <LeaveType__c> lt = additionalLeavePolicy.keyset();
 system.debug(lt.size);

 

will it work ??

 

AS

 

Map<ID,User> Usr = new Map<ID,User>([SELECT  name,TITLE FROM User WHERE Id IN : ownerIdList]);

 

IT WORKS  ??

I am not getting a proper ID

 

 

 

!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}

var newRecords = [];
 
var c = new sforce.SObject("Leave_Balance__c");

result1 = sforce.connection.query("Select Id from Leave_Balance__c where Employee_Name__c= '{!Leave_Application__c.OwnerId}' and LeaveType__c='{!Leave_Application__c.LeaveType__c}'  limit 1");          
//   LeaveType__c   is a reference { look up } to another object....    but it's giving some error , but it works fine in SOQL query in apex ??

records = result1.getArray("records");
if (records.length == 1) {
    var record = records[0];
  Id = (record.id);
alert(id);                                        

                          // here my id is some ext-gen1   ??
} else {
  alert("Something went wrong here");
}

I have to write down a Detail page button which will be fetching information from the current record and will be updating another custom object .

 

'm able to find information on List Page Buttons , but nothing for this  :(

 

Any help will be appreciated :)

I have two page layouts.

 

After approval prcoess , IF APPROVED, I want to change the page layout associated with the record types.

 

How can i achieve this functionality ??

 

Thanks in Advance.



i AM CREATING A QUEUE USING Group and queuesobject   . standard objects.


in the "queuesobject" there is a field 'sobjectType' where we associate supported objects to the queue.


But using apex code we are only able to attach a single object to it..



queuesobject q = new queuesobject (queueid=groupt.id, sobjecttype='test__c');   ///  this line




how can we achieve this...

I AM USING THIS CODE IN A TRIGGER TO AUTOMATE CREATION OF THE QUEUES .



Group g=new Group(Name='hello', Type='QUEUE');
insert g;


QueuesObject q= new QueuesObject (queueid=g.id, sobjectType='lead');

insert q;    ///   error is represented in this line


I am using this trigger on an object insertion.


If i use the same code in a visualforce page using apex controller, it works....


thanks in advance....

can someone help with a popup alert in a custom object once a checkbox box field is ticked .

i am looking to ask the user if they really want to tick the field .

 

  • May 07, 2012
  • Like
  • 0

I am using action function as a function to load on the pageLOAD.

 

If i use a normal javascript function, it's working fine.

 

but with this actionFunction, 'm getting a blank page.

 

Correct me :)

 

 

<apex:form >
    <apex:actionFunction name="currentMonthLoad" reRender="Caption1">
    
    alert("was here once");
    </apex:actionFunction>
    </apex:form>

 

 

    function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  {
     window.onload = func;
  }
  else
  {
      window.onload = function()
      {
        if (oldonload)
        {
           oldonload();
        }
        func();
      }
   }
}
   
addLoadEvent(function()     
{
 
   currentMonthLoad();
  
});

I have written a vf page.

 

Initally I used normal HTML button, so it was working properly. But as per my functionality need I changed it to commandbutton. Now 'm calling a method using ACTION and simultaneously a onclick javascript method.

 

It first performs the javascript method and then does the action call.

 

The issue 'm facing that it reloads the page and all the javascript variable gets reinitialized.

 

How can I prevent that ??

I have to store the variables to their states.

 

Thanks in advance.

global class InsertDefaultLeaveBalanceForNewUserClass
   {
    
    Static List<Leave_Balance__c> leaveBalanceList = new List<Leave_Balance__c>();
    
    @future
     Global Static void createLeaveBalance(Id userId,Decimal defaultLeave,ID leaveTypeID)
      {
          Leave_Balance__c lb = new Leave_Balance__c();
                lb.Employee_Name__c=userId;
                lb.LeaveType__c=leaveTypeID;
                lb.Leave_Credit__c=defaultLeave;
                  
                leaveBalanceList.add(lb);
                system.debug(leaveBalanceList.Size());     // it always gives list size to 1
               
      
      }
   
    Global Static void insertLeaveBalance()
       {
         system.debug(leaveBalanceList.size());      // here always the list size is 0
         insert leaveBalanceList;
       
       }
   
   }

 

 

How can I modify this code to insert the records ??

hi...,

can i find the solution for the triggers concept

 

my aim was to save the email domine name for the contact object in the custom field when it is inserted or updated

Greetings,

 

Just curious if there is a one line way to declare a list and addAll values from a set to that list.

 

I currently have:

 

ID[] toDel = New ID[]{};
            toDel.addAll(PVtoExternalIDs.keySet());
            database.delete(toDel);

 

 

I would like to convert the keySet to a list and not have the other tow lines. Kind of like:

 

database.delete(New ID[]{map.keySet()});

 

but that does not work obviously....



I need to connect each of my Salesforce opportunities with my payment and billing system.

My system works in client / server mode is not clud and handle my database is Firebird.


I have to do is validate my every opportunity closed won, with the payments recorded on my system. automatically want to see in the salesforce payment if the customer has the opportunity.



Can you tell me where to start, since I have little programming with apex.


Thanks for your help

 
  • April 28, 2012
  • Like
  • 0

I have a query that i want to run which only returns records whose custom string field value is not within the keyset of a map. 

 

The trick is populating the map with thousands of records.

 

The problem i'm having is i'm running into heap size limits while trying to populate the map. If i can just populate that map within one instantiation/population line of code, i can avoid the heap size exception.

 

Example below:

 

Map<String, Custom_Object__c> myMap = new Map<String, Custom_Object__c>([Select Custom_Field__c From Custom_Object__c Where Custom_Field__c != null limit 50000]);

 

This will instantiate & populate the map with key value pairs on one line, and i avoid the heap exception. However the key for the map is the id of the records, and the value is the record. What i need as the key is the field 'Custom_Field__c'. 

 

Does anyone know how to accomplish the instantiation/population of a map on a single line of code where the key (or value for that matter) is a specific field value?

 

What i'm trying to accomlish is using that maps keys or values as a filter for another query for another object.

 

Thanks for the help in advance.

Hi,

 

I have a requirement to integrate LDAP with Salesforce using Single Sign ON (SSO). Can anybody help me to provide any material/links...

 

Thanks

 

I have to create a custom button to print the record.

 

Any suggestions ??

 

I am tryin to create a MAP

 

Map<LeaveType__c,Leave_Policy__c> additionalLeavePolicy =new Map<LeaveType__c,Leave_Policy__c>([ SELECT Maximum_Allowed_Credit_for_Leave_Type__c,LeaveType__c,Next_Execution_Date__c,Action_Taken__c FROM Leave_Policy__c WHERE RecordType.Name='Additional Leave Policy']);

 Set <LeaveType__c> lt = additionalLeavePolicy.keyset();
 system.debug(lt.size);

 

will it work ??

 

AS

 

Map<ID,User> Usr = new Map<ID,User>([SELECT  name,TITLE FROM User WHERE Id IN : ownerIdList]);

 

IT WORKS  ??

I am not getting a proper ID

 

 

 

!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}

var newRecords = [];
 
var c = new sforce.SObject("Leave_Balance__c");

result1 = sforce.connection.query("Select Id from Leave_Balance__c where Employee_Name__c= '{!Leave_Application__c.OwnerId}' and LeaveType__c='{!Leave_Application__c.LeaveType__c}'  limit 1");          
//   LeaveType__c   is a reference { look up } to another object....    but it's giving some error , but it works fine in SOQL query in apex ??

records = result1.getArray("records");
if (records.length == 1) {
    var record = records[0];
  Id = (record.id);
alert(id);                                        

                          // here my id is some ext-gen1   ??
} else {
  alert("Something went wrong here");
}

I have to write down a Detail page button which will be fetching information from the current record and will be updating another custom object .

 

'm able to find information on List Page Buttons , but nothing for this  :(

 

Any help will be appreciated :)

 

I want to add a record to my object BD which is having a single field 'Name' using apex class.

The Scenario is like this -

A object 'Employee' is having field 'Emp_name' and 'Date' and if the Date for a particular record is equal to TODAY's date then a record should be added in object 'BD' with the matching name from Employee.

I will perform the scheduling using 'Schedule Apex' for daily .

 

Actually i have to do scheduling thats why i have to use Apex Class.

 

Thanks in Advance.

Pranay

  • April 16, 2012
  • Like
  • 0