• JoeyD
  • NEWBIE
  • 30 Points
  • Member since 2010

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

Hi,

 

I have an object called meeting note and a child object called attendee.

 

When you create a meeting you can add as many attendees as you want.

 

What I would like to happen is when you add an attendee and hit save you are returned not to the attendee record but to the linked meeting note.

 

Thanks

 

Ross

Hi all,

 

I have a custom extension I am using with a VF page that replaces the "new" button of the object. The object is a child of Opportunities and, and the records are created from an Opportunity related list.  I have the Opportunity field on the object auto-populating, but I would like an Account look-up field to auto populate as well with the Account related to the Opportunity, as I would like a related list of the custom object on Account records. 

 

Is there a way to do it in the extension, or will I have to use a before insert trigger?

 

Thanks

  • July 19, 2010
  • Like
  • 0

Hi all,

 

Below is some code that I got to work with the help of everyone here on the forums as well as elsewhere on the internet, so I thought I would post it for everyone to view in case it might help someone else down the road who is looking for something similar.

 

What it does is allow you to enter a new record of a custom parent object (which, itself, has a master-detail to the Opportunity object) while also entering multiple records for the child object that will save under the parent.

 

When the "New" button is clicked from the related list of an Opportunity record, the Opportunity field is automatically populated.


Note: I have only used this class and VF page in the sandbox, as a learning experiment. Everything works as I would expect it to, however, I am very new to programming in general, so I would suggest creating your own test class, and testing this stuff out in your sandbox or developer edition first, if you want to use it.

 

Also, I don't expect this stuff to be perfect (or, for that matter, not broken), so I'm very open to suggestions on how to make this stuff cleaner or more efficient. 

 

I'll try to post some screen shots as well.

 

The VF page:

 

<apex:page StandardController="Custom_Parent__c" extensions="parentChild" id="thePage">
    <style>
        .container
            {
                margin-left:10%;
                border:1px;
            }
        .even
            {
                background-color:#eeeed1;
            }
        .odd
            {
            }
    </style>
    <apex:sectionHeader title="Parent and Child"/>
        <apex:Message />
    <apex:form >
        <apex:pageBlock id="pb" title="Parent Detail">
            <apex:pageBlockButtons >
                <apex:commandbutton value="Save" action="{!Save}"/>
                <apex:commandbutton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="2" showHeader="false">
                <apex:outputField value="{!parent.Opportunity__c}" id="getOppid"/>
                <apex:inputField value="{!parent.Field1__c}"/>
                <apex:inputField value="{!parent.Field2}"/>
                <apex:inputField value="{!parent.Field2__c}"/>
                <apex:inputField value="{!parent.Field3__c}"/>
                &nbsp;
                <apex:inputField value="{!parent.Field4__c}"/>
                &nbsp;
                <apex:inputField value="{!parent.Field5__c}"/>
                <br/>
                <br/>
                <br/>      
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Child" columns="1" collapsible="false"> 
                <apex:pageBlock id="pb1">
                    <apex:pageMessages />
                    <apex:outputPanel layout="block" styleClass="container"> 
                    <apex:pageBlockTable value="{!lstInner}" var="c" id="therepeat" style="width:460px;padding:4px;" rowClasses="even,odd">
                        <apex:column headerValue="Column 1 Header" style="border:1px solid #f3f3eb;">
                            <apex:inputField value="{!c.child.Col1__c}" style="width:3em;"/>
                        </apex:column>
                        <apex:column headerValue="Column 2 Header" style="border:1px solid #f3f3eb;">
                            <apex:inputField value="{!c.child.Col2__c}"/>
                        </apex:column>
                        <apex:column headerValue="Column 3 Header" style="border:1px solid #f3f3eb;">
                            <apex:inputField value="{!c.child.Col3__c}" style="width:2em;"/>
                        </apex:column>
                        <apex:column style="border:1px solid #f3f3eb;">
                            <apex:commandLink value="Remove" action="{!Del}" rerender="pb1">
                                <apex:param name="rowToBeDeleted" value="{!c.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                            </apex:commandLink>
                        </apex:column>
                        
                    </apex:pageBlockTable>
                    <apex:commandLink value="Add Row" action="{!Add}" rerender="pb1"/>
                </apex:outputPanel>
                </apex:pageBlock>
            </apex:pageBlockSection>
            <apex:pageBlockSection columns="1" title="New Section Title" collapsible="false">
                <apex:inputField value="{!parent.Field6__c}" style="width:400px;"/>
            </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>
</apex:page>

 

 

The Apex class:

 

 

public class parentChild {

    public List<Custom_Child__c> children  = new List<Custom_Child__c>();
    public List<innerClass> lstInner {get;set;}
    public String selectedRowIndex {get;set;}  
    public Integer count = 1;
    Custom_Parent__c parent;
    
    public Custom_Parent__c getparent(){
        if(parent == null) parent = new Custom_Parent__c();
        return parent;
    }
    
    public String getOppid(){
        String q = ApexPages.currentPage().getParameters().get('OppId');
        return q;
    }

