• kavya.ax1320
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Hi,

 

Can anyone help me with a sample confirmation dialog which can be written without using JavaScript.

 

Thanks.

 

Hi,

 

Is there a possibility to list out only Standard and Custom objects from the instance using the Schema.describe function.

 

Thanks in advance.

 

 

Anyone knows how to create and insert a record into the history object(custom object's history) inside test method?

I have created a custom history related list for a custom object. But I dont know how to write a test method for that. Here is the code:

 

 public list<cHistories> getHistories()
    {
        // Initialize list to be returned
         list<cHistories> list_ch = new list<cHistories>();
    
        // Loop through all field history records
       
         for (Mapping_Object__History fh: [select ParentId,OldValue,NewValue,IsDeleted,Id,Field,CreatedDate,CreatedById,CreatedBy.Name
              From Mapping_Object__History
              where ParentId =:mapping.id
              order by CreatedDate desc])
              {
               // Create a new wrapper object
               cHistories ch = new cHistories();
      
               // Set the Date
               ch.theDate = String.valueOf(fh.createddate);
      
               // Set who performed the action
               ch.who = fh.createdby.name;
      
               // Set the Action value
               if (String.valueOf(fh.Field) == 'created')
               {    // on Creation
                    ch.action = 'Created.';
               }
               else if (fh.OldValue != null && fh.NewValue == null)
               { // when deleting a value from a field
                 // Format the Date and if there's an error, catch it and re
                 try {
                 ch.action = 'Deleted ' + Date.valueOf(fh.OldValue).format() + ' in <b>' + Schema.getGlobalDescribe().get('Mapping_Object__c').getDescribe().fields.getMap().get(String.valueOf(fh.Field)).getDescribe().getLabel() + '</b>.';
               
                 } catch (Exception e){
                   ch.action = 'Deleted ' + String.valueOf(fh.OldValue) + ' in <b>' + Schema.getGlobalDescribe().get('Mapping_Object__c').getDescribe().fields.getMap().get(String.valueOf(fh.Field)).getDescribe().getLabel() + '</b>.';
                   }
               }
               else
               {             // all other scenarios
                String fromText = '';
                if (fh.OldValue != null)
                {
                 try {
                      fromText = ' from ' + Date.valueOf(fh.OldValue).format();
                     } catch (Exception e) {
                      fromText = ' from ' + String.valueOf(fh.OldValue);
                      }
                }
       
                String toText = '';
                try {
                 toText = ' ' + Date.valueOf(fh.NewValue).format();
                } catch (Exception e) {
                 toText = ' ' + String.valueOf(fh.NewValue);
                   }
                               
          
          ch.action = 'Changed <b>' + Schema.getGlobalDescribe().get('Mapping_Object__c').getDescribe().fields.getMap().get(String.valueOf(fh.Field)).getDescribe().getLabel() + '</b>' + fromText + ' to <b>' + toText + '</b>.';    
               }
               list_ch.add(ch);   
             }
     return list_ch;
    }
   
    public class cHistories
    {
        // Class properties
        public String theDate {get; set;}
        public String who {get; set;}
        public String action {get; set;}
          
    }

 

 

When I tried to insert a record into the History object in the test method, It is throwing error that insertion operation is not allowed for History objects. Does anyone know of a solution?

Hi,

 

Schema.ChildRelationship returns the name of the SObject. Is there a possibility to compare it with a string without using the describe function.

 

Thanks ,

Hi,

 

Can a normal function send an apex error message to the Visualforce Page.

 

EX : 

public void abc (){

 

 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.error,'Error!!!!!!));

 

}

 

Thanks.

Hi !!!

 

Is there a possibility to get all the required fields of an object into select List.?

 

Example

All the Required Fields of the Account  to be listed into a select list.

 

Thanks in Advance.

Manju

Anyone knows how to create and insert a record into the history object(custom object's history) inside test method?

I have created a custom history related list for a custom object. But I dont know how to write a test method for that. Here is the code:

 

 public list<cHistories> getHistories()
    {
        // Initialize list to be returned
         list<cHistories> list_ch = new list<cHistories>();
    
        // Loop through all field history records
       
         for (Mapping_Object__History fh: [select ParentId,OldValue,NewValue,IsDeleted,Id,Field,CreatedDate,CreatedById,CreatedBy.Name
              From Mapping_Object__History
              where ParentId =:mapping.id
              order by CreatedDate desc])
              {
               // Create a new wrapper object
               cHistories ch = new cHistories();
      
               // Set the Date
               ch.theDate = String.valueOf(fh.createddate);
      
               // Set who performed the action
               ch.who = fh.createdby.name;
      
               // Set the Action value
               if (String.valueOf(fh.Field) == 'created')
               {    // on Creation
                    ch.action = 'Created.';
               }
               else if (fh.OldValue != null && fh.NewValue == null)
               { // when deleting a value from a field
                 // Format the Date and if there's an error, catch it and re
                 try {
                 ch.action = 'Deleted ' + Date.valueOf(fh.OldValue).format() + ' in <b>' + Schema.getGlobalDescribe().get('Mapping_Object__c').getDescribe().fields.getMap().get(String.valueOf(fh.Field)).getDescribe().getLabel() + '</b>.';
               
                 } catch (Exception e){
                   ch.action = 'Deleted ' + String.valueOf(fh.OldValue) + ' in <b>' + Schema.getGlobalDescribe().get('Mapping_Object__c').getDescribe().fields.getMap().get(String.valueOf(fh.Field)).getDescribe().getLabel() + '</b>.';
                   }
               }
               else
               {             // all other scenarios
                String fromText = '';
                if (fh.OldValue != null)
                {
                 try {
                      fromText = ' from ' + Date.valueOf(fh.OldValue).format();
                     } catch (Exception e) {
                      fromText = ' from ' + String.valueOf(fh.OldValue);
                      }
                }
       
                String toText = '';
                try {
                 toText = ' ' + Date.valueOf(fh.NewValue).format();
                } catch (Exception e) {
                 toText = ' ' + String.valueOf(fh.NewValue);
                   }
                               
          
          ch.action = 'Changed <b>' + Schema.getGlobalDescribe().get('Mapping_Object__c').getDescribe().fields.getMap().get(String.valueOf(fh.Field)).getDescribe().getLabel() + '</b>' + fromText + ' to <b>' + toText + '</b>.';    
               }
               list_ch.add(ch);   
             }
     return list_ch;
    }
   
    public class cHistories
    {
        // Class properties
        public String theDate {get; set;}
        public String who {get; set;}
        public String action {get; set;}
          
    }

 

 

When I tried to insert a record into the History object in the test method, It is throwing error that insertion operation is not allowed for History objects. Does anyone know of a solution?

Hi,

 

Schema.ChildRelationship returns the name of the SObject. Is there a possibility to compare it with a string without using the describe function.

 

Thanks ,

Hi,

 

Can a normal function send an apex error message to the Visualforce Page.

 

EX : 

public void abc (){

 

 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.error,'Error!!!!!!));

 

}

 

Thanks.

Hi !!!

 

Is there a possibility to get all the required fields of an object into select List.?

 

Example

All the Required Fields of the Account  to be listed into a select list.

 

Thanks in Advance.

Manju

Hi,

I need to add the field history from a custom object to a page, but am running into a lot of problems.  The related list displays with no problem when viewing the custom object through the salesforce custom object tab, but on my custom page it says that Histories is not a valid child relationship name for the entity.  I have checked the child relationships of my custom object and the History object that salesforce generates automatically when "Track Field History" is checked is listed with the name "Histories" as the child relationship name.  I have tried this on multiple custom objects (making them as simple as possible) and a relatedList on Histories just doesn't seem to be possible.  Has anyone been able to make this work?

-David