• Wayne_Clark
  • NEWBIE
  • 85 Points
  • Member since 2010

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 34
    Questions
  • 37
    Replies

I have 2 objects (NRMA__c)  (ts2__Application__c).  I'm trying to update a look up field (Candidate__c) on the NRMA object with the Candidate field (ts2__Candidate_Contact__c) from the Application object. 

 

I was able to accomplish other field updates like this through workflows, but for some reason, I was unable to update the Contract lookup field on the NRMA.  I need this field to populate the Contact that is listed on the Application object. 

 

Here is another run down of the fields and objects:

NRMA__c - object that includes a lookup to contacts (Candidate__c) - trying to update this field automatically

ts2__Application - object that includes a looup field to Contacts (ts2__Candidate_Contact__c). 

 

When creating a new record on NRMA from Application, I want this to happen before update, before insert:

NRMA.Candiate c = Application.ts2__Candidate_Contact__c

 

Here is the trigger, but it's not working:

 

trigger CandidateTrigger on NRMA__C (before insert, before update) {

  List<String> canList = new List<String>();
  for (NRMA__c n:Trigger.new){
    canList.add(n.Application__c);
  }
 
  List<ts2__Application__c> contactList = [SELECT Id, Name, ts2__Candidate_Contact__r.Id FROM ts2__Application__c WHERE Id in :canList];
 
  Map<String, Id> nameToId = new Map<String, Id>();
  for(ts2__Application__c c : contactList) {
    nameToId.put(c.Name, c.Id);
  }
 
  for (NRMA__c n:Trigger.new){
  n.Candidate__c = nameToId.get(n.Application__r.ts2__Candidate_Contact__r.Id);
  }
 
  }

 

 

Any ideas?  Thanks!

the salesforce advance search is down, what's the issue? 

 

I was just made aware from 2 companies I work with and I checked myself, anyone else having this issue?

This post stems from another post about our orgs issue with overall test coverage issue, the link to the previous post is here:

http://boards.developerforce.com/t5/Apex-Code-Development/Code-Coverage/td-p/257383

 

We found out that there were some classes installed in our production that do not have any code coverage and is bringing our overall coverage to around 35%.  There is also a managed package installed that is causing test failures.  These issues are not allowing us to develop and deploy any custom code.

 

If I developed custom code in a developer org and deployed the custom code we need as a managed package, would it deploy OK?  I've installed other managed packages into our production so I'm thinking this may be the way to go. 

 

Any suggestions or advice?  Thanks!

I'm tyring to insert a master record and detail record from one visualforce page, but I can't get the test class to work, any idea?

 

I'm only getting 64% coverage and it's throwing this message.  Thanks in advance!

 

System.DmlException: Insert failed. First exception on row 0 with id a1OS0000000B8yiMAC; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]


Class.newVendorPriceController.save: line 43, column 7 Class.TestNewVendorPriceController.TestNewVendorPriceController: line 41, column 1 External entry point

 

public class newVendorPriceController {
   
   
   Vendor_Price_Line_Item__c vendorlineitem;
   Vendor_Pricing__c vendorprice;
   Order__c order;
   
    private final Map<String, String> currentpageParams;

     
     public newVendorPriceController(ApexPages.StandardController controller) {
     
     this.vendorprice = (Vendor_Pricing__c)controller.getRecord();
     this.currentpageParams = ApexPages.currentPage().getParameters();

            
    }   
    
   public Vendor_Pricing__c getvendorprice() {
      if(vendorprice == null) vendorprice = new Vendor_Pricing__c();
      return vendorprice;
   }
   
     public Vendor_Price_Line_Item__c getvendorlineitem() {
      if(vendorlineitem == null) vendorlineitem = new Vendor_Price_Line_Item__c();
      return vendorlineitem;
   }
   

    public string oId = apexpages.currentpage().getParameters().get('id');
    
    
    public PageReference cancel() {
          PageReference pr = new PageReference('/ui/desktop/DesktopPage');
          pr.setRedirect(true);
          return pr;
     }

      public PageReference save() {

      insert vendorprice;
    
      vendorlineitem.Vendor_Price__c=vendorprice.id;
      insert vendorlineitem;


      PageReference vendyPage = new ApexPages.StandardController(vendorprice).view();
      vendyPage.setRedirect(true);

      return vendyPage;
   }

   }

 

 

 

 

 

