• Will678
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 10
    Replies
I have a trigger, that calls an Apex code on a custom object.  This code checks the value of a status field on the object, and then updates another object based on the result.  When I edit the object using the normal Edit mode, the code executes perfectly.  However, when I edit this status field using inline editing, the code does not execute.  Is this a known limitation, or is there something I need to put in my trigger or code to deal with this?
I need to automatically name opportunities in this format:
AccountName - Autonumber {000000}

How can I implement that? If I create a helping field of type auto number the field is not set in the before insert trigger. In the after insert trigger I can't rename the opportunity.

Any help appreciated.
  • May 30, 2008
  • Like
  • 0
The newbie is back again...  I now have all of my code working both in Eclipse and in my development environment.  Here is my trigger which fires on the Insert or Update of a new custom object, Job:
Code:
trigger TargetMkups on Job__c (before insert, before update) {
 JobCalculations.updateTargetMkups(trigger.new);
}

 
Below is the class and method called in the trigger:
Code:
public class JobCalculations {
 
public static void updateTargetMkups(Job__c[] myjob) {
 
 Set<Id> jobId = new Set<Id>();
 for (Job__c j:myjob) { 
  if (j.opportunity__c != null){
   jobId.add(j.opportunity__c);
  }
    
  Opportunity o = [ SELECT  Id, AccountId
       FROM Opportunity
       WHERE Id in : jobId];
      
  Account a =  [ SELECT  Id, target_c2c_mkup__c, target_w2h_mkup__c, target_w2b_mkup__c
       FROM Account
       WHERE Id = :o.AccountId];
        
  j.target_c2c_mkup__c = a.target_c2c_mkup__c;
  j.target_w2h_mkup__c = a.target_w2h_mkup__c;
  j.target_w2b_mkup__c = a.target_w2b_mkup__c;
 }
}
}

 
And, here is my test method which inserts one account, one opportunity, and one job which, given the simplicity of this code, I would think should achieve ample coverage:
Code:
public class JobCalculationstest {

public static testMethod void testUpdateTargetMkups() {
 Account a1 = new Account (name = 'Test Acct', target_c2c_mkup__c = 1.4, target_w2b_mkup__c = 1.45, target_w2h_mkup__c = 1.45);
 insert a1;
 Opportunity o1 = new Opportunity (name = 'Test Opp', accountid = a1.id, stageName ='Open', CloseDate=Date.newInstance(2008,5,15));
 insert o1;
 Job__c j1 = new Job__c (name = 'Test Job', opportunity__c = o1.id);
 insert j1;
 Job__c queryJob1 = [select Id, target_c2c_mkup__c, target_w2b_mkup__c, target_w2h_mkup__c from Job__c where Id = :j1.Id];
 System.assertEquals(1.4, queryJob1.target_c2c_mkup__c);
 System.assertEquals(1.45, queryJob1.target_w2b_mkup__c);
 System.assertEquals(1.45, queryJob1.target_w2h_mkup__c);  
}
}

 However, I still get 0% coverage from the test above.  As I said, I know the code works because I've tested it in my development environment.  Additionally, the log file shows the updated values in the log.  I'm just stuck with this 0% coverage.  I'm so close... Any advice?
 
I'm a newbie to Apex (and to Java for that matter).
 
I've created a custom object, Job, that has a lookup relationship to Opportunity.  I'm trying to create a method that will get the account id off of the opportunity (based on the opportunity id stored on job), and then get some default custom fields off of account to populate in the job record.  However, I can't even seem to get off of the ground with the method.  My idea is that I would call this method from a trigger in Job.
 
The following code gives me the following compile error:
 
Save error: Didn't understand relationship 'Job__c' in field path.  If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. Staffing/src/unpackaged/classes JobCalculations.cls line 17 1210710065570 177
 
I have changed the reference to Job to be Job__r to no avail, and I have changed the reference to the field to be Job__c.Opportunity__r with no luck either.  Does anyone have any advice for a newbie?
 
Code:
public class JobCalculations {

 public static void updateTargetMkups(Job__c myjob) { 
    
  Opportunity o = [ SELECT Id, AccountId
       FROM Opportunity
       WHERE Job__c.opportunity__c = : Id];
 }
}