    public PageReference Save(){
        try{
            for(Integer j = 0;j<lstInner.size();j++){
                children.add(lstInner[j].child);
            } 
            insert parent;
            for (Custom_Child__c sku : children){
                sku.Custom_Parent__c = parent.id;
            }
            insert children;
        }
        catch(DmlException ex){
            ApexPages.addMessages(ex);
        } 
        PageReference pr = new PageReference('/'+parent.id);
        pr.setRedirect(True);
        return pr;
    }
        
    public void Add(){   
        count = count+1;
        addMore();      
    }

    public void addMore(){
        innerClass objInnerClass = new innerClass(count);
        lstInner.add(objInnerClass);    
        system.debug('lstInner---->'+lstInner);            
    }
    
    public void Del(){
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;  
    }

    public parentChild(ApexPages.StandardController ctlr){
        this.parent = (Custom_Parent__c)ctlr.getRecord();
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';   
    }

    public class innerClass {       
        
        public String recCount {get;set;}
        public Custom_Child__c child {get;set;}
        
        public innerClass(Integer intCount){
            recCount = String.valueOf(intCount);        
            child = new Custom_Child__c();
        }  
    }
}

 

 

I've tried to replace all of my actualy object and field names with generic ones, so I apologized if I missed something.

Anyhow, let me know what you think! And hopefully this helps someone. :)

 

 

  • July 07, 2010
  • Like
  • 1

Hi all,

 

I need to add the Orders__c.ID value to every Ordered_SKU__c.Order__c field on save.  I can't figure out how to get it in there... Any suggestions?

 

 

public class orderInsert {

Orders__c orders;
List<Ordered_SKU__c> skus {get; set;}

public Orders__c getOrders(){
if(orders == null){
orders = new Orders__c();
}
return orders;
}

public orderInsert(){
skus = new List<Ordered_SKU__c>();
skus.add(New Ordered_SKU__c()); // I've tried (New Ordered_SKU__c(Order__c = orders.id)); but obviously that returns a null value.
}

public void addrow(){
skus.add(new Ordered_SKU__c());
}

public PageReference save() {
try{
insert orders;
insert skus;
}
catch(DmlException ex){
ApexPages.addMessages(ex);
}
PageReference pr = new PageReference('/'+orders.id);
pr.setRedirect(true);
return pr;
}
}

 

 

  • June 29, 2010
  • Like
  • 0

I've added the following extension to a visualforce page. The page's object is a child of Opportunities. After saving a record in this child object, I'd like to be redirected back to the parent record.

 

I don't know how to get the parent Opportunity record ID to reference in the PageReference method.

 

(I know my custom object is called TestParent... this is because it is actually the parent of another custom object, TestChild. :smileytongue: )

 

 

public class testParentSave {

public TestParent__c parent {get; set;}

public testParentSave(ApexPages.StandardController controller) {
parent = (TestParent__c) controller.getRecord();
}

public PageReference save() {
insert parent;
PageReference pr = new PageReference('/'+TestParent__c.Opportunity__c);
pr.setRedirect(true);
return pr;
}
}

 

 

  • June 15, 2010
  • Like
  • 0

Is it possible to replace only the save behavior of a custom object, without recreating the detail page in visualforce?

We have a custom object that is a child to a parent custom object, and when we create a new child record and save, we'd like to be redirected to the master detail record.

 

So as an example, if you create a new Contact for Account1, and save, you return to the Account1 detail page.

 

I've used methods like the code below in extension classes for visualforce pages, but I don't know how I would use only this single method and have it replace the operation of that object's standard controller.

 

 

public PageReference save() {
    
        try{
            update pfc;
        }
        catch(DmlException ex){
            ApexPages.addMessages(ex);  
        }
        PageReference pr = new PageReference('/home/home.jsp');
        pr.setRedirect(true);
        return pr;
    }
           

 

 

 

I hope I'm making sense!

 

Any help would be greatly appreciated.

  • June 11, 2010
  • Like
  • 0

Hi all,

 

I'm currently using the following class:

 

public with sharing class classTest{
    
    public classTest(ApexPages.StandardSetController controller) {
    }
    
    List<Dealer_Forecast__c> dfc;
    public String myUserID = UserInfo.getUserId();

    public List<Dealer_Forecast__c> getDfc(){
        if(dfc == null){
            dfc = [SELECT Account__c,Style__c, Region__c, Territory__c
                FROM Dealer_Forecast__c 
                WHERE Account__r.OwnerId =:myUserID];
        }    
        
        return dfc;
    }
}
    

 

 

 

But instead of creating the list where the owner of the account is the current user, I'd like to pull records where a custom field on the related Account = a custom field on the current user's User record. So I changed the code to the following:

 

public with sharing class classTest{
    
    public classTest(ApexPages.StandardSetController controller) {
    }
    
    public String userlist {get; set;}
    List<Dealer_Forecast__c> dfc;
    public String myUserID = UserInfo.getUserId();

    public String getUserlist(){  
        userlist = [SELECT Report_Server_Co_Id__c FROM User WHERE id = :myUserID LIMIT 1].Report_Server_Co_Id__c;
        return userlist;   
    }
    public Integer userterr = Integer.valueOf(userlist);
    
    public List<Dealer_Forecast__c> getDfc(){
        if(dfc == null){
            dfc = [SELECT Account__c,Style__c, Region__c, Territory__c
                FROM Dealer_Forecast__c 
                WHERE Account__r.Territory__c =:userterr];
        }    
        
        return dfc;
    }
}
    

 

 

 