Test Method:

 

@isTest

private class TestNewVendorPriceController {


static testMethod void TestNewVendorPriceController(){

   Vendor_Pricing__c venprice;
   ApexPages.StandardController sc;
   newVendorPriceController vpc;

Account account = new Account();// specify all the required fields
account.name = 'testing';
account.shippingcity = 'baltimore';
account.shippingstate = 'MD';
account.shippingcountry = 'USA';
account.shippingpostalcode = '21228';
insert account;
Contact contact = new Contact();// specify all the required fields
contact.lastname = 'test';
insert contact;
States__c state = new States__c ();
state.State_Code__c = 'BB';
insert state;
Order__c ord = new Order__c ();
ord.Account__c = account.Id;
insert ord;
Vendor_Pricing__c ven = new Vendor_Pricing__c ();
ven.Order__c = ord.Id;
insert ven;
Vendor_Price_Line_Item__c venline = new Vendor_Price_Line_Item__c ();
venline.Vendor_Price__c = ven.Id;
insert venline;

System.assertNotEquals(null, ven.Id);//tests to see if your insert was successful
   vpc = new newVendorPriceController(new ApexPages.StandardController(ven)); //here you instantiate the controller with a standard controller.
   //start you user testing.

vpc.getvendorprice();
vpc.getvendorlineitem ();
vpc.save();
vpc.cancel();



}

}

Code Coverage: 39%

Your overall code coverage is currently 39%. To deploy code to production, you must have at least 75%.

 

We have about 10 Apex classes that are reading 0% code coverage.

 

I run the test on one of the them and the code coverage shows 100%.

 

I then run a test on another class that reads 0% and the code coverage shows 100%.

 

However, the coverage on the first class I ran now shows 0%.

 

I have about 10 classes showing 0%, but when I run individual test on them, the are above 75%.  Some of these classes include the test code inside the class.  But, there are a few of them where I'm not able to run the test on them, I'm not even sure how these made it to production without being tested.

 

How do I make all the classes read the correct code coverage?  I'm thinking I need to seperate out the test coverage and make a seperate test class for the ones that include the test code, but I wanted to get some feedback before I tackle this.

 

Any feedback is greatly appreciated.

Hi,

 

I'm trying to create a Rollup SUM on a master object to total a number formula field on the child records, but it's not letting me select the field to SUM.

 

The formula field on the child record references a related object. Is this the reason it will not let me select that field to SUM? 

Hello,

 

Is it possible to count the number of records there are in a related list, only if their start dates is greater than the master objects start date? 

 

We have a School_Calendar__c which is the child of the Account.  The School Calendar has start and end dates and contains child object Calendar_Events__c, which are a list of events where the school has closings, these records also have start and end dates, example, Spring Break, the school closes between x date and x date.

 

The Order__c is another child object to the Account and includes a start date.

 

I'm trying to Count the number of Calendar_Event_Days__c there are, but only if the start date of the Calendar Event is greater than the start date of the Order.

 

Thanks in advance!

 

Aloha,

 

I'm having trouble testing out this line of code:

 

    public List<Order_Dimension__c> getdimList() {
            return dimList;
      }

 

 

Below is the full controller and test method so far, but only 60% is covered and the lines above are marked in red as not being tested.

 

 

public with sharing class OrderExtension{
    
    
    private final List<Order_Dimension__c> dimList;
    
    public OrderExtension(ApexPages.StandardController controller)     
        {
        dimList = [select e.Name, e.Commodity_Description__c, e.Length_Feet__c, Length_Inches__c, Width_Feet__c, Width_Inches__c, Height_Feet__c, Height_Inches__c, Classification__c, Dimensions__c
        from Order_Dimension__c e where Order__c=:ApexPages.currentPage().getParameters().get('id') 
        ];
    }
        
    public List<Order_Dimension__c> getdimList() {
            return dimList;
      }
  
}

 

@isTest

