Using columns in a visual force page - salesforce

I have a record field I am for a revenue breakdown. I need my columns to look like they do in the picture, which is the code I will display, except I need the revenue classification in the left column to be bottom in the right column.
When I try I get errors like cannot more than two child elements under page block items.
<apex:page standardController="EventPackageRevenueBreakdown__c"
extensions="EventPackageRevenueBreakdownExt" standardStylesheets="true"
tabstyle="EventPackageRevenueBreakdown__c">
<apex:form >
<apex:pageBlock mode="edit"
title="Event Package Revenue Breakdown Edit">
<apex:pageblockbuttons >
<apex:commandbutton action="{!save}" value="{!$Label.Package_Save}"></apex:commandbutton>
<apex:commandbutton action="{!SaveAndNew}"
value="{!$Label.Package_SaveAndNew}"></apex:commandbutton>
<apex:commandbutton action="{!cancel}"
value="{!$Label.Package_Cancel}"></apex:commandbutton>
</apex:pageblockbuttons>
<apex:pagemessages ></apex:pagemessages>
<apex:pageblocksection id="PackageEventInformationPBS"
title="{!$Label.Package_Information}">
<apex:pageBlockSectionItem >
<apex:outputpanel layout="block" styleClass="requiredInput"></apex:outputpanel>
</apex:pageBlockSectionItem>
<apex:outputpanel layout="block" styleClass="requiredBlock"></apex:outputpanel>
<apex:inputfield required="true"
value="{!EventPackageRevenueBreakdown__c.UnitPrice__c}"></apex:inputfield>
<apex:inputfield required="true"
value="{!EventPackageRevenueBreakdown__c.Location__c}"></apex:inputfield>
<apex:inputfield required="true"
value="{!EventPackageRevenueBreakdown__c.Name}"></apex:inputfield>
<apex:outputfield value="{!EventPackageRevenueBreakdown__c.BookingPackageEvent__c}" />
<apex:inputfield required="true"
value="{!EventPackageRevenueBreakdown__c.RevenueClassification__c}"></apex:inputfield>
</apex:pageblocksection>
<apex:pageblocksection title="Admin and Gratuity">
<apex:pageBlockSectionItem >
<apex:outputpanel layout="block" styleClass="requiredInput"></apex:outputpanel>
</apex:pageBlockSectionItem>
<apex:outputpanel layout="block" styleClass="requiredBlock"></apex:outputpanel>
<apex:inputfield required="false"
value="{!eventItem.AdminCharge__c}"></apex:inputfield>
<apex:inputfield required="false" value="{!eventItem.Gratuity__c}"></apex:inputfield>
</apex:pageblocksection>
</apex:pageBlock>
</apex:form>
</apex:page>

If the pageBlockSection is set to two columns (the default, I believe) then it lays out it's fields Left->Right, then down a row, then Left->Right again.
To push a field over , you can add an empty pageBlockSectionItem
You should layout out your fields like this:
<apex:pageblocksection id="PackageEventInformationPBS" title="{!$Label.Package_Information}" columns="2">
<apex:inputfield required="true" value="{!EventPackageRevenueBreakdown__c.UnitPrice__c}"/>
<apex:inputfield required="true" value="{!EventPackageRevenueBreakdown__c.Location__c}"/>
<apex:inputfield required="true" value="{!EventPackageRevenueBreakdown__c.Name}"/>
<apex:outputfield value="{!EventPackageRevenueBreakdown__c.BookingPackageEvent__c}"/>
</apex:pageBlockSectionItem> <!-- empty selectItem--> <apex:pageBlockSectionItem/>
<apex:inputfield required="true" value="{!EventPackageRevenueBreakdown__c.RevenueClassification__c}"/>
</apex:pageblocksection>

Related

im trying to add commandLink to my visualforce form but it doesnt exist