I am able to save the class, but when the code is executed, I get an error stating "Argument 1 cannot be null". I imagine the way I'm trying to achieve what is I need is completely incorrect.

 

Any suggestions?

Thanks!

 

  • June 09, 2010
  • Like
  • 0

Hi all,

 

 

We have lists of contacts that we would like to import into sfdc as accounts while also adding them to a campaign and adding associated partner accounts.

Is it possible to use the Excel Connector to import this data and achieve this?

 

Thanks.

  • May 20, 2010
  • Like
  • 0

Hi all,

 

I've implemented an Apex class and visualforce page that allows an editable list to be called from a custom object. The apex class allows the list to be sortable.

The button to access this page is on the List View of the custom object, and I've been trying to find a way to allow the visualforce page to only display the records that were selected in the List View, while still maintaining its sort function.

 

I basically took the code from this link here: http://wiki.developerforce.com/index.php/Sorting_Tables

 

Any ideas?

  • May 19, 2010
  • Like
  • 0

I'm using this bit of code to allow a save button on a page to save a list, but I'd like the button to redirect the user to a different page after they click Save, much like the Cancel button does now.

 

 

public PageReference cancel() {
          PageReference pr = new PageReference('/a0G/o');
          pr.setRedirect(true);
          return pr;
          }
    public void save() {
    
        try{
            update pfc;
        }
        catch(DmlException ex){
            ApexPages.addMessages(ex);
            
        }
        }
           

 

 

The save method works, in that what is edited in the list saves, I would just like to add the same PageReference bit from the cancel method to the save method, and I don't know how to do that. :smileyindifferent:

 

Ideally both cancel and save buttons would direct the user back to the List View from where the visualforce page that uses this class is accessed, but simply redirecting back to the object URL is fine.

 

Any help would be greatly appreciated!

 

  • May 14, 2010
  • Like
  • 0

Hi all!

 

I have only one or two weeks experience with Apex and Visualforce, and no coding experience, so please bear with me.

I altered the MassEdit visualforce page to the specifications of my supervisor, but we now we need to be able to sort the fields.

Having no experience with Apex or Java or anything, I was hoping I could sort of copy/paste the code from this Sorting Tables tutorial and replace the components that made sense.  It's not really working out.

 

Not being in Developer Edition, I'm having to use the Force.com IDE through Eclipse.

Here's the class:

 

 

public with sharing class massEditSort {

    List<Product_Forecasting__c> fcs;
    public String sortField {get; set;}
    public String previousSortField {get; set;}
    
    public List<Product_Forecasting__c> getFcs() {
        if(fcs == null){
            fcs = [select Forecast_For_Month__c, Style__c, Color_Code__c, Product_Description__c, Color__c, LQ2__c, Forecasted_Units_Q2_c__c, LQ3__c, Forecasted_Units_Q3_2010__c, Forecasted_Units_Q4_2010__c from Product_Forecasting__c];
        }
        return fcs;
    }
    
    public void doSort(){
        String order = 'asc';
        
        /*This checks to see if the same header was click two times in a row, if so 
        it switches the order.*/
        if(previousSortField == sortField){
            order = 'desc';
            previousSortField = null;
        }else{
            previousSortField = sortField;
        }
       
        //To sort the table we simply need to use this one line, nice!
        superSort.sortList(fcs,sortField,order);
    }
}

 

 

Now when I try to save this, I get an error that reads: Average test coverage across all Apex Classes and Triggers is 74%, at least 75% test coverage is required

And also the error: Save error: Method does not exist or incorrect signature: superSort.sortList(LIST:SOBJECT:Product_Forecasting__c, String, String)

 

Here is the Visualforce Page I am trying to get to work with this controller:

 

 

<apex:page controller="massEditSort">
    <apex:form >
        
	<apex:pageBlock >
		Note: All modifications made on the page will be lost if Cancel button is clicked without clicking the Save button first.<br />
		<p style="color:red"><u>Do not click the "Agree With Forecast" checkbox if you update or change any other field.</u></p>
	</apex:pageBlock>
	<apex:pageBlock >
	<apex:pageBlockButtons >
		<apex:commandButton value="Save" action="{!save}"/>
		<apex:commandButton value="Cancel" action="{!cancel}"/>
	</apex:pageBlockButtons>            

	<apex:pageBlockTable value="{!selected}" var="o" id="table">
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Forecast_For_Month__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Forecast For Month:" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.Forecast_For_Month__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Style__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Style#" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.Style__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Color_Code__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Color Code" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.Color_Code__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Product_Description__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Product Description" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.Product_Description__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Color__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Color" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.Color__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.LQ2__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="LQ2 2009" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.LQ2__c}"/>
                </apex:column>
                 <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Forecasted_Units_Q2_c__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Forecasted Units Q2 2010" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:inputField value="{!o.Forecasted_Units_Q2_c__c}"/>
                </apex:column>
		 <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.LQ3__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="LQ3 2009" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.LQ3__c}"/>
                </apex:column>
		 <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Forecasted_Units_Q3_2010__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Forecasted Units Q3 2010" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:inputField value="{!o.Forecasted_Units_Q3_2010__c}"/>
                </apex:column>
		 <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.LQ4__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="LQ4 2009" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.LQ4__c}"/>
                </apex:column>
		 <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Forecasted_Units_Q4_2010__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Forecasted Units Q4 2010" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:inputField value="{!o.Forecasted_Units_Q4_2010__c}"/>
                </apex:column>
		<apex:column headerValue="Agree With Forecast">
			<apex:inputField value="{!a.Agree_With_Forecast__c}"/>
		</apex:column>
		<apex:column headerValue="Comments on Style Forecast">
			<apex:inputTextarea value="{!a.Comments_on_Style_Forecast__c}" style="width:160px"/>
		</apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Any help will be greatly appreciated!