private class TestOrderExtension {

static testMethod void testOrderExtension(){
   Order__c order;
   ApexPages.StandardController sc;
   OrderExtension ore;

Account account = new Account();// specify all the required fields
account.name = 'testing';
account.shippingcity = 'baltimore';
account.shippingstate = 'MD';
account.shippingcountry = 'USA';
account.shippingpostalcode = '21228';
insert account;
Contact contact = new Contact();// specify all the required fields
contact.lastname = 'test';
insert contact;
States__c state = new States__c ();
state.State_Code__c = 'BB';
insert state;
Order__c ord = new Order__c ();
ord.Account__c = account.Id;
insert ord;
Order_Dimension__c dim = new Order_Dimension__c ();
dim.order__c = order.Id;
dim.Commodity_Description__c = 'steel';
dim.Classification__c = 'new';
dim.Height_Feet__c = Decimal.valueOf('1');
dim.Height_Feet__c = Decimal.valueOf('1');
dim.Length_Feet__c = Decimal.valueOf('1');
dim.Length_Inches__c = Decimal.valueOf('1');
dim.Width_Feet__c = Decimal.valueOf('1');
dim.Width_Inches__c = Decimal.valueOf('1');


System.assertNotEquals(null, ord.Id);//tests to see if your insert was successful
   ore = new OrderExtension(new ApexPages.StandardController(ord)); //here you instantiate the controller with a standard controller.
   //start you user testing.




}

}

 

 

Hello,

 

I have a custom object (Order__c) where I've embedded a visualforce page within the page layout.  The page has an extension to retrieve a list of the related list (Stops__c).  I'm trying to create a link on the Name of the stops so the user can click the link and go to the specific record with in the related list (Stops__c), or better yet mimic the pop-up window that shows when you hoover the mouse over a lookup field.  Any ideas on how to achieve this? 

 

Below is the main code I have so far on my Visualforce page, I've managed to link it to the page, but only when I'm in the visualforce/apex edit mode with the URL is set at apex/order?id={lorder__c.Id}

 

Visualforce markup:

 

<apex:dataTable value="{!StopList}" var="STOP">

 

      <apex:column >
        <apex:facet name="header">
         <apex:outputText value="Stop Name"/>
       </apex:facet>
       <apex:outputLink value="Stops?id={!STOP.Id}" id="theLink"> {!STOP.Name} </apex:outputLink>
       <!-- Position name field is linked to the job details page -->
       </apex:column>

 

 

The link only works when I'm the visualforce edit view (visual.force.com/apex/order?id=a0kS0000000738i), but not when I'm in the normal record view (my.salesforce.com/a0kS0000000738i)  The link goes to another Visualforce page called Stops.  Any ideas on how to get this link to work in the regular record view, or also have a popup on mouseover?

 

Thanks in advance!

 

 

Hello,

 

Is there anyway to add Products to a custom object like it is with the Opportunity? 

 

Thanks!

I'm trying to populate a lookup to Account in Account called Parent_or_Self_Id__c, but it generates an error when I set a record to reference itself:

Hierarchy Constraint Violation in the UI

or

CIRCULAR_DEPENDENCY, attempt to violate hierarchy constraints in Apex

 

From a Data Model and a practical perspective it's much preferred to have one lookup field than potentially sixty-five cross object formulas (if that's even allowed) to pull the data from the parent record defaulting with the current record.

 

Anyone know if the apparent check restricting circular references in the data can be disabled by the SalesForce feature activation customer support?  I called a different area of customer support and the person seemed to be under the assumption that it couldn't be changed without any reasoning why.

 

Perhaps the validation rule was created by a salesforce developer over-protecting the system so he could guarantee no infinate loops ever?  In theory poorly coded Apex especially triggers could be following lookups in the data and get lost in an infinate loop.  But in practice, if that happened it would violate a governor rule, and generate an API error with no harm.   I can't think of any other reason to restrict data from having circular references.  Perhaps there is more reasoning to this restriction that I'm not aware of?

 

I keep running into all of these different ways that SalesForce is crippled... perhaps one per month!  So disappointing!  Another item to add to the list of technical flaws in SalesForce that maybe I can get someone to listen to at the next DreamForce?  SalesForce may be one of the least flawed Content Management Systems (CMS), but that's why experienced people often caution against CMS instead of custom programming because of those things you need done that can't be done!