• Ola
  • NEWBIE
  • 25 Points
  • Member since 2009

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

Has anyone been able to associate a custom object to OpportunityLineIte?

 

I'm trying to associate a custom object (BOM_Item__c) to OpportunityLineItems, preferably via a Master-Detail connection but a Lookup connection would also be ok.

 

I've tried to do this via the salesforce web setup interface. When trying to create a Lookup or Master-Detail connection the OpportunityLineItem is not among the selectable objects.

 

When I try to create the connection via the Force.com integration in Eclipse I also get errors (see below).

Is the OpportunityLineItem not a normal object? If that's the case is there some other way I can achieve the same result?

 

Any help would be much appreciated!

 

Thanks!

/Ola

 

Custom object:

 

<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<deploymentStatus>Deployed</deploymentStatus>
<description>Part of the Bill Of Material for the associated Opportunity Line Item</description>
<fields>
<fullName>Opportunity__c</fullName>
<label>Opportunity</label>
<referenceTo>Opportunity</referenceTo>
<relationshipLabel>BOM Items</relationshipLabel>
<relationshipName>BOM_Items</relationshipName>
<relationshipOrder>0</relationshipOrder>
<type>MasterDetail</type>
<writeRequiresMasterRead>true</writeRequiresMasterRead>
</fields>
<fields>
<fullName>OpportunityLineItem__c</fullName>
<label>BOM OpportunityLineItem</label>
<referenceTo>OpportunityLineItem</referenceTo>
<relationshipLabel>Line Item BOM Item</relationshipLabel>
<relationshipName>Line_Item_BOM_Item</relationshipName>
<type>Lookup</type>
</fields>
<label>BOM Item</label>
<listViews>
<fullName>All</fullName>
<filterScope>Everything</filterScope>
<label>All</label>
</listViews>
<nameField>
<label>BOM Item Name</label>
<type>Text</type>
</nameField>
<pluralLabel>BOM Items</pluralLabel>
<searchLayouts/>
<sharingModel>ControlledByParent</sharingModel>
</CustomObject>

 

 

 

 

Deploy error:

# Deploy Results:
   File Name:    objects/BOM_Item__c.object
   Full Name:  BOM_Item__c.OpportunityLineItem__c
   Action:  NO ACTION
   Result:  FAILED
   Problem: Custom Object Definition ID: bad value for restricted picklist field: OpportunityLineItem

  • August 14, 2009
  • Like
  • 0

Hi all,

I am new to SalesForce so I appologise in advance for any newbie mistakes.


I'm trying to make a vf page to display the fields of the SObjects returned by an arbitrary query. I found a working solution for displaying the fields of one object in this thread: dynamicSObject. I have tried to take the accepted solution in the thread and iterate over a list of DynamicSObjects instead of showing just one.

When I try the original solution everything works fine.
The iterative code below uploads ok without any error messages.
When I try to view the page with the new iterative version I get the following runtime error:


 System.Exception: Too many fields describes: 11

Class.queryTestController.DynamicSObject.getFields: line 61, column 46 External entry point


The position mentioned in the error message is in the line below at "getDescribe()"

for (Schema.SObjectField f : getDescribe().fields.getMap().values()) {

What am I doing wrong?

Thank you for your time!

/Ola

 

 

<apex:page controller="queryTestController">

<apex:form >
<apex:inputText value="{!dynamicQuery}" id="dynamicQuery"/>
</apex:form>

<apex:form id="content">
<apex:pageMessages />
<apex:repeat var="object" value="{!unknowns}">
<h1>{!object.sobjectType} [{!now()}]</h1><br/>
<apex:pageBlock title="{!object.id}">
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!object.save}" value="Save" rerender="content"/>
</apex:pageBlockButtons>
<apex:pageBlockTable var="f" value="{!object.fields}">
<apex:column value="{!f.name}" headerValue="Name"/>
<apex:column headerValue="Value">
<apex:inputText value="{!f.value}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:repeat>
</apex:form>

</apex:page>



public class queryTestController {

private List<DynamicSObject> dynamicSObjects;
public string dynamicQuery { get; set;}

public queryTestController () {
dynamicQuery = 'select name,closedate from Opportunity';
}

public List<DynamicSObject> getUnknowns() {
dynamicSObjects = new List<DynamicSObject>();
ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(Database.query(dynamicQuery));
List<SObject> base = (List<SObject>) setCon.getRecords();
for (SObject obj : base) {
dynamicSObjects.add(new DynamicSObject(obj));
}
return dynamicSObjects;
}

public class DynamicSObject {
public DynamicSObject(SObject delegate) {
this.delegate = delegate;
}

public ID getID() {
return delegate.id;
}

public void save() {
Database.upsert(delegate);
}

public String getSObjectType() {
return getDescribe().getName();
}

public List<Field> getFields() {
if (fields == null) {
fields = new List<Field>();
for (Schema.SObjectField f : getDescribe().fields.getMap().values()) {
if (f.getDescribe().getType() != DisplayType.ID) {
try {
Field field = new Field(delegate, f);
fields.add(field);
} catch (System.SObjectException x) {
// Do nothing - just means that the field was not selected in the select list
}
}
}
}

return fields;
}

private Schema.DescribeSObjectResult getDescribe() {
return delegate.getSObjectType().getDescribe();
}

private final SObject delegate;
private List<Field> fields;
}

public class Field {
Field(SObject delegate, Schema.SObjectField f) {
this.delegate = delegate;
this.f = f;

getValue();
}

public String getName() {
return f.getDescribe().getName();
}

public String getValue() {
Object value = delegate.get(f);
return value != null ? String.valueOf(value) : null;
}

public void setValue(String value) {
// TODO: Handle remaining data type conversions...
if (f.getDescribe().getType() == DisplayType.INTEGER) {
delegate.put(f, Integer.valueOf(value));
} else {
delegate.put(f, value);
}
}

private final SObject delegate;
private final Schema.SObjectField f;
}
}

 

 

 

  • May 18, 2009
  • Like
  • 0