I understand if it's one of those "This guy has no idea what's going on, and it would be way too much work to fix this garbage for him." :)

 

 

  • May 13, 2010
  • Like
  • 0

Hi all,

 

Below is some code that I got to work with the help of everyone here on the forums as well as elsewhere on the internet, so I thought I would post it for everyone to view in case it might help someone else down the road who is looking for something similar.

 

What it does is allow you to enter a new record of a custom parent object (which, itself, has a master-detail to the Opportunity object) while also entering multiple records for the child object that will save under the parent.

 

When the "New" button is clicked from the related list of an Opportunity record, the Opportunity field is automatically populated.


Note: I have only used this class and VF page in the sandbox, as a learning experiment. Everything works as I would expect it to, however, I am very new to programming in general, so I would suggest creating your own test class, and testing this stuff out in your sandbox or developer edition first, if you want to use it.

 

Also, I don't expect this stuff to be perfect (or, for that matter, not broken), so I'm very open to suggestions on how to make this stuff cleaner or more efficient. 

 

I'll try to post some screen shots as well.

 

The VF page:

 

<apex:page StandardController="Custom_Parent__c" extensions="parentChild" id="thePage">
    <style>
        .container
            {
                margin-left:10%;
                border:1px;
            }
        .even
            {
                background-color:#eeeed1;
            }
        .odd
            {
            }
    </style>
    <apex:sectionHeader title="Parent and Child"/>
        <apex:Message />
    <apex:form >
        <apex:pageBlock id="pb" title="Parent Detail">
            <apex:pageBlockButtons >
                <apex:commandbutton value="Save" action="{!Save}"/>
                <apex:commandbutton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="2" showHeader="false">
                <apex:outputField value="{!parent.Opportunity__c}" id="getOppid"/>
                <apex:inputField value="{!parent.Field1__c}"/>
                <apex:inputField value="{!parent.Field2}"/>
                <apex:inputField value="{!parent.Field2__c}"/>
                <apex:inputField value="{!parent.Field3__c}"/>
                &nbsp;
                <apex:inputField value="{!parent.Field4__c}"/>
                &nbsp;
                <apex:inputField value="{!parent.Field5__c}"/>
                <br/>
                <br/>
                <br/>      
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Child" columns="1" collapsible="false"> 
                <apex:pageBlock id="pb1">
                    <apex:pageMessages />
                    <apex:outputPanel layout="block" styleClass="container"> 
                    <apex:pageBlockTable value="{!lstInner}" var="c" id="therepeat" style="width:460px;padding:4px;" rowClasses="even,odd">
                        <apex:column headerValue="Column 1 Header" style="border:1px solid #f3f3eb;">
                            <apex:inputField value="{!c.child.Col1__c}" style="width:3em;"/>
                        </apex:column>
                        <apex:column headerValue="Column 2 Header" style="border:1px solid #f3f3eb;">
                            <apex:inputField value="{!c.child.Col2__c}"/>
                        </apex:column>
                        <apex:column headerValue="Column 3 Header" style="border:1px solid #f3f3eb;">
                            <apex:inputField value="{!c.child.Col3__c}" style="width:2em;"/>
                        </apex:column>
                        <apex:column style="border:1px solid #f3f3eb;">
                            <apex:commandLink value="Remove" action="{!Del}" rerender="pb1">
                                <apex:param name="rowToBeDeleted" value="{!c.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                            </apex:commandLink>
                        </apex:column>
                        
                    </apex:pageBlockTable>
                    <apex:commandLink value="Add Row" action="{!Add}" rerender="pb1"/>
                </apex:outputPanel>
                </apex:pageBlock>
            </apex:pageBlockSection>
            <apex:pageBlockSection columns="1" title="New Section Title" collapsible="false">
                <apex:inputField value="{!parent.Field6__c}" style="width:400px;"/>
            </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>
</apex:page>

 

 

The Apex class:

 

 

public class parentChild {

    public List<Custom_Child__c> children  = new List<Custom_Child__c>();
    public List<innerClass> lstInner {get;set;}
    public String selectedRowIndex {get;set;}  
    public Integer count = 1;
    Custom_Parent__c parent;
    