im trying to add commandlink to my vf pageblock table but its not even exist. I get 0 error in developer console but it doesnt work. i tried to add it into column and it doesnt work tried alot of things please help me
<apex:page standardController="Account" >
<apex:form >
<apex:pageBlock title="Account Primary Contact" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{! Account.Name }"/>
<apex:inputField value="{! Account.Phone }"/>
<apex:inputField value="{! Account.ID }"/>
<apex:inputField value="{! Account.Type}"/>
<apex:inputField value="{! Account.Phone }"/>
<apex:inputField value="{! Account.AccountNumber }"/>
<apex:inputField value="{! Account.Active__c }"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<apex:pageBlock title="Search Related Contacts">
<apex:pageBlockSection ></apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Related Contacts">
<apex:form>
<apex:pageBlockTable value="{!Account.contacts}" var="contact">
<apex:column value="{!contact.Name}"/>
<apex:column value="{!contact.Title}"/>
<apex:column value="{!contact.Phone}"/>
<apex:column value="{!contact.Is_Primary_Contact__c}"/>
<apex:commandLink action="{!save}" value="set"/>
</apex:pageBlockTable>
</apex:form>
</apex:pageBlock>
</apex:page>

Multiple buttons with same action

In my VF page I have 7 sections that represent days in a week. Every section has "Add multiple timesheet item" button. When that button is clicked, new row shows up with fields to fill(Project, Number of working hours..). So, I have 7 buttons with same action, and when I click, for example, on button in 1st section, action executes in every section, and I don't want that. I want executing only in section where button was clicked.
This is my code in VF page:
<apex:page Controller="TimesheetController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Monday" columns="1">
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!listItems}" var="sheet_item">
<apex:column headerValue="Assignment">
<apex:inputField value="{!sheet_item.Assignment__c}"/>
</apex:column>
<apex:column headerValue="Number of Hours">
<apex:inputField value="{!sheet_item.Number_of_Hours__c}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputTextarea value="{!sheet_item.Description__c}" rows="5" cols="30"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
<apex:outputPanel layout="block" html-align="center">
<apex:commandButton value="Add Timesheet Item" action="{!addItem}"/>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Tuesday" columns="1">
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!listItems}" var="sheet_item">
<apex:column headerValue="Assignment">
<apex:inputField value="{!sheet_item.Assignment__c}"/>
</apex:column>
<apex:column headerValue="Number of Hours">
<apex:inputField value="{!sheet_item.Number_of_Hours__c}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputTextarea value="{!sheet_item.Description__c}" rows="5" cols="30"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
<apex:outputPanel layout="block" html-align="center">
<apex:commandButton value="Add Timesheet Item" action="{!addItem}" />
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Wednesday" columns="1">
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!listItems}" var="sheet_item">
<apex:column headerValue="Assignment">
<apex:inputField value="{!sheet_item.Assignment__c}"/>
</apex:column>
<apex:column headerValue="Number of Hours">
<apex:inputField value="{!sheet_item.Number_of_Hours__c}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputTextarea value="{!sheet_item.Description__c}" rows="5" cols="30"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
<apex:outputPanel layout="block" html-align="center">
<apex:commandButton value="Add Timesheet Item" action="{!addItem}"/>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Thursday" columns="1">
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!listItems}" var="sheet_item">
<apex:column headerValue="Assignment">
<apex:inputField value="{!sheet_item.Assignment__c}"/>
</apex:column>
<apex:column headerValue="Number of Hours">
<apex:inputField value="{!sheet_item.Number_of_Hours__c}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputTextarea value="{!sheet_item.Description__c}" rows="5" cols="30"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
<apex:outputPanel layout="block" html-align="center">
<apex:commandButton value="Add Timesheet Item" action="{!addItem}" />
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Friday" columns="1">
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!listItems}" var="sheet_item">
<apex:column headerValue="Assignment">
<apex:inputField value="{!sheet_item.Assignment__c}"/>
</apex:column>
<apex:column headerValue="Number of Hours">
<apex:inputField value="{!sheet_item.Number_of_Hours__c}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputTextarea value="{!sheet_item.Description__c}" rows="5" cols="30"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
<apex:outputPanel layout="block" html-align="center">
<apex:commandButton value="Add Timesheet Item" action="{!addItem}" />
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Saturday" columns="1" >
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!listItems}" var="sheet_item">
<apex:column headerValue="Assignment">
<apex:inputField value="{!sheet_item.Assignment__c}"/>
</apex:column>
<apex:column headerValue="Number of Hours">
<apex:inputField value="{!sheet_item.Number_of_Hours__c}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputTextarea value="{!sheet_item.Description__c}" rows="5" cols="30"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
<apex:outputPanel layout="block" html-align="center">
<apex:commandButton value="Add Timesheet Item" action="{!addItem}" />
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Sunday" columns="1">
<apex:pageBlockSectionItem >
<apex:pageBlockTable value="{!listItems}" var="sheet_item">
<apex:column headerValue="Assignment">
<apex:inputField value="{!sheet_item.Assignment__c}"/>
</apex:column>
<apex:column headerValue="Number of Hours">
<apex:inputField value="{!sheet_item.Number_of_Hours__c}"/>
</apex:column>
<apex:column headerValue="Description">
<apex:inputTextarea value="{!sheet_item.Description__c}" rows="5" cols="30"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
<apex:outputPanel layout="block" html-align="center">
<apex:commandButton value="Add Timesheet Item" action="{!addItem}"/>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Contentment, PTO" columns="1">
<br/>
<apex:inputField label="Mood" value="{!timesheet.Mood__c}"/>
<br/>
<apex:inputTextarea label="Upcoming PTO" value="{!timesheet.Upcoming_PTO__c}" rows="5" cols="30"/>
<br/>
<apex:inputTextarea label="Comment" value="{!timesheet.Comment__c}" rows="5" cols="30"/>
<br/>
<apex:outputPanel layout="block" html-align="center">
<apex:commandButton value="Submit" action="{!saveDetails}" style="float:centre" />
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
And this is my Controller:
public class TimesheetController{
Timesheet_Item__c item = new Timesheet_Item__c();
public list<Timesheet_Item__c> listItems{get; set;}
public Timesheet__c timesheet{get; set;}
public TimesheetController () {
timesheet = new Timesheet__c();
listItems = new list<Timesheet_Item__c>();
listItems.add(item);
}
public void addItem() {
Timesheet_Item__c sheet_item = new Timesheet_Item__c();
listItems.add(sheet_item);
}
public PageReference saveDetails() {
for(Integer i=0; i<listItems.size(); i++) {
insert listItems;
}
insert timesheet;
return null;
}
}
It's not "action executes in every section". You render same variable 7 times. If you enter hours into it as 1,2,3,4,5,6,7 I expect it'll save 7 because that's the last time this is mentioned on the form, this field's value will "win".
You need a list of lists:
List<List<Timesheet_Item__c>> l = new List<List<Timesheet_Item__c>>{
new List<Timesheet_Item__c>(),
new List<Timesheet_Item__c>(),
new List<Timesheet_Item__c>(),
new List<Timesheet_Item__c>(),
new List<Timesheet_Item__c>(),
new List<Timesheet_Item__c>(),
new List<Timesheet_Item__c>()
};
and then in the button action you can pass extra <apex:param> with number from 0 to 6, saying to which one add new item. Just watch out, <apex:commandButton> is bit stupid when passing parameters.
Or maybe a Map<String, List<Timesheet_Item__c>> = new Map<String, List<Timesheet_Item__c>>{ 'Monday' => new List<Timesheet_Item__c>(), ...}; Same principle, pass the map key in the button.

