• Anji P 9
  • NEWBIE
  • 30 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 5
    Replies
when i insert contact child record of account it will take that one only but its asking remaining child records i mean opportunity,case records also how to solve this problem. 


vf page:

<apex:page controller="Account_insert_con">
    <apex:form >
        <apex:pageBlock id="pb" title="Account list" >
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="save" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlocksection title="account data" id="pbs">
                <apex:inputField value="{!wraps.acc.name}"/>
                <apex:inputfield value="{!wraps.acc.type}"/>
                <apex:inputfield value="{!wraps.acc.phone}"/>
               <apex:inputField value="{!wraps.acc.industry}"/>
            </apex:pageBlocksection>
            <apex:pageBlockSection columns="1"  title="contact list" >
                <apex:pageBlockTable value="{!contacts}" var="c" id="pbt">
                    <apex:column headerValue="firstname">
                        <apex:inputtext value="{!c.firstname}"/>
                    </apex:column>
                    <apex:column headerValue="lastname">
                    <apex:inputText value="{!c.lastname}"/>
                    </apex:column>
                    <apex:column headerValue="phone">
                        <apex:inputText value="{!c.phone}"/>
                    </apex:column>
                    <apex:column headerValue="Leadsource">
                        <apex:inputText value="{!c.leadsource}"/>
                    </apex:column>
                    <apex:column headerValue="AddRow" >
                        <apex:commandButton value="add" action="{!multichild}" id="pbs"/>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
            <apex:pageblocksection columns="1">
                <apex:pageblocktable value="{!opp}" var="o">
                    <apex:column headerValue="name">
                        <apex:inputText value="{!o.name}"/>
                       </apex:column>
                  
                     <apex:column headerValue="stagename">
                        <apex:inputText value="{!o.stagename}"/>
                    </apex:column>
                      <apex:column headerValue="ClosedDate">
                          <apex:inputText value="{!o.CloseDate}"/>
                    </apex:column>
                    <apex:column headerValue="AddRow">
                        <apex:commandbutton value="add" action="{!optyadd}" id="pbs"/>
                    </apex:column>
                </apex:pageblocktable>
            </apex:pageblocksection>
            <apex:pageblocksection columns="1">
                <apex:pageBlockTable value="{!cases}" var="c">
                    <apex:column headerValue="Origin">
                        <apex:inputText value="{!c.origin}"/>
                    </apex:column>
                    <apex:column headerValue="status">
                        <apex:inputText value="{!c.status}"/>
                    </apex:column>
                    <apex:column headerValue="AddRow">
                        <apex:commandButton value="caseadd" action="{!caseadd}" id="pbs"/>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageblocksection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

apex code:

public class Account_insert_con {
    public Account_insert_wrapper wraps{set;get;}
    public List<contact> contacts{set;get;}
    public List<opportunity> opp{set;get;}
    public List<case> cases{set;get;}
    public Account_insert_con(){
        wraps=new  Account_insert_wrapper();
        wraps.acc=new Account();
        wraps.con=new contact();
        opp=new List<opportunity>();
        cases=new list<case>();
        wraps.opps=new opportunity();
        contacts=new List<contact>();
        contacts.add(wraps.con);
        opp.add(wraps.opps);
        wraps.cs=new case();
        cases.add(wraps.cs);
        multichild();
        optyadd();
        caseadd();
    }
    public void multichild(){
        wraps.con=new contact();
        contacts.add(wraps.con);
        }
    public void optyadd(){
        wraps.opps=new opportunity();
        opp.add(wraps.opps);
    }
    
    public void caseadd(){
        wraps.cs=new case();
        cases.add(wraps.cs);
    }
    
    public PageReference save (){
        insert wraps.acc;
        System.debug('====>'+contacts);
        System.debug('====>'+opp);
        System.debug('====>'+cases);
        List<contact> cons=new List<contact>();
        if(contacts.size() != 0){
            System.debug('in contacts');
        for(contact c:contacts){
            c.Accountid=wraps.acc.id;
            cons.add(c);
        }
        insert cons;
        }

            List<opportunity> opportunities=new List<opportunity>();
        if(opp != null && opp.size() > 0)
           {    
            System.debug('in opportunities');
            for(opportunity o:opp){
                o.AccountId=wraps.acc.id;
                opportunities.add(o);
            }
            insert opportunities;
        }
                List<case> cc =new List<case>();
        if(cases != null && cases.size() > 0) {
            System.debug('in cases');
                for(case co: cases){
                    co.AccountId=wraps.acc.id;
                    cc.add(co);
                }
            insert cc;
        }
        PageReference p=new PageReference('/'+wraps.acc.id);
        return p;
    }

        
}

wrapper class:--

public class Account_insert_wrapper {
    public Account acc{set;get;}
    public contact con{set;get;}
    public opportunity opps{set;get;}
    public case cs{set;get;}
}
Vf page:
--------------------------


<apex:page controller="Account_Tasks">
    <apex:form>
    <apex:pageBlock id="pb">
        <apex:pageBlockButtons location="top">
        <apex:commandButton value="Save" action="{!save}" rerender="pb"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Account Details">
        <apex:inputField value="{!acc.Name}"/>
            <apex:inputField value="{!acc.Industry}"/>
            <apex:inputField value="{!acc.Phone}"/>
            <apex:inputField value="{!acc.ownership}"/>
            <apex:inputField value="{!acc.rating}"/>
        </apex:pageBlockSection>
        <apex:pageBlockSection title="Task Details" columns="1" id="pbs">
            <apex:pageBlockTable value="{!tsks}" var="t">
                <apex:column headerValue="Priority">
        <apex:inputField value="{!t.Priority}"/>
                    </apex:column>
                <apex:column headerValue="Status">
            <apex:inputField value="{!t.status}"/>
                    </apex:column>
                <apex:column headerValue="Status">
            <apex:inputField value="{!t.Tasksubtype}"/>
                    </apex:column>
                    <apex:column headerValue="Status">
            <apex:inputField value="{!t.calltype}"/>
                        </apex:column>
                        <apex:column headerValue="Status">
            <apex:inputField value="{!t.createdDate}"/>
                            </apex:column>
                <apex:column >
                <apex:commandButton value="ADD" action="{!AddTask}" rerender="pbs"/>
                </apex:column>
                </apex:pageBlockTable>
        </apex:pageBlockSection>
        <apex:pageBlockSection columns="1" id="pbs1">
            <apex:pageBlockTable value="{!attch}" var="att">
                <apex:column headerValue="File Name">
            <apex:inputField value="{!att.name}"/>
                    </apex:column>
                                <apex:column headerValue="Body">
            <apex:inputtext value="{!str}"/>
                    </apex:column>
                <apex:column>
                <apex:commandButton value="Add Attachment" action="{!AddAttachmnt}" rerender="pbs1"/>
                </apex:column>
         </apex:pageBlockTable>
        </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>



Apex code:
----------------------------

public class Account_Tasks {
    public account acc{set;get;}
    public task tsk{set;get;}
    public string str{set;get;}
    public list<attachment> attch{set;get;}
    public list<task>tsks{set;get;}
    public Account_Tasks(){
        attch=new List<attachment>();
        tsks=new list<task>();
        acc=new account();
        tsk=new Task();
        AddTask();
        AddAttachmnt();
    }
    public void AddTask(){
        tsk=new task();
        tsks.add(tsk);
    }
    public void AddAttachmnt(){
        str=null;
        attachment a=new attachment();
        attch.add(a);
    }
    
    public PageReference save(){
        insert acc;
       list<task> tasks=new list<task>();
        for(task t:tsks){
            t.whatid=acc.id;
            tasks.add(t);
        }
        insert tasks;
        list<attachment> attaches=new list<attachment>();
        for(attachment at:attch){
        at.ParentId=acc.Id;
        at.Name=acc.Name+'.pdf';
        at.Body=blob.toPdf(str);
            attaches.add(at);
     }
        insert attaches;
        Pagereference p=new Pagereference('/'+acc.id);
        return p;
        }
    
}
 
apex code:--

public class Pagination_Example {
    public Apexpages.StandardSetController controller {set;get;}
    public List<Opportunity> getOptyList(){
        List<Opportunity> opty=(List<Opportunity>)controller.getRecords();
        return opty;
    }
    public Pagination_Example (){
       List<opportunity> opps=[select id,name,stagename,amount from opportunity];
      controller=new apexpages.standardsetcontroller(opps);
        controller.setpagesize(10);
    }
    
}

vf page:--

<apex:page controller="Pagination_Example">
    <apex:form >
       <apex:pageblock id="pb">
        <apex:pageblockbuttons location="top">
        <apex:commandButton value="Previous" action="{!controller.previous}" rendered="{!controller.hasprevious}"/>
        <apex:commandButton value="First" action="{!controller.first}" rendered="{!controller.hasprevious}"/>
        <apex:commandButton value="Next" action="{!controller.Next}" rendered="{!controller.hasnext}"/>
        <apex:commandButton value="Last" action="{!controller.last}" rendered="{!controller.hasnext}"/>
        </apex:pageblockbuttons>
           <apex:pageBlockTable value="{!optylist}" var="a">
               <apex:column value="{!a.name}"/>
               <apex:column value="{!a.stagename}"/>
               <apex:column value="{!a.amount}"/>
           </apex:pageBlockTable>
           <apex:facet name="footer"> <h1>
            {!controller.pagenumber}&nbsp;&nbsp;of&nbsp;&nbsp;{!controller.resultsize}
         
               </h1>
           </apex:facet>
           </apex:pageblock>
    </apex:form>
</apex:page>
apex code:--

public class Pagination_Example {
    public Apexpages.StandardSetController controller {set;get;}
    public List<Opportunity> getOptyList(){
        List<Opportunity> opty=(List<Opportunity>)controller.getRecords();
        return opty;
    }
    public Pagination_Example (){
       List<opportunity> opps=[select id,name,stagename,amount from opportunity];
      controller=new apexpages.standardsetcontroller(opps);
        controller.setpagesize(10);
    }
    
}

vf page:--

<apex:page controller="Pagination_Example">
    <apex:form >
       <apex:pageblock id="pb">
        <apex:pageblockbuttons location="top">
        <apex:commandButton value="Previous" action="{!controller.previous}" rendered="{!controller.hasprevious}"/>
        <apex:commandButton value="First" action="{!controller.first}" rendered="{!controller.hasprevious}"/>
        <apex:commandButton value="Next" action="{!controller.Next}" rendered="{!controller.hasnext}"/>
        <apex:commandButton value="Last" action="{!controller.last}" rendered="{!controller.hasnext}"/>
        </apex:pageblockbuttons>
           <apex:pageBlockTable value="{!optylist}" var="a">
               <apex:column value="{!a.name}"/>
               <apex:column value="{!a.stagename}"/>
               <apex:column value="{!a.amount}"/>
           </apex:pageBlockTable>
           <apex:facet name="footer"> <h1>
            {!controller.pagenumber}&nbsp;&nbsp;of&nbsp;&nbsp;{!controller.resultsize}
         
               </h1>
           </apex:facet>
           </apex:pageblock>
    </apex:form>
</apex:page>