    public Custom_Parent__c getparent(){
        if(parent == null) parent = new Custom_Parent__c();
        return parent;
    }
    
    public String getOppid(){
        String q = ApexPages.currentPage().getParameters().get('OppId');
        return q;
    }

    public PageReference Save(){
        try{
            for(Integer j = 0;j<lstInner.size();j++){
                children.add(lstInner[j].child);
            } 
            insert parent;
            for (Custom_Child__c sku : children){
                sku.Custom_Parent__c = parent.id;
            }
            insert children;
        }
        catch(DmlException ex){
            ApexPages.addMessages(ex);
        } 
        PageReference pr = new PageReference('/'+parent.id);
        pr.setRedirect(True);
        return pr;
    }
        
    public void Add(){   
        count = count+1;
        addMore();      
    }

    public void addMore(){
        innerClass objInnerClass = new innerClass(count);
        lstInner.add(objInnerClass);    
        system.debug('lstInner---->'+lstInner);            
    }
    
    public void Del(){
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;  
    }

    public parentChild(ApexPages.StandardController ctlr){
        this.parent = (Custom_Parent__c)ctlr.getRecord();
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';   
    }

    public class innerClass {       
        
        public String recCount {get;set;}
        public Custom_Child__c child {get;set;}
        
        public innerClass(Integer intCount){
            recCount = String.valueOf(intCount);        
            child = new Custom_Child__c();
        }  
    }
}

 

 

I've tried to replace all of my actualy object and field names with generic ones, so I apologized if I missed something.

Anyhow, let me know what you think! And hopefully this helps someone. :)

 

 

  • July 07, 2010
  • Like
  • 1

Hi all,

 

I tried to update User  Object, but it didn't work.

Then I got an error message which is '"Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []".

 

Here is VF.

<apex:page standardController="User" extensions="userExtension2" sidebar="false">
<apex:pageMessages showDetail="true" />
 <apex:sectionHeader title="AAA" subtitle="{!$User.LastName} {!$User.FirstName}"></apex:sectionHeader>
    <apex:form >
        <apex:pageBlock title="BBB">
            <apex:pageBlockButtons>
                <apex:commandButton action="{!save}" value="save"></apex:commandButton>
                <apex:commandButton action="{!cancel}" value="cancel"></apex:commandButton>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="CCC" collapsible="false" columns="1">
                <apex:inputField value="{!User.testField1__c}"></apex:inputField>
                <apex:inputField value="{!User.testField2__c}"></apex:inputField>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Here is Controller Extensions.

public class userExtension2 {
   private final User u;

   public userExtension2(ApexPages.StandardController stdController) {
      this.u = (User)stdController.getRecord();
   }

   public PageReference save() {
      try {
         update u;
      }
      catch (DmlException e) {
      }
   }
   return null;
}

 

 

Hi,

How do you create/display a small popup windows right in the middle just to inform the users some information and when a user click Ok the popup window will go away? Please advice. Please send sample codes if available.

 

thanks

Paul

 

  • August 02, 2010
  • Like
  • 0

Hi,

 

I have an object called meeting note and a child object called attendee.

 

When you create a meeting you can add as many attendees as you want.

 

What I would like to happen is when you add an attendee and hit save you are returned not to the attendee record but to the linked meeting note.

 

Thanks

 

Ross

Hi all,

I want a custom button next to RequestUpdate button (let it be: mybutton). I have created mybutton :)

 

When mybutton is clicked a blank mail should be sent to the contact i have chosen (the contact under me)

 

Help me. Thanks .

Japp

Hi all,

 

I have a custom extension I am using with a VF page that replaces the "new" button of the object. The object is a child of Opportunities and, and the records are created from an Opportunity related list.  I have the Opportunity field on the object auto-populating, but I would like an Account look-up field to auto populate as well with the Account related to the Opportunity, as I would like a related list of the custom object on Account records. 

 

Is there a way to do it in the extension, or will I have to use a before insert trigger?

 

Thanks

  • July 19, 2010
  • Like
  • 0

Hi all,

 

Below is some code that I got to work with the help of everyone here on the forums as well as elsewhere on the internet, so I thought I would post it for everyone to view in case it might help someone else down the road who is looking for something similar.

 

What it does is allow you to enter a new record of a custom parent object (which, itself, has a master-detail to the Opportunity object) while also entering multiple records for the child object that will save under the parent.

 

When the "New" button is clicked from the related list of an Opportunity record, the Opportunity field is automatically populated.


Note: I have only used this class and VF page in the sandbox, as a learning experiment. Everything works as I would expect it to, however, I am very new to programming in general, so I would suggest creating your own test class, and testing this stuff out in your sandbox or developer edition first, if you want to use it.

 

Also, I don't expect this stuff to be perfect (or, for that matter, not broken), so I'm very open to suggestions on how to make this stuff cleaner or more efficient. 

 

I'll try to post some screen shots as well.

 

The VF page:

 