Rerender a pageblock

If I run the page first time, all pageblocks shows the message "choose an user, account or opp" because nothing is choosen. But if I already have selected a user, account or opp the pageblock will show a list/detail of the account or opp.
If I change the user at the top, I want that all panel/pageblocks will resetet, but how can I do that?
I added all pageblocks to the rerender function, but it doesn't work. What is wrong with my code?
<apex:form >
<apex:pageBlock id="pbUser">
<apex:pageBlockSection >
<apex:OutputPanel >
<apex:selectList value="{!SelectedUserId}" size="1" multiselect="false">
<apex:selectOptions value="{!ListOfUser}" />
<apex:actionSupport event="onchange" action="{!fetchAccounts}" <u><b>rerender="pbAcc, pbOpp, pbOppD"</b></u>/>
</apex:selectList>
</apex:OutputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageblock <u><b>id="pbAcc"</b></u>>
<apex:pageBlockSection rendered="{!IF(AccList.size >0,true,false)}" id="pbsAcc">
<apex:outputpanel style="overflow:scroll;height:200px;" layout="block" id="panelAcc">
<apex:pageblocktable value="{!AccList}" var="Acc" onRowClick="highlightAcc(this)">
<apex:column headervalue="Name">
<apex:outputField value="{!Acc.Name}"/>
<apex:actionSupport event="onclick" action="{!fetchOpps}" <u><b>rerender="pbOpp, pbOppD"</b></u>>
<apex:param assignTo="{!SelectedAccountId}" value="{!Acc.Id}" name="SelectedAccountId"/>
</apex:actionSupport>
</apex:column>
<apex:column headervalue="Street">
<apex:outputfield value="{!Acc.BillingStreet}" />
</apex:column>
<apex:column headervalue="City">
<apex:outputfield value="{!Acc.BillingCity}" />
</apex:column>
</apex:pageblocktable>
</apex:outputpanel>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!IF(AccList.size <1,true,false)}">
<apex:outputpanel style="overflow:scroll;height:200px;" layout="block">
Choose a User.
</apex:outputpanel>
</apex:pageBlockSection>
</apex:pageblock>
<apex:pageblock <u><b>id="pbOpp"</b></u>>
<apex:pageBlockSection rendered="{!IF(OppList.size >0,true,false)}" id="pbsOpp">
<apex:outputpanel style="overflow:scroll;height:200px;" layout="block" id="panelOpp">
<apex:pageblocktable value="{!OppList}" var="Opp" onRowClick="highlightOpp(this)">
<apex:column headervalue="Name">
<apex:outputfield value="{!Opp.Name}"/>{!Opp.Id}
<apex:actionSupport event="onclick" action="{!fetchOppDetail}" <u><b>rerender="pbOppD"</b></u>>
<apex:param assignTo="{!SelectedOppId}" value="{!Opp.Id}" name="SelectedOppId"/>
</apex:actionSupport>
</apex:column>
<apex:column headervalue="Amount">
<apex:outputfield value="{!Opp.Amount}"/>
</apex:column>
</apex:pageblocktable>
</apex:outputpanel>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!IF(OppList.size <1,true,false)}">
<apex:outputpanel style="overflow:scroll;height:200px;" layout="block">
Choose an account.
</apex:outputpanel>
</apex:pageBlockSection>
</apex:pageblock>
<apex:pageblock <u><b>id="pbOppD"</b></u> mode="inlineEdit">
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!SaveInlineChanges}" value="Save" id="saveButton"/>
<apex:commandButton action="{!fetchOppDetail}" value="Cancel" id="cancelButton"/>
</apex:pageBlockButtons>
<apex:pageBlockSection rendered="{!IF(OppDetail.size >0,true,false)}" id="pbsOppD">
<apex:outputpanel style="overflow:scroll;height:200px;" layout="block" id="panelOppD">
<apex:pageblocktable value="{!OppDetail}" var="OppD">
<apex:column headervalue="Name">
<apex:outputfield value="{!OppD.Name}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputfield>
</apex:column>
<apex:column headervalue="Amount">
<apex:outputfield value="{!OppD.Amount}" />
</apex:column>
</apex:pageblocktable>
</apex:outputpanel>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!IF(OppDetail.size <1,true,false)}">
<apex:outputpanel style="overflow:scroll;height:200px;" layout="block">
Chosse an opportunity.
</apex:outputpanel>
</apex:pageBlockSection>
</apex:pageblock>
</apex:form>
Thanks,
Sascha
I suspect that the problem is that you have some misplaced html in you actionSupport definition. Change:
<apex:actionSupport event="onchange" action="{!fetchAccounts}" <u><b>rerender="pbAcc, pbOpp, pbOppD"</b></u>/>
To:
<apex:actionSupport event="onchange" action="{!fetchAccounts}" rerender="pbAcc, pbOpp, pbOppD"/>
(This applies to the other actionSupport elements further down the page also)

