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
Will_1Will_1 

Compile Error on Bind - Newbie

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];
 }
}

 

TehNrdTehNrd
Try this:

Code:
public class JobCalculations {

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

 

Will_1Will_1
TehNrd, Thank you very much!  Your code worked exactly, with the exception that I only need Id in the SQL, and not OpportunityId.  Thanks again!
Will678Will678

Now, the next problem for a newbie...

I've created the following Trigger to try to initiate the class and method above:

Code:
trigger TargetMkupsTrigger on Job__c (before insert, before update) {
 JobCalculations.updateTargetMkups(Trigger.new);
}

However, when I try to save this trigger, I receive the following error:

Save error: Method does not exist or incorrect signature: JobCalculations.updateTargetMkups(LIST:SOBJECT:Job__c).

I've tried to insert some type of object in the method call, but I cannot figure out the proper syntax.  Any thoughts out there?
 

SuperfellSuperfell
your method take a single job__c, but trigger.new is an array of job__c.
Will_1Will_1
Okay.  Makes sense.  I have updated my code to be the following, but I'm still getting the same error:
 
Save error: Method does not exist or incorrect signature: JobCalculations.updateTargetMkups(LIST:SOBJECT:Job__c) Staffing/src/unpackaged/triggers TargetMkupsTrigger.trigger line 2 1210784614164 247
Here is my trigger and current class/method:
 
Code:
trigger TargetMkupsTrigger on Job__c (before insert, before update) {
 JobCalculations.updateTargetMkups(Trigger.new);
}

public class JobCalculations {

 public static void updateTargetMkups(Job__c[] myjob) { 
  
  Set<Id> oppId = new Set<Id>();
  
  for (Job__c j:myjob) { 
   
   oppId.add(j.opportunity__c);
    
   Opportunity o = [ SELECT  Id, AccountId
        FROM Opportunity
        WHERE Id in : oppId];
       
   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;
  }
 }
}

 
Will678Will678

Anyone have any additional advice on this problem? 

I have looked at this code over and over, and now that I have changed the method to include an array of Job__c, I would think that at least from a method signature perspective, this should work.

TehNrdTehNrd
What happens when you remove all arguments:

Code:
trigger TargetMkupsTrigger on Job__c (before insert, before update) {
 JobCalculations.updateTargetMkups();
}

public class JobCalculations {

 public static void updateTargetMkups() { 
  /*Comment it out
  Set<Id> oppId = new Set<Id>();
  
  for (Job__c j:myjob) { 
   
   oppId.add(j.opportunity__c);
    
   Opportunity o = [ SELECT  Id, AccountId
        FROM Opportunity
        WHERE Id in : oppId];
       
   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;
  }*/
 }
}

 

Will678Will678

I tried something similar to this before to no avail, but I just did the following and I STILL get the same error??!! 

Code:
trigger TargetMkupsTrigger on Job__c (before insert, before update) {
 JobCalculations.updateTargetMkups();
}

public class JobCalculations {

 public static void updateTargetMkups() { 
  

 }
}


 

TehNrdTehNrd
Have you tried deleting the class and then recreating it?


Message Edited by TehNrd on 05-15-2008 01:44 PM
Will678Will678

I just tried deleting both the class and the trigger.  I then recreated the class (with no arguments), and there were no errors.  I recreated the trigger definition, and I received no errors either.  However, when I actually call the method within the trigger, THEN I receive the error.  So, the shell of the trigger below saves with no errors, but when I add the method call in the second version, then I get the exact same error.  I have checked for typo's in the method name over and over, but I cannot see any.

Code:
trigger TargetMkups on Job__c (before insert, before update) {

}

trigger TargetMkups on Job__c (before insert, before update) {
 JobCalculations.updateTargetMkups();
}


 

TehNrdTehNrd
Definitely seem strange. These would be my last thoughts but then a expert may need to take over.

Are you using Eclipse? Do you have the latest verstion of Eclipse and the Force.com IDE. Maybe rebuild the projects in Eclipse.

Also try making the saves through the web editor.


Message Edited by TehNrd on 05-16-2008 09:48 AM
Will678Will678

I am using Eclipse.  I should be using the latest version of everything since I only set this up a little over a week ago.  I actually do not know how to make these changes directly in the web version.  When I go to these development objects within Salesforce, I do not see an option to edit them directly.

I just deleted my old project, and setup a new one and recreated both the trigger and the class, but I still have the same problem.  Since this is the first development I am doing within Salesforce, I think it may be likely that there is some setup component that is not correct (user error, I'm sure).  So, here are some random comments that may strike a chord with someone:

- I have setup the Eclipse Force.com project directly to my production environment.  Does this matter in creating these objects?

- I can see the definition of my class, and the trigger in the development area of my salesforce.com account.  The "body" of these objects never appears online, I only see the definitions.

- All of this code is "unpackaged". 

Any thoughts are appreciated.  Tehnrd, you have been very helpful.  Maybe one of the administrators has an idea.  I have to believe other newbies out there have the same challenges.

 

TehNrdTehNrd
I believe this is your issue:

- I have setup the Eclipse Force.com project directly to my production environment.  Does this matter in creating these objects?

Try it in a sandbox or setup a dev account I think your issue will be resolved.



Message Edited by TehNrd on 05-16-2008 10:31 AM
Will678Will678
Well, TehNrd, that finally worked.  Now, all I have is the Test Coverage error which I know I need to write a special test method to get through and then I need to figure out how to get all this code to my production environment.  Thanks for your help.
TehNrdTehNrd
Glad it worked for you.

The test coverage is why your changes were not being saved to production.

All code in production must be covered by tests and since your trigger and class weren't, the saves were never committed, and that's why you couldn't see the code when you looked through the UI.

Technically code can be written in production if tests covered all the code. Yet you should never develop in production for a few reasons. You will miss bugs, we all make little mistakes, and you don't want these in production. Another reason is that I believe all test are run with any save, and for us to run all tests it takes about 4.5 minutes, and that just wouldn't be very productive.

Hope that all helps.

-Jason