<apex:page StandardController="Custom_Parent__c" extensions="parentChild" id="thePage">
    <style>
        .container
            {
                margin-left:10%;
                border:1px;
            }
        .even
            {
                background-color:#eeeed1;
            }
        .odd
            {
            }
    </style>
    <apex:sectionHeader title="Parent and Child"/>
        <apex:Message />
    <apex:form >
        <apex:pageBlock id="pb" title="Parent Detail">
            <apex:pageBlockButtons >
                <apex:commandbutton value="Save" action="{!Save}"/>
                <apex:commandbutton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="2" showHeader="false">
                <apex:outputField value="{!parent.Opportunity__c}" id="getOppid"/>
                <apex:inputField value="{!parent.Field1__c}"/>
                <apex:inputField value="{!parent.Field2}"/>
                <apex:inputField value="{!parent.Field2__c}"/>
                <apex:inputField value="{!parent.Field3__c}"/>
                &nbsp;
                <apex:inputField value="{!parent.Field4__c}"/>
                &nbsp;
                <apex:inputField value="{!parent.Field5__c}"/>
                <br/>
                <br/>
                <br/>      
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Child" columns="1" collapsible="false"> 
                <apex:pageBlock id="pb1">
                    <apex:pageMessages />
                    <apex:outputPanel layout="block" styleClass="container"> 
                    <apex:pageBlockTable value="{!lstInner}" var="c" id="therepeat" style="width:460px;padding:4px;" rowClasses="even,odd">
                        <apex:column headerValue="Column 1 Header" style="border:1px solid #f3f3eb;">
                            <apex:inputField value="{!c.child.Col1__c}" style="width:3em;"/>
                        </apex:column>
                        <apex:column headerValue="Column 2 Header" style="border:1px solid #f3f3eb;">
                            <apex:inputField value="{!c.child.Col2__c}"/>
                        </apex:column>
                        <apex:column headerValue="Column 3 Header" style="border:1px solid #f3f3eb;">
                            <apex:inputField value="{!c.child.Col3__c}" style="width:2em;"/>
                        </apex:column>
                        <apex:column style="border:1px solid #f3f3eb;">
                            <apex:commandLink value="Remove" action="{!Del}" rerender="pb1">
                                <apex:param name="rowToBeDeleted" value="{!c.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                            </apex:commandLink>
                        </apex:column>
                        
                    </apex:pageBlockTable>
                    <apex:commandLink value="Add Row" action="{!Add}" rerender="pb1"/>
                </apex:outputPanel>
                </apex:pageBlock>
            </apex:pageBlockSection>
            <apex:pageBlockSection columns="1" title="New Section Title" collapsible="false">
                <apex:inputField value="{!parent.Field6__c}" style="width:400px;"/>
            </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>
</apex:page>

 

 

The Apex class:

 

 

public class parentChild {

    public List<Custom_Child__c> children  = new List<Custom_Child__c>();
    public List<innerClass> lstInner {get;set;}
    public String selectedRowIndex {get;set;}  
    public Integer count = 1;
    Custom_Parent__c parent;
    
    public Custom_Parent__c getparent(){
        if(parent == null) parent = new Custom_Parent__c();
        return parent;
    }
    
    public String getOppid(){
        String q = ApexPages.currentPage().getParameters().get('OppId');
        return q;
    }

    public PageReference Save(){
        try{
            for(Integer j = 0;j<lstInner.size();j++){
                children.add(lstInner[j].child);
            } 
            insert parent;
            for (Custom_Child__c sku : children){
                sku.Custom_Parent__c = parent.id;
            }
            insert children;
        }
        catch(DmlException ex){
            ApexPages.addMessages(ex);
        } 
        PageReference pr = new PageReference('/'+parent.id);
        pr.setRedirect(True);
        return pr;
    }
        
    public void Add(){   
        count = count+1;
        addMore();      
    }

    public void addMore(){
        innerClass objInnerClass = new innerClass(count);
        lstInner.add(objInnerClass);    
        system.debug('lstInner---->'+lstInner);            
    }
    
    public void Del(){
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;  
    }

    public parentChild(ApexPages.StandardController ctlr){
        this.parent = (Custom_Parent__c)ctlr.getRecord();
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';   
    }

    public class innerClass {       
        
        public String recCount {get;set;}
        public Custom_Child__c child {get;set;}
        
        public innerClass(Integer intCount){
            recCount = String.valueOf(intCount);        
            child = new Custom_Child__c();
        }  
    }
}

 

 

I've tried to replace all of my actualy object and field names with generic ones, so I apologized if I missed something.

Anyhow, let me know what you think! And hopefully this helps someone. :)

 

 

  • July 07, 2010
  • Like
  • 1

Hi all,

 

I need to add the Orders__c.ID value to every Ordered_SKU__c.Order__c field on save.  I can't figure out how to get it in there... Any suggestions?

 

 

public class orderInsert {

Orders__c orders;
List<Ordered_SKU__c> skus {get; set;}

public Orders__c getOrders(){
if(orders == null){
orders = new Orders__c();
}
return orders;
}

public orderInsert(){
skus = new List<Ordered_SKU__c>();
skus.add(New Ordered_SKU__c()); // I've tried (New Ordered_SKU__c(Order__c = orders.id)); but obviously that returns a null value.
}

public void addrow(){
skus.add(new Ordered_SKU__c());
}

public PageReference save() {
try{
insert orders;
insert skus;
}
catch(DmlException ex){
ApexPages.addMessages(ex);
}
PageReference pr = new PageReference('/'+orders.id);
pr.setRedirect(true);
return pr;
}
}

 

 

  • June 29, 2010
  • Like
  • 0

