Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

i am making some changes in the controller and i want to save the updated data to the object in salesforce how can i do that?

 public void getMappingDetails(){


    for(Portfolio_Security_Mapping__c p:getPortfolioMapping(portfolioId))
    {            
        security=getSecurities(p.Security_Id__c).get(0);

        //calculating total_amount for each of the security available in a portfolio
        p.Total_Amount__c=p.Quantity__c*security.Current_Price__c;
        portfolio_amount+=p.Total_Amount__c;
        system.debug(' security beta ' + security.beta__c);
        beta=beta+(security.beta__c*p.Quantity__c);            
        quantity+=p.Quantity__c;

    }

    string searchquery='SELECT Portfolio_Amount__c,Portfolio_Beta__c FROM Portfolio__c where Id=\''+ portfolioId+'\'';
    portfolio=Database.query(searchquery);
    portfolio.get(0).Portfolio_Amount__c=portfolio_amount;
    portfolio_beta=Math.round((beta/quantity)*100.0)/100.0;
    portfolio.get(0).Portfolio_Beta__c=portfolio_beta;
    system.debug(' portfolio beta ' + portfolio_beta);

}    

i want to save the updated amount details back to the object in salesforce

share|improve this question
1  
didn't you add update portfolio; at the end of your method or are you having issues with that? –  highfive Jul 9 at 9:33
    
i realized what i had to add the same day only thank you for your help though –  Ankita Jul 14 at 10:58

2 Answers 2

Adding the following line should do the trick:

update portfolio;

UPDATE: Just seen highfive's comment. Glad we agree on the potential solution.

share|improve this answer

Use the following code to get the data saved. Just added the update statement at the end. public void getMappingDetails(){

for(Portfolio_Security_Mapping__c p:getPortfolioMapping(portfolioId))
{            
    security=getSecurities(p.Security_Id__c).get(0);

    //calculating total_amount for each of the security available in a portfolio
    p.Total_Amount__c=p.Quantity__c*security.Current_Price__c;
    portfolio_amount+=p.Total_Amount__c;
    system.debug(' security beta ' + security.beta__c);
    beta=beta+(security.beta__c*p.Quantity__c);            
    quantity+=p.Quantity__c;

}

string searchquery='SELECT Portfolio_Amount__c,Portfolio_Beta__c FROM Portfolio__c where Id=\''+ portfolioId+'\'';
portfolio=Database.query(searchquery);
portfolio.get(0).Portfolio_Amount__c=portfolio_amount;
portfolio_beta=Math.round((beta/quantity)*100.0)/100.0;
portfolio.get(0).Portfolio_Beta__c=portfolio_beta;
system.debug(' portfolio beta ' + portfolio_beta);
update portfolio;

}    
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.