function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ranganath C NRanganath C N 

how to add records from one object to another new object like adding products to cart...please can anyone help me with this

Kamal ThakurKamal Thakur
Hi Ranganath,

Do you want to have the functionality of "Products to Cart" Or do you want to Add Records from one object to other. There's a huge difference between both. Do let me know. 

Thanks.
Ranganath C NRanganath C N
Thank you for ur reply sir. i need code for adding products to cart.
Ranganath C NRanganath C N
i have product object...i need to add those products to cart
Ranganath C NRanganath C N
contd...
by calling cart as new object....i.e,copy the records from product object to cart object
Kamal ThakurKamal Thakur
Do you want to copy all the Records from Product Object to Cart Object?
Ranganath C NRanganath C N
I am diplaying all the product records in a table , by using addtocart button corresponding to each record i am adding products to cart
Kamal ThakurKamal Thakur
Okay, I understand. If you have written any code please mention it here, we're glad to help. 

Or you want us to write the whole code?

Regards.
Ranganath C NRanganath C N
Thankyou sir,
Till diplaying the records its completed....but addtocart programming i need sir.
Kamal ThakurKamal Thakur
Are you using VF? Put your code here so that we can help. 
Ranganath C NRanganath C N
VF PAGE

<apex:page Controller="proj1" docType="html-5.0" > 
    <apex:form > 
    
        <apex:selectList size="1" value="{!searchstring}"> 
            <apex:selectOptions value="{!listOfStrings }"/>  
        </apex:selectList>
        
        <apex:commandButton value="Search records" action="{!search}" /> 
        <apex:commandButton value="Clear records" action="{!clear}" /> 
        
        <apex:pageBlock title="Search Result"> 
            <apex:pageblockTable value="{!acc}" var="a"> 
                <apex:column value="{!a.name}"/> 
                <apex:column value="{!a.ProductCode }"/> 
                <apex:column value="{!a.Quantity__c}"/> 
                <apex:column value="{!a.UnitPrice__c}"/> 
                <apex:column > <apex:commandButton value="AddToCart"   /> </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock> 
        
    </apex:form> 
</apex:page>



CONTROLLER

public with sharing class proj1{ 
    public String Product2{ get; set; }

public list <Product2> acc {get;set;} 
public string searchstring {get;set;} 
public list<Selectoption> listOfStrings {get; set;}

public proj1( ) { 
    listOfStrings = new List<Selectoption>();
      for(Product2 a: [SELECT  Name,  ProductCode,IsActive From Product2 LIMIT 50])
       listOfStrings.add(new selectoption(a.name,a.name));
     // listOfStrings.add(a.name);



public void search(){
string searchquery='select name,ProductCode,Quantity__c,UnitPrice__c from product2 where name like \'%'+searchstring +'%\' Limit 30';
acc= Database.query(searchquery); 
}

public void clear(){ 
acc.clear(); 

}