How to generate xml file as output for a database in specific format through stored procedure in SQL Server?

I want to generate an xml file in the format shown below through a stored procedure.
I am facing few issues to fetch the values in the same format for the foreign key tag which is below. So can anyone help me out on how to create a stored procedure which yields the result in below given format?
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<database name="Northwind" default="True">
<schema name="dbo" default="True">
<table name="Categories">
<field name="CategoryID" primary_key="True" type_name="int" type="Int32" size="4" precision="10" scale="255" nullable="False" readonly="True" />
<field name="CategoryName" type_name="nvarchar" type="String" size="15" precision="255" scale="255" nullable="False" />
<field name="Description" type_name="ntext" type="String" size="1073741823" precision="255" scale="255" />
<field name="Picture" type_name="image" type="Binary" size="2147483647" precision="255" scale="255" />
</table>
<table name="Customers">
<field name="CustomerID" primary_key="True" type_name="nchar" type="String" size="5" precision="255" scale="255" nullable="False" />
<field name="CompanyName" type_name="nvarchar" type="String" size="40" precision="255" scale="255" nullable="False" />
<field name="ContactName" type_name="nvarchar" type="String" size="30" precision="255" scale="255" />
<field name="ContactTitle" type_name="nvarchar" type="String" size="30" precision="255" scale="255" />
<field name="Address" type_name="nvarchar" type="String" size="60" precision="255" scale="255" />
<field name="City" type_name="nvarchar" type="String" size="15" precision="255" scale="255" />
<field name="Region" type_name="nvarchar" type="String" size="15" precision="255" scale="255" />
<field name="PostalCode" type_name="nvarchar" type="String" size="10" precision="255" scale="255" />
<field name="Country" type_name="nvarchar" type="String" size="15" precision="255" scale="255" />
<field name="Phone" type_name="nvarchar" type="String" size="24" precision="255" scale="255" />
<field name="Fax" type_name="nvarchar" type="String" size="24" precision="255" scale="255" />
</table>
<table name="Shippers">
<field name="ShipperID" primary_key="True" type_name="int" type="Int32" size="4" precision="10" scale="255" nullable="False" readonly="True" />
<field name="CompanyName" type_name="nvarchar" type="String" size="40" precision="255" scale="255" nullable="False" />
<field name="Phone" type_name="nvarchar" type="String" size="24" precision="255" scale="255" />
</table>
<table name="Suppliers">
<field name="SupplierID" primary_key="True" type_name="int" type="Int32" size="4" precision="10" scale="255" nullable="False" readonly="True" />
<field name="CompanyName" type_name="nvarchar" type="String" size="40" precision="255" scale="255" nullable="False" />
<field name="ContactName" type_name="nvarchar" type="String" size="30" precision="255" scale="255" />
<field name="ContactTitle" type_name="nvarchar" type="String" size="30" precision="255" scale="255" />
<field name="Address" type_name="nvarchar" type="String" size="60" precision="255" scale="255" />
<field name="City" type_name="nvarchar" type="String" size="15" precision="255" scale="255" />
<field name="Region" type_name="nvarchar" type="String" size="15" precision="255" scale="255" />
<field name="PostalCode" type_name="nvarchar" type="String" size="10" precision="255" scale="255" />
<field name="Country" type_name="nvarchar" type="String" size="15" precision="255" scale="255" />
<field name="Phone" type_name="nvarchar" type="String" size="24" precision="255" scale="255" />
<field name="Fax" type_name="nvarchar" type="String" size="24" precision="255" scale="255" />
<field name="HomePage" type_name="ntext" type="String" size="1073741823" precision="255" scale="255" />
</table>
<table name="Orders">
<field name="OrderID" primary_key="True" type_name="int" type="Int32" size="4" precision="10" scale="255" nullable="False" readonly="True" />
<field name="CustomerID" type_name="nchar" type="String" size="5" precision="255" scale="255" />
<field name="EmployeeID" type_name="int" type="Int32" size="4" precision="10" scale="255" />
<field name="OrderDate" type_name="datetime" type="DateTime" size="8" precision="23" scale="3" />
<field name="RequiredDate" type_name="datetime" type="DateTime" size="8" precision="23" scale="3" />
<field name="ShippedDate" type_name="datetime" type="DateTime" size="8" precision="23" scale="3" />
<field name="ShipVia" type_name="int" type="Int32" size="4" precision="10" scale="255" />
<field name="Freight" type_name="money" type="Decimal" size="8" precision="19" scale="255" />
<field name="ShipName" type_name="nvarchar" type="String" size="40" precision="255" scale="255" />
<field name="ShipAddress" type_name="nvarchar" type="String" size="60" precision="255" scale="255" />
<field name="ShipCity" type_name="nvarchar" type="String" size="15" precision="255" scale="255" />
<field name="ShipRegion" type_name="nvarchar" type="String" size="15" precision="255" scale="255" />
<field name="ShipPostalCode" type_name="nvarchar" type="String" size="10" precision="255" scale="255" />
<field name="ShipCountry" type_name="nvarchar" type="String" size="15" precision="255" scale="255" />
<foreignkey>
<referenced_object>
<name>Customers</name>
<name>dbo</name>
<name>Northwind</name>
</referenced_object>
<referencing_field name="CustomerID" referenced_field="CustomerID" />
<referencing_cardinality>Many</referencing_cardinality>
<referenced_cardinality>One</referenced_cardinality>
</foreignkey>
<foreignkey>
<referenced_object>
<name>Shippers</name>
<name>dbo</name>
<name>Northwind</name>
</referenced_object>
<referencing_field name="ShipVia" referenced_field="ShipperID" />
<referencing_cardinality>Many</referencing_cardinality>
<referenced_cardinality>One</referenced_cardinality>
</foreignkey>
<foreignkey>
<referenced_object>
<name>Employees</name>
<name>dbo</name>
<name>Northwind</name>
</referenced_object>
<referencing_field name="EmployeeID" referenced_field="EmployeeID" />
<referencing_cardinality>Many</referencing_cardinality>
<referenced_cardinality>One</referenced_cardinality>
</foreignkey>
</table>
<table name="Products">
<field name="ProductID" primary_key="True" type_name="int" type="Int32" size="4" precision="10" scale="255" nullable="False" readonly="True" />
<field name="ProductName" type_name="nvarchar" type="String" size="40" precision="255" scale="255" nullable="False" />
<field name="SupplierID" type_name="int" type="Int32" size="4" precision="10" scale="255" />
<field name="CategoryID" type_name="int" type="Int32" size="4" precision="10" scale="255" />
<field name="QuantityPerUnit" type_name="nvarchar" type="String" size="20" precision="255" scale="255" />
<field name="UnitPrice" type_name="money" type="Decimal" size="8" precision="19" scale="255" />
<field name="UnitsInStock" type_name="smallint" type="Int16" size="2" precision="5" scale="255" />
<field name="UnitsOnOrder" type_name="smallint" type="Int16" size="2" precision="5" scale="255" />
<field name="ReorderLevel" type_name="smallint" type="Int16" size="2" precision="5" scale="255" />
<field name="Discontinued" type_name="bit" type="Boolean" size="1" precision="255" scale="255" nullable="False" />
<foreignkey>
<referenced_object>
<name>Categories</name>
<name>dbo</name>
<name>Northwind</name>
</referenced_object>
<referencing_field name="CategoryID" referenced_field="CategoryID" />
<referencing_cardinality>Many</referencing_cardinality>
<referenced_cardinality>One</referenced_cardinality>
</foreignkey>
<foreignkey>
<referenced_object>
<name>Suppliers</name>
<name>dbo</name>
<name>Northwind</name>
</referenced_object>
<referencing_field name="SupplierID" referenced_field="SupplierID" />
<referencing_cardinality>Many</referencing_cardinality>
<referenced_cardinality>One</referenced_cardinality>
</foreignkey>
</table>
</schema>
</database>
</metadata>
Declare #temp Table(result xml)
DECLARE #value varchar(50)
insert into #temp values((
Select DB_NAME() AS '#name',
(SELECT sc.SCHEMA_NAME as '#name' ,
(SELECT TABLE_NAME as '#name',
(
SELECT COLUMN_NAME as '#name',
t.name as '#type_name',
case DATA_TYPE
when 'nvarchar'
then 'String'
when 'varchar'
then 'String'
when 'int'
then 'Int32'
when 'bigint'
then 'Int64'
when 'bit'
then 'Boolean'
when 'datetime'
then 'DateTime'
else null
end as '#type',
NUMERIC_PRECISION as '#precision',
NUMERIC_SCALE as '#scale',
case data_type
when 'nvarchar'
then CHARACTER_MAXIMUM_LENGTH
when 'varchar'
then CHARACTER_MAXIMUM_LENGTH
else null
end as '#size',
INFORMATION_SCHEMA.COLUMNS.IS_NULLABLE AS '#nullable',
'true' as '#readonly',
'true'as '#primary_key'
FROM INFORMATION_SCHEMA.COLUMNS
INNER JOIN
sys.types t ON TYPE_ID(INFORMATION_SCHEMA.COLUMNS.DATA_TYPE) = t.user_type_id
LEFT OUTER JOIN
sys.index_columns ic ON t.name=INFORMATION_SCHEMA.COLUMNS.COLUMN_NAME
--ON ic.column_id = INFORMATION_SCHEMA.COLUMNS.COLUMN_NAME
LEFT OUTER JOIN
sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
where INFORMATION_SCHEMA.COLUMNS.TABLE_NAME =
INFORMATION_SCHEMA.TABLES.TABLE_NAME
order by INFORMATION_SCHEMA.COLUMNS.ORDINAL_POSITION
For XML PATH ('field'), type
)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='my schema'
ORDER BY TABLE_NAME ASC
For XML PATH ('table'),type)
from INFORMATION_SCHEMA.SCHEMATA sc where sc.SCHEMA_NAME IN(Select distinct TOP 1 ta.TABLE_SCHEMA from
INFORMATION_SCHEMA.TABLES ta )
For XML PATH('schema'),type)
For XML PATH('database'),Root('metadata')))
select * from #temp
The above code is used to generate just table data
The below stored procedure is used to generate the foreign key constraint
(select INFORMATION_SCHEMA.TABLE_CONSTRAINTS.TABLE_NAME as 'name',
INFORMATION_SCHEMA.TABLE_CONSTRAINTS.TABLE_SCHEMA as 'name',
INFORMATION_SCHEMA.TABLE_CONSTRAINTS.TABLE_CATALOG as 'name' ,
referencing_field_name =FK_COLS.COLUMN_NAME,
referenced_field = PK_COLS.COLUMN_NAME,
referencing_cardinality='Many',
referenced_cardinality='one'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS REF_CONST
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS
ON REF_CONST.CONSTRAINT_CATALOG = INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_CATALOG
AND REF_CONST.CONSTRAINT_SCHEMA = INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_SCHEMA
AND REF_CONST.CONSTRAINT_NAME = INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_NAME
AND INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_TYPE = 'FOREIGN KEY'
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK
ON REF_CONST.UNIQUE_CONSTRAINT_CATALOG = PK.CONSTRAINT_CATALOG
AND REF_CONST.UNIQUE_CONSTRAINT_SCHEMA = PK.CONSTRAINT_SCHEMA
AND REF_CONST.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
AND PK.CONSTRAINT_TYPE = 'PRIMARY KEY'
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE FK_COLS ON REF_CONST.CONSTRAINT_NAME = FK_COLS.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE PK_COLS ON PK.CONSTRAINT_NAME = PK_COLS.CONSTRAINT_NAME
FOR XML RAW ('referenced_object'), ELEMENTS, ROOT ('foreign key'))
We are facing an issue in integrating these two stored procedures
So, Is there any way to generate the xml file in the same format dynamically

