function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Apps HeroApps Hero 

Inserting a a record to custom object

I have a custom object in which a status field frequently change with approval. Meaning "Approved, Rejected, Assigned, Completed" etc. each time when this status changed , I have to insert a record with all fields from the object to another object called History with new status.  So that all the status changes can be reviewed later in the history table.

Can someone suggest the efficient way to get this done.

I am very new to Force.com. and excited to learn

Thanks

George

Jake GmerekJake Gmerek

The best way will be an Apex Trigger for this functionality.  It is not that complicated, if you are interested, let me know and I can help you develop one.

sandeep@Salesforcesandeep@Salesforce

You may wite logic as in trigger jus t upbackthis feiled

Apps HeroApps Hero
Sure, Jake I am interested Please help me develop one
George
Jake GmerekJake Gmerek

Ok, do you have any development experience at all?

 

I would definitely recommend reading through the force.com workbook here:

 

http://wiki.developerforce.com/page/Force.com_workbook

 

This way you have a basic idea what is going on.  Then we can go from there.

Apps HeroApps Hero

I am fairy new ,  I did something, Not any apex in the application, DId  objects, forumalas validations etc.  I am actually a relational database guy for 17 yeas. Worked with Oracle PL/SQL.

 

I read the apex work book, and tried to write the trigger, But did not work . Here is my scenario

 

I have 2 Objects  Change_Request__c   which is parent and  Change_History__c    which is child.

Whenever I change  the status value in the parent object and save, It must insert a new recod in the child object with parent id as foreign  key.

This should happend for each time the status changed.

 

 

Change_Request__c          -Parent

 

Request No

Request_Name__c

Change_Type__c

Description__c

Module__c

Request_Date__c

Status__c  ( Possible values "Approved", "Rejected", "Changed")

 

 

 

*********************************************************************************************************

 

Change_History__c            -Child
History_No

Request No ( Forign key from other other object)

Request_Name__c

Change_Type__c

Description__c

Module__c

Request_Date__c
Status_changed_by_c ( user modify the record in the other Object

Status__c  ( Changed status in the other obeject)

Jake GmerekJake Gmerek

Something like this should get you started:

 

trigger AddHistory on Change_History__c (after insert, after update) {

List<Change_History__c> recsToAdd = new List<Change_History__c>();

foreach(Change_Request__c CR : trigger.new)
{
	recsToAdd.add(new Change_History__c( Request_No__c = CR.id, Change_Type__c = CR.Change-Type__c, **Add the rest of your fields**));
}
insert recsToAdd;

}