I've added the following extension to a visualforce page. The page's object is a child of Opportunities. After saving a record in this child object, I'd like to be redirected back to the parent record.

 

I don't know how to get the parent Opportunity record ID to reference in the PageReference method.

 

(I know my custom object is called TestParent... this is because it is actually the parent of another custom object, TestChild. :smileytongue: )

 

 

public class testParentSave {

public TestParent__c parent {get; set;}

public testParentSave(ApexPages.StandardController controller) {
parent = (TestParent__c) controller.getRecord();
}

public PageReference save() {
insert parent;
PageReference pr = new PageReference('/'+TestParent__c.Opportunity__c);
pr.setRedirect(true);
return pr;
}
}

 

 

  • June 15, 2010
  • Like
  • 0

I'm having trouble forcing these 2 pageBlocks to be the same size. Any suggestions?

I would like 'My Chatter' to take up 50% of the page and 'Whose following who?' to take 50% as well.

 

Hi all,

 

I'm currently using the following class:

 

public with sharing class classTest{
    
    public classTest(ApexPages.StandardSetController controller) {
    }
    
    List<Dealer_Forecast__c> dfc;
    public String myUserID = UserInfo.getUserId();

    public List<Dealer_Forecast__c> getDfc(){
        if(dfc == null){
            dfc = [SELECT Account__c,Style__c, Region__c, Territory__c
                FROM Dealer_Forecast__c 
                WHERE Account__r.OwnerId =:myUserID];
        }    
        
        return dfc;
    }
}
    

 

 

 

But instead of creating the list where the owner of the account is the current user, I'd like to pull records where a custom field on the related Account = a custom field on the current user's User record. So I changed the code to the following:

 

public with sharing class classTest{
    
    public classTest(ApexPages.StandardSetController controller) {
    }
    
    public String userlist {get; set;}
    List<Dealer_Forecast__c> dfc;
    public String myUserID = UserInfo.getUserId();

    public String getUserlist(){  
        userlist = [SELECT Report_Server_Co_Id__c FROM User WHERE id = :myUserID LIMIT 1].Report_Server_Co_Id__c;
        return userlist;   
    }
    public Integer userterr = Integer.valueOf(userlist);
    
    public List<Dealer_Forecast__c> getDfc(){
        if(dfc == null){
            dfc = [SELECT Account__c,Style__c, Region__c, Territory__c
                FROM Dealer_Forecast__c 
                WHERE Account__r.Territory__c =:userterr];
        }    
        
        return dfc;
    }
}
    

 

 

 

I am able to save the class, but when the code is executed, I get an error stating "Argument 1 cannot be null". I imagine the way I'm trying to achieve what is I need is completely incorrect.

 

Any suggestions?

Thanks!

 

  • June 09, 2010
  • Like
  • 0

I'm using this bit of code to allow a save button on a page to save a list, but I'd like the button to redirect the user to a different page after they click Save, much like the Cancel button does now.

 

 

public PageReference cancel() {
          PageReference pr = new PageReference('/a0G/o');
          pr.setRedirect(true);
          return pr;
          }
    public void save() {
    
        try{
            update pfc;
        }
        catch(DmlException ex){
            ApexPages.addMessages(ex);
            
        }
        }
           

 

 

The save method works, in that what is edited in the list saves, I would just like to add the same PageReference bit from the cancel method to the save method, and I don't know how to do that. :smileyindifferent:

 

Ideally both cancel and save buttons would direct the user back to the List View from where the visualforce page that uses this class is accessed, but simply redirecting back to the object URL is fine.

 

Any help would be greatly appreciated!

 

  • May 14, 2010
  • Like
  • 0

Hi all!

 

I have only one or two weeks experience with Apex and Visualforce, and no coding experience, so please bear with me.

I altered the MassEdit visualforce page to the specifications of my supervisor, but we now we need to be able to sort the fields.

Having no experience with Apex or Java or anything, I was hoping I could sort of copy/paste the code from this Sorting Tables tutorial and replace the components that made sense.  It's not really working out.

 

Not being in Developer Edition, I'm having to use the Force.com IDE through Eclipse.

Here's the class:

 

 

public with sharing class massEditSort {

    List<Product_Forecasting__c> fcs;
    public String sortField {get; set;}
    public String previousSortField {get; set;}
    
    public List<Product_Forecasting__c> getFcs() {
        if(fcs == null){
            fcs = [select Forecast_For_Month__c, Style__c, Color_Code__c, Product_Description__c, Color__c, LQ2__c, Forecasted_Units_Q2_c__c, LQ3__c, Forecasted_Units_Q3_2010__c, Forecasted_Units_Q4_2010__c from Product_Forecasting__c];
        }
        return fcs;
    }
    
    public void doSort(){
        String order = 'asc';
        
        /*This checks to see if the same header was click two times in a row, if so 
        it switches the order.*/
        if(previousSortField == sortField){
            order = 'desc';
            previousSortField = null;
        }else{
            previousSortField = sortField;
        }
       
        //To sort the table we simply need to use this one line, nice!
        superSort.sortList(fcs,sortField,order);
    }
}

 

 