Error Message when popup window is loaded

I have created 2 popup on 2 button. And have a object (AC). On both popup I have some fields to insert.
In 1st popup it contain A.name1, A.name2, A.date, A.Edate, A.Pjt etc and in 2nd popup I have fields A.Name1, A.name2. The A.Name1 and A.name2 are required field in object.
My problem is that when I try to insert the value in the 1st popup I am getting error meg that "YOU MUST ENTER A VALUE" but even then i enter the value. So I commented the 2nd popup then it is working fine but when 2nd popup is uncommented the this error is thrown event the value is entered. The 2nd popup contains the same 2 fields in the first with some other fields.
can anybody help me to find the solution for this error.
<apex:outputPanel id="tstpopup">
<apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
<apex:pageblock >
<apex:pageblocksection >
<apex:pageblocksectionitem >
<apex:outputlabel value="name1: " />
<apex:inputfield id="proj" value="{!AC.name1__c}" />
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputlabel value="name2: " />
<apex:inputfield id="role" value="{!AC.name2__c}" />
</apex:pageblocksectionitem>
<p/>
<apex:commandbutton value="Pencil in a New Project" action="{!save}" />
<apex:commandbutton value="Cancel" action="{!closePopup}" immediate="true" /><br/><br/><br/>
</apex:pageblocksection>
</apex:pageblock>
</apex:outputPanel>
</apex:outputPanel>
<apex:outputPanel id="tstpopup1">
<apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
<apex:pageblock >
<apex:pageblocksection >
<apex:pageblocksectionitem >
<apex:outputlabel value="name1: " />
<apex:inputfield id="proj1" value="{!AC.name1__c}" />
</apex:pageblocksectionitem><p/>
<apex:pageblocksectionitem >
<apex:outputlabel value="Date: " />
<apex:inputfield id="sd" value="{!AC.Date__c}" />
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputlabel value="EDate: " />
<apex:inputfield id="ed" value="{!AC.EDate__c}" />
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputlabel value="Proj: " />
<apex:inputfield id="pl" value="{!AC.Pjt__c}" />
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputlabel value="Charge: " />
<apex:inputfield id="charge" value="{!AC.Charge__c}" />
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputlabel value="Name2: " />
<apex:inputfield id="role1" value="{!AC.name2__c}" />
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputlabel value="time: " />
<apex:inputfield id="overtime" value="{!AC.time__c}" />
</apex:pageblocksectionitem>
</apex:pageblocksection>
<apex:commandbutton value="Assign to a New Project" action="{!assign}" />
<apex:commandbutton value="Cancel" action="{!closePopup}" immediate="true" /><br/><br/><br/>
</apex:pageblock>
</apex:outputPanel>
</apex:outputPanel>
I think this is because you have the same object in two popups. If you enters a value eg. name1_c in your first popup - the other field name1_c in your second popup is still empty.
Try to create two diferent instances of your object:
Apex class:
public YourObject AC1 { get; set; }
public YourObject AC2 { get; set; }
// Constructor
public YourClassName(){
AC1 = new YourObject();
AC2 = new YourObject();
}
First popup:
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp1}">
<apex:pageblock >
<apex:pageBlockButtons>
<apex:commandbutton value="Assign to a New Project" action="{!assign1}" />
<apex:commandbutton value="Cancel" action="{!closePopup1}" immediate="true" />
</apex:pageBlockButtons>
<apex:pageblocksection >
<apex:pageblocksectionitem >
<apex:outputlabel value="name1: " />
<apex:inputfield id="proj1" value="{!AC1.name1__c}" />
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputlabel value="Name2: " />
<apex:inputfield id="role1" value="{!AC1.name2__c}" />
</apex:pageblocksectionitem>
<!-- other fields from the instance 1 of the object -->
....
</apex:pageblocksection>
<apex:pageblock >
<apex:outputPanel>
Second popup:
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp2}">
<apex:pageblock >
<apex:pageBlockButtons>
<apex:commandbutton value="Assign to a Another Project" action="{!assign2}" />
<apex:commandbutton value="Cancel" action="{!closePopup2}" immediate="true" />
</apex:pageBlockButtons>
<apex:pageblocksection >
<apex:pageblocksectionitem >
<apex:outputlabel value="name1: " />
<apex:inputfield id="proj2" value="{!AC2.name1__c}" />
</apex:pageblocksectionitem>
<apex:pageblocksectionitem >
<apex:outputlabel value="Name2: " />
<apex:inputfield id="role2" value="{!AC2.name2__c}" />
</apex:pageblocksectionitem>
<!-- other fields from the instance 2 of the object -->
....
</apex:pageblocksection>
<apex:pageblock >
<apex:outputPanel>

Resources