• NewToForceDevelopment
  • NEWBIE
  • 0 Points
  • Member since 2012

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

I have a payment object that has 2 properties amount and date. I have the following code in the Apex page and Controller that displays existing payments. I want to update amount of one payments and save it. What scode should i write in the save method to acheive this. I know i have to call update payment on the save method but i am not able to retrieve the user input from the page in my controller.

 

 

 

public with sharing class PaymentDetailsController

{    

public Decimal amount_c{get; set;}    

public Datetime date_c{get; set;}            

public PageReference save()

{        

Payment__c pc = new Payment__c();        

pc.Amount__c = amount_c;               

ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'Amount - '+ pc.Amount__c );         ApexPages.addMessage(myMsg);        

return null;    

}

List<Payment__c> payments = new List<Payment__c>();            

public PaymentDetailsController()    

{             

processLinkClick();       

}             

public void processLinkClick()

{

       payments = [SELECT Id , Payment__c.Contact__c, Amount__c, Date__c FROM Payment__c WHERE Amount__c > 0 and Payment__c.Contact__c =: ApexPages.currentPage().getParameters().get('contactid')];    

}

        

public List<Payment__c> GetPaymentDetails()   

 {       

 return payments;       

}            

}

 

 

 

<apex:page controller="PaymentDetailsController" tabStyle="Payment__c" >
<apex:form >
        <h1>{!$CurrentPage.parameters.contactid}</h1>
 
        <apex:pageBlock title="Payment Details">
<apex:pageblockSection >
<h1>Page Messages:</h1>
<apex:pageMessages showDetail="true" id="msg"/>
</apex:pageblockSection>             
            <apex:pageBlockTable value="{!PaymentDetails}" var="pd">
                <apex:column HeaderValue="Amount">
                    <apex:inputField value="{!pd.Amount__c}" id="amount_c" />
                </apex:column>               
                <apex:column headerValue="Date">
                    <apex:inputField value="{!pd.Date__c}" id="date_c"/>
                </apex:column>
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
       
    </apex:form>
</apex:page> 

I am trying to get the value of the inputfield when doing a save on that field.

The requirement is on save on this page should update the table with th enew values that are entered in the amount_c and date_c fields.

 

This is how my code looks...

 

public with sharing class PaymentDetailsController {

            public PageReference save() {

                  return null;

            }

}

 

 

<apex:page controller="PaymentDetailsController" tabStyle="Payment__c" >
<apex:form >
 
        <apex:pageBlock title="Payment Details">
            <apex:pageBlockTable value="{!PaymentDetails}" var="pd">
                <apex:column HeaderValue="Amount">
                    <apex:inputField value="{!pd.Amount__c}" id="amount_c"/>
                </apex:column>               
                <apex:column headerValue="Date">
                    <apex:inputField value="{!pd.Date__c}" id="date_c"/>
                </apex:column>
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
       
    </apex:form>
</apex:page>

 

I have custom object called payment and its parent is the standard object contact.  I am writing a trigger after insert of 'payment' object to update a field on the contact object.  I am able to get the payment object after insert in the trigger and also update it's properties but when i try to access the parent object (contact)  I am umable to what should the apex code for this look like.

 

trigger newPaymentTrigger on Payment__c (after insert) {    

Payment__c payment = [SELECT Id FROM Payment__c WHERE Id IN :Trigger.new];    

update payment;        

//Contact contact = [SELECT Id FROM Contact WHERE Id = :payment.Contact__c];

}

 

The commented line does not work because payment.Contact__c is null

 

The relation ship between the 2 objects is look up relation ship.

I have a payment object that has 2 properties amount and date. I have the following code in the Apex page and Controller that displays existing payments. I want to update amount of one payments and save it. What scode should i write in the save method to acheive this. I know i have to call update payment on the save method but i am not able to retrieve the user input from the page in my controller.

 

 

 

public with sharing class PaymentDetailsController

{    

public Decimal amount_c{get; set;}    

public Datetime date_c{get; set;}            

public PageReference save()

{        

Payment__c pc = new Payment__c();        

pc.Amount__c = amount_c;               

ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'Amount - '+ pc.Amount__c );         ApexPages.addMessage(myMsg);        

return null;    

}

List<Payment__c> payments = new List<Payment__c>();            

public PaymentDetailsController()    

{             

processLinkClick();       

}             

public void processLinkClick()

{

       payments = [SELECT Id , Payment__c.Contact__c, Amount__c, Date__c FROM Payment__c WHERE Amount__c > 0 and Payment__c.Contact__c =: ApexPages.currentPage().getParameters().get('contactid')];    

}

        

public List<Payment__c> GetPaymentDetails()   

 {       

 return payments;       

}            

}

 

 

 

<apex:page controller="PaymentDetailsController" tabStyle="Payment__c" >
<apex:form >
        <h1>{!$CurrentPage.parameters.contactid}</h1>
 
        <apex:pageBlock title="Payment Details">
<apex:pageblockSection >
<h1>Page Messages:</h1>
<apex:pageMessages showDetail="true" id="msg"/>
</apex:pageblockSection>             
            <apex:pageBlockTable value="{!PaymentDetails}" var="pd">
                <apex:column HeaderValue="Amount">
                    <apex:inputField value="{!pd.Amount__c}" id="amount_c" />
                </apex:column>               
                <apex:column headerValue="Date">
                    <apex:inputField value="{!pd.Date__c}" id="date_c"/>
                </apex:column>
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
       
    </apex:form>
</apex:page> 

I have custom object called payment and its parent is the standard object contact.  I am writing a trigger after insert of 'payment' object to update a field on the contact object.  I am able to get the payment object after insert in the trigger and also update it's properties but when i try to access the parent object (contact)  I am umable to what should the apex code for this look like.

 

trigger newPaymentTrigger on Payment__c (after insert) {    

Payment__c payment = [SELECT Id FROM Payment__c WHERE Id IN :Trigger.new];    

update payment;        

//Contact contact = [SELECT Id FROM Contact WHERE Id = :payment.Contact__c];

}

 

The commented line does not work because payment.Contact__c is null

 

The relation ship between the 2 objects is look up relation ship.