Now when I try to save this, I get an error that reads: Average test coverage across all Apex Classes and Triggers is 74%, at least 75% test coverage is required

And also the error: Save error: Method does not exist or incorrect signature: superSort.sortList(LIST:SOBJECT:Product_Forecasting__c, String, String)

 

Here is the Visualforce Page I am trying to get to work with this controller:

 

 

<apex:page controller="massEditSort">
    <apex:form >
        
	<apex:pageBlock >
		Note: All modifications made on the page will be lost if Cancel button is clicked without clicking the Save button first.<br />
		<p style="color:red"><u>Do not click the "Agree With Forecast" checkbox if you update or change any other field.</u></p>
	</apex:pageBlock>
	<apex:pageBlock >
	<apex:pageBlockButtons >
		<apex:commandButton value="Save" action="{!save}"/>
		<apex:commandButton value="Cancel" action="{!cancel}"/>
	</apex:pageBlockButtons>            

	<apex:pageBlockTable value="{!selected}" var="o" id="table">
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Forecast_For_Month__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Forecast For Month:" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.Forecast_For_Month__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Style__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Style#" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.Style__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Color_Code__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Color Code" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.Color_Code__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Product_Description__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Product Description" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.Product_Description__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Color__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Color" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.Color__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.LQ2__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="LQ2 2009" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.LQ2__c}"/>
                </apex:column>
                 <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Forecasted_Units_Q2_c__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Forecasted Units Q2 2010" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:inputField value="{!o.Forecasted_Units_Q2_c__c}"/>
                </apex:column>
		 <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.LQ3__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="LQ3 2009" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.LQ3__c}"/>
                </apex:column>
		 <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Forecasted_Units_Q3_2010__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Forecasted Units Q3 2010" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:inputField value="{!o.Forecasted_Units_Q3_2010__c}"/>
                </apex:column>
		 <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.LQ4__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="LQ4 2009" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!o.LQ4__c}"/>
                </apex:column>
		 <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink value="{!$ObjectType.Product_Forecasting__c.Fields.Forecasted_Units_Q4_2010__c.Label}" action="{!doSort}" rerender="table">
                            <apex:param name="sortField" value="Forecasted Units Q4 2010" assignTo="{!sortField}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:inputField value="{!o.Forecasted_Units_Q4_2010__c}"/>
                </apex:column>
		<apex:column headerValue="Agree With Forecast">
			<apex:inputField value="{!a.Agree_With_Forecast__c}"/>
		</apex:column>
		<apex:column headerValue="Comments on Style Forecast">
			<apex:inputTextarea value="{!a.Comments_on_Style_Forecast__c}" style="width:160px"/>
		</apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Any help will be greatly appreciated!

I understand if it's one of those "This guy has no idea what's going on, and it would be way too much work to fix this garbage for him." :)

 

 

  • May 13, 2010
  • Like
  • 0

How can I make a page that has both Master Record and Detail Records on the same page for data entry?

 

I have a Header Table and a Line Table and would like to be able to enter the Header Details at the top of the page and then be able to add multiple lines associated with the Header, all from within the same page.

 

So the Page would look somewhat like:

 

Header Field 1 Header Feild 2 Header Field 3

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

 

Row 1 = Detail Field 1 Detail Field 2 Detail Field 3 Detail Field 4

Row 2 = Detail Field 1 Detail Field 2 Detail Feild 3 Detail Field 4 

.

.

 

 

Thanks. 

  • June 18, 2009
  • Like
  • 0
Hi,
 
I created a visualforce page( on a custom object),  to overide my standard "New" Button. 
I used the input field component to input data into 2 required lookup fields but every time i type data into these fields i get an error message
Error: Required fields are missing: [Project__c, Training_Grant__c], 
my code looks like this;
 
<apex:page standardController="Training2__c">
<apex:form >
<apex:pageBlock title="Training Edit" mode="edit">
 <apex:commandButton action="{!save}" value="Save">
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:commandButton>
    </apex:pageBlock>
  </apex:form>
  <apex:form >
  <apex:pageBlock >
 <apex:pageBlockSection title="Project Information" columns="2">
        <apex:inputField value="{!Training2__c.Project__c}"/>
        <apex:inputField value="{!Training2__c.Training_Grant__c}"/>
        <apex:inputField value="{!Training2__c.Current_Balance__c}"/>
        <apex:inputField value="{!Training2__c.Total_TE_fee_Balance__c}"/>
        <apex:inputField value="{!Training2__c.TE_Balance__c}"/>

        <apex:inputField value="{!Training2__c.Region__c}"/>
    <apex:inputField value="{!Training2__c.Stichting_Funds_Approval_Date__c}"/>
         </apex:pageBlockSection>
   </apex:pageBlock>
    </apex:form>
</apex:page>
  • September 18, 2008
  • Like
  • 0