Hi all,

I am new to SalesForce so I appologise in advance for any newbie mistakes.


I'm trying to make a vf page to display the fields of the SObjects returned by an arbitrary query. I found a working solution for displaying the fields of one object in this thread: dynamicSObject. I have tried to take the accepted solution in the thread and iterate over a list of DynamicSObjects instead of showing just one.

When I try the original solution everything works fine.
The iterative code below uploads ok without any error messages.
When I try to view the page with the new iterative version I get the following runtime error:


 System.Exception: Too many fields describes: 11

Class.queryTestController.DynamicSObject.getFields: line 61, column 46 External entry point


The position mentioned in the error message is in the line below at "getDescribe()"

for (Schema.SObjectField f : getDescribe().fields.getMap().values()) {

What am I doing wrong?

Thank you for your time!

/Ola

 

 

<apex:page controller="queryTestController">

<apex:form >
<apex:inputText value="{!dynamicQuery}" id="dynamicQuery"/>
</apex:form>

<apex:form id="content">
<apex:pageMessages />
<apex:repeat var="object" value="{!unknowns}">
<h1>{!object.sobjectType} [{!now()}]</h1><br/>
<apex:pageBlock title="{!object.id}">
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!object.save}" value="Save" rerender="content"/>
</apex:pageBlockButtons>
<apex:pageBlockTable var="f" value="{!object.fields}">
<apex:column value="{!f.name}" headerValue="Name"/>
<apex:column headerValue="Value">
<apex:inputText value="{!f.value}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:repeat>
</apex:form>

</apex:page>



public class queryTestController {

private List<DynamicSObject> dynamicSObjects;
public string dynamicQuery { get; set;}

public queryTestController () {
dynamicQuery = 'select name,closedate from Opportunity';
}

public List<DynamicSObject> getUnknowns() {
dynamicSObjects = new List<DynamicSObject>();
ApexPages.StandardSetController setCon = new ApexPages.StandardSetController(Database.query(dynamicQuery));
List<SObject> base = (List<SObject>) setCon.getRecords();
for (SObject obj : base) {
dynamicSObjects.add(new DynamicSObject(obj));
}
return dynamicSObjects;
}

public class DynamicSObject {
public DynamicSObject(SObject delegate) {
this.delegate = delegate;
}

public ID getID() {
return delegate.id;
}

public void save() {
Database.upsert(delegate);
}

public String getSObjectType() {
return getDescribe().getName();
}

public List<Field> getFields() {
if (fields == null) {
fields = new List<Field>();
for (Schema.SObjectField f : getDescribe().fields.getMap().values()) {
if (f.getDescribe().getType() != DisplayType.ID) {
try {
Field field = new Field(delegate, f);
fields.add(field);
} catch (System.SObjectException x) {
// Do nothing - just means that the field was not selected in the select list
}
}
}
}

return fields;
}

private Schema.DescribeSObjectResult getDescribe() {
return delegate.getSObjectType().getDescribe();
}

private final SObject delegate;
private List<Field> fields;
}

public class Field {
Field(SObject delegate, Schema.SObjectField f) {
this.delegate = delegate;
this.f = f;

getValue();
}

public String getName() {
return f.getDescribe().getName();
}

public String getValue() {
Object value = delegate.get(f);
return value != null ? String.valueOf(value) : null;
}

public void setValue(String value) {
// TODO: Handle remaining data type conversions...
if (f.getDescribe().getType() == DisplayType.INTEGER) {
delegate.put(f, Integer.valueOf(value));
} else {
delegate.put(f, value);
}
}

private final SObject delegate;
private final Schema.SObjectField f;
}
}

 

 

 

  • May 18, 2009
  • Like
  • 0
Hi all,

I'd like to dynamically  render an Sobject to a VF page.

Here is my controller:

Code:
private list<SObject> obj;

public void setobj(list<SObject> s){obj=s;} public list<Sobject> getobj(){return obj;}
public PageReference init() {
 obj=[select Name from Account limit 10]; return null; }

Here my VF Page:

Code:
<apex:page Controller="Test" action="{!init}">
<apex:form>
<apex:repeat value="{!obj}" var="field">
   <apex:inputField value="{!field.Name}"/>
</apex:repeat>
</apex:form>
</apex:page>

I've got this error message :
Read access not found for null.
I've also tried with outputText, inputText with no success.The only field I've managed to retrieve is the ID.

Any Idea ?