You need to sign in to do that
Don't have an account?
ajay ambati
Issue on visualforce page
Iam developed one vfpage using custom controller.In this my requiremnt is retrieve all parent records(account related) in one pageblock table and all childrecords(contact related ) in one pgblocktable.so i done with this and its working iam retriving rcords of both but my another requiremnt is iam placed another button for save the records its not working iam getting error and also iam used inlineedit in this but not working below is my code
vfpage:
<apex:page controller="soql1" showHeader="false" >
<apex:form >
<apex:pageBlock title="listofparentrecordsacc" >
<apex:pageBlockButtons location="top" >
<apex:commandButton value="listofaccountsparent" action="{!myparentrecords}" />
<apex:commandButton value="listofcontactchid" action="{!mychildrecords}" />
<apex:commandButton value="save" action="{!save}" />
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!lst}" var="a" rendered="{!show}" >
<apex:column value="{!a.name}"/>
<apex:column value="{!a.industry}"/>
<apex:column headerValue="contacts">
<apex:repeat value="{!a.contacts}" var="b">
{!b.firstname}<br/>
</apex:repeat>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!cnt}" var="c" rendered="{!show1}">
<apex:column value="{!c.firstname}"/>
<apex:column value="{!c.lastname}"/>
<apex:column value="{!c.account.name}"/>
</apex:pageBlockTable>
<apex:inlineEditSupport />
<apex:pageblockTable value="{!lst1}" var="s">
<apex:column value="{!s.name}"/>
<apex:column value="{!s.industry}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:
public class soql1
{
public string na {get;set;}
public string ind {get;set;}
public list<account> lst2 {get;set;}
public boolean show {get;set;}
public boolean show1 {get;set;}
public list<account> lst {get;set;}
public list<account> lst1 {get;set;}
public list<schema.contact> cnt{get;set;}
public void myparentrecords()
{
show=true;
show1=false;
lst=[select id,name,industry,(select id,firstname from contacts)from account];
}
public void mychildrecords()
{
show=false;
show1=true;
cnt=[select id,firstname,lastname,account.name from contact];
}
public PageReference save(){
account a=new account();
a.Name=na;
a.industry=ind;
// lst2 = [select id,name,industry from account ];
//if(a.name =='')
//{
//a.name=na;
lst1.add(a);
//}
insert lst1;
return null;
}
}
vfpage:
<apex:page controller="soql1" showHeader="false" >
<apex:form >
<apex:pageBlock title="listofparentrecordsacc" >
<apex:pageBlockButtons location="top" >
<apex:commandButton value="listofaccountsparent" action="{!myparentrecords}" />
<apex:commandButton value="listofcontactchid" action="{!mychildrecords}" />
<apex:commandButton value="save" action="{!save}" />
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!lst}" var="a" rendered="{!show}" >
<apex:column value="{!a.name}"/>
<apex:column value="{!a.industry}"/>
<apex:column headerValue="contacts">
<apex:repeat value="{!a.contacts}" var="b">
{!b.firstname}<br/>
</apex:repeat>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!cnt}" var="c" rendered="{!show1}">
<apex:column value="{!c.firstname}"/>
<apex:column value="{!c.lastname}"/>
<apex:column value="{!c.account.name}"/>
</apex:pageBlockTable>
<apex:inlineEditSupport />
<apex:pageblockTable value="{!lst1}" var="s">
<apex:column value="{!s.name}"/>
<apex:column value="{!s.industry}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:
public class soql1
{
public string na {get;set;}
public string ind {get;set;}
public list<account> lst2 {get;set;}
public boolean show {get;set;}
public boolean show1 {get;set;}
public list<account> lst {get;set;}
public list<account> lst1 {get;set;}
public list<schema.contact> cnt{get;set;}
public void myparentrecords()
{
show=true;
show1=false;
lst=[select id,name,industry,(select id,firstname from contacts)from account];
}
public void mychildrecords()
{
show=false;
show1=true;
cnt=[select id,firstname,lastname,account.name from contact];
}
public PageReference save(){
account a=new account();
a.Name=na;
a.industry=ind;
// lst2 = [select id,name,industry from account ];
//if(a.name =='')
//{
//a.name=na;
lst1.add(a);
//}
insert lst1;
return null;
}
}
<apex:page StandardController="provide your object name" extensions="soql1" showHeader="false" >
code:
public void save(){
//account a=new account();
//a.Name=na;
//a.industry=ind;
lst2 = [select id,name,industry from account ];
for(account a:lst2)
{
if(a.name =='')
{
//a.name=na;
lst1.add(a);
}
insert lst1;
//return null;
}
Visualforce Error
Help for this Page
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page vfsoql1: Class.soql1.save: line 38, column 1
Class.soql1.save: line 38, column 1