• alynlin
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Hi all.

 

I am writing an apex trigger,

 

trigger LatestEvaluationHistory on Evaluation_History__c (after delete, after insert,
 after undelete, after update) {

// this is the child object.

 

 

 

//then I want to update the parant object when the child is delete/insert/update

List<Job_Evaluation__c> dateToUpdate = new List <Job_Evaluation__c>{};

 

 

}

 

then I got the error:  Field is not writeable

 

 

Any body can help me on this? cause I am totally new in apex :)

 

 

Hi, I am learning salesforce and apex coding, and got some problems.

 

For example, code like this: (The function is, Tag the record with latest date "Most Recent Record", and other record not tagged.)

 

 

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

trigger LatestEvaluationHistory on Evaluation_History__c (after delete, after insert, after update) {
        
        List<Evaluation_History__c> ctxsToUpdate = new List<Evaluation_History__c>{};    
        Set<Id> emtoupdate = new Set<Id> ();
        boolean firstRecord = true;    
        
        if (Trigger.isInsert || Trigger.isUpdate ) {
            for (Evaluation_History__c c: Trigger.New) {
                emtoupdate.add(c.Job_Name__c);
            }
        }
        
        else {
            for (Evaluation_History__c c: Trigger.Old) {
                emtoupdate.add(c.Job_Name__c);
            }
        }
        
        if(ctxsToUpdate != null && !ctxsToUpdate.IsEmpty())
        {
        for(Evaluation_History__c ctx : [Select Id, Most_Recent_Record__c, Effective_Date__c
            from Evaluation_History__c where Job_Name__c =: emtoupdate ORDER BY Effective_Date__c DESC])
            {
                if(firstRecord)
                {
                    ctx.Most_Recent_Record__c = True;
                    firstRecord = false;    //System.debug(LoggingLevel.INFO,'a'+ctx.Id);
                }
                else
                {
                    ctx.Most_Recent_Record__c = False;    //System.debug(LoggingLevel.INFO,'b'+ctx.Id);
                }
                    
                ctxsToUpdate.add(ctx);
            }
        
        update ctxsToUpdate;
        }
}

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

 

This code can work in Sandbox, but cannot deploy into production because the test coverage is 0%.

So Who can teach me how to increase the test coverage???

 

Thanks a lot.

I am really torturing in this part.

 

Hi all.

 

I am writing an apex trigger,

 

trigger LatestEvaluationHistory on Evaluation_History__c (after delete, after insert,
 after undelete, after update) {

// this is the child object.

 

 

 

//then I want to update the parant object when the child is delete/insert/update

List<Job_Evaluation__c> dateToUpdate = new List <Job_Evaluation__c>{};

 

 

}

 

then I got the error:  Field is not writeable

 

 

Any body can help me on this? cause I am totally new in apex :)

 

 

Hi, I am learning salesforce and apex coding, and got some problems.

 

For example, code like this: (The function is, Tag the record with latest date "Most Recent Record", and other record not tagged.)

 

 

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

trigger LatestEvaluationHistory on Evaluation_History__c (after delete, after insert, after update) {
        
        List<Evaluation_History__c> ctxsToUpdate = new List<Evaluation_History__c>{};    
        Set<Id> emtoupdate = new Set<Id> ();
        boolean firstRecord = true;    
        
        if (Trigger.isInsert || Trigger.isUpdate ) {
            for (Evaluation_History__c c: Trigger.New) {
                emtoupdate.add(c.Job_Name__c);
            }
        }
        
        else {
            for (Evaluation_History__c c: Trigger.Old) {
                emtoupdate.add(c.Job_Name__c);
            }
        }
        
        if(ctxsToUpdate != null && !ctxsToUpdate.IsEmpty())
        {
        for(Evaluation_History__c ctx : [Select Id, Most_Recent_Record__c, Effective_Date__c
            from Evaluation_History__c where Job_Name__c =: emtoupdate ORDER BY Effective_Date__c DESC])
            {
                if(firstRecord)
                {
                    ctx.Most_Recent_Record__c = True;
                    firstRecord = false;    //System.debug(LoggingLevel.INFO,'a'+ctx.Id);
                }
                else
                {
                    ctx.Most_Recent_Record__c = False;    //System.debug(LoggingLevel.INFO,'b'+ctx.Id);
                }
                    
                ctxsToUpdate.add(ctx);
            }
        
        update ctxsToUpdate;
        }
}

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

 

This code can work in Sandbox, but cannot deploy into production because the test coverage is 0%.

So Who can teach me how to increase the test coverage???

 

Thanks a lot.

I am really torturing in this part.