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
amar joshiamar joshi 

pagereference link is broken up

hi community

i m developing one page and stuck with some errors

in my page there are two buttons 'convert' & 'cancel'

for  cancel button  i have write the code 
Code:
<apex:commandButton action="{!cancle}" value="cancel" immediate="true" alt="cancel"/>

 here i have put immediate = "true " so its not check the standard salesforce validation

now  for 'convert' button i want to put 'immediate' value depending upon the value selected in select list component

for that i have create a Boolean getter method which put the  the true and false

now problem is that the variable i m using is used with select options getter method and with that variable i do the page reference

so i cant reference my page

bellow is the code

Code:
page code
<apex:page controller="convert1" tabstyle="lead">
   <apex:sectionHeader title="Convert Lead"subtitle="{!lead.owner.name}"/>
           Leads can be converted to accounts, contacts, opportunities, and followup tasks.
          <br>You should only convert a lead once you have identified it as qualified.</br>
           <br>After this lead has been converted, it can no longer be viewed or edited as a lead, but can be viewed in lead reports.</br>
            <br> </br>
        <apex:form >
          <apex:pageBlock mode="edit">
             <apex:pageblockButtons >
               <apex:commandButton id="Button1" action="{!convertLead}" immediate="{!Isvalid}" value="convert" />
               <apex:commandButton action="{!cancle}" value="cancel" immediate="true" alt="cancel"/>
             </apex:pageblockButtons>
             <apex:pageBlockSection title="Convert Lead">
                    <apex:inputfield value="{!lead.Record_Owner__c}"/>
                    <apex:pageblockSectionItem ></apex:pageblockSectionItem>
                       <apex:pageBlockSectionItem >
                         Converted Status
                         <apex:selectlist value="{!string}" size="1" required="True">
                         <apex:selectoption itemvalue="Qualified" itemlabel="qualified"/>
                         </apex:selectlist>
                       </apex:pageBlockSectionItem>
                       <apex:pageblockSectionItem ></apex:pageblockSectionItem>
                       <apex:pageBlockSectionItem >
                        Account name
                          <apex:selectlist value="{!countries}" title="Choose a country" size="1" required="true">
                          <apex:selectOptions value="{!items}" />
                        </apex:selectlist>
                       </apex:pageblocksectionitem>
                       
                         <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
    
    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                <apex:outputPanel >
                    <p>You have selected:</p>
                    <apex:variable var="c" value="{!countries}">
                    <p>You have selected12333:</p>
                   <apex:outputtext value="{!c}"/>
                    </apex:variable>
                    
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
                       
                       </apex:pageblocksection>
                       <apex:pageblocksection title="Task Information">
                            <apex:inputfield value="{!task.subject}"/>
                            <apex:inputfield value="{!task.Branch_Name__c}" required="True"/>
                            <apex:inputfield value="{!task.ActivityDate}"/>
                            <br><apex:inputfield value="{!task.Description}"/></br>
                      </apex:pageblocksection>
                      <apex:pageBlockSection title="Other Information">
                           <apex:inputfield value="{!task.Priority}"/>
                           <br><apex:inputfield value="{!task.Status}"/></br>
                      </apex:pageBlockSection>
                      <apex:pageblockSection title="Reminder">
                            <apex:inputfield value="{!task.ReminderDateTime}"/>
                       </apex:pageblockSection>
          </apex:pageBlock>
        </apex:form>
</apex:page>

 controller

Code:
global class convert1{ 
String co='';
public PageReference cancle()
{
String m2 = '/'+ApexPages.currentPage().getParameters().get('id');
PageReference pageref = new Pagereference(m2);
return pageref;
}
public PageReference convertLead() {

if(co.equals('02')) // what happen here it create a new account as select option
compontant is create a new account
 {
Account a = new Account(name=l.company,
Group_Company__c=l.Group_Company__c,
Billing_Street__c=l.Street__c,
Billing_City__c=l.City__c,
Billing_State_Province__c=l.State__c,
Billing_Country__c=l.Country__c,
Billing_Zip_Postal_Code__c=l.Zip_Postal_code__c);
insert a;
Contact c = new Contact(LastName=l.LastName,
FirstName=l.FirstName,accountId = a.Id);

insert c;
}
else if(co.equals('01')) // here as option is attach to exsisting so it navigate to
convert contact page but here error occur coz it cant
catch the co value coz it is used in Isvalid() method
and we have put string co = ''; if i dont put it give
 me null pointer exception for Isvalid() method
{
String m2 = '/'+ApexPages.currentPage().getParameters().get('id');
PageReference pageref = new Pagereference(m2);
return pageref;
//ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Validation Failed: Comments are required.'));
}
else
{
pagereference pageref = page.convertcontact;
pageref.setRedirect(true);
pageref.getparameters().put('cid',co);
pageref.getparameters().put('id',l.id);

//Account ab = [select id from account where id = :ac[i].id];
//update ab;
return pageref;
}

//insert task;
return null;
}


public PageReference test() {
return null;
}



//-------------------------------------------------------------------------------------------
//--This logic get the Qualified status from the database--//
String s ='Qualified';
public String getstring()
{
return s;
}
public void setstring(String s)
{
this.s = s;
}

//this part is for getting the account list from database


Integer i;
lead l;
list<Account> ac = new account[]{};
List<SelectOption> options = new List<SelectOption>();
String s1 = '--none--';


public List<SelectOption> getItems()
{

l = [select id,FirstName,LastName,company,Group_Company__c,Street__c,City__c,State__c,Country__c,Zip_Postal_code__c from lead where id = :ApexPages.currentPage().getParameters().get('id')];
ac = [select id,name from account where name = :l.company];
String s2 = 'Create a new Account : '+l.company;

if(ac.size()>0)
{
options.add(new selectOption('01',s1));
options.add(new SelectOption('02',s2));
for(i=0;i<ac.size();i++)
{
String s3='Attach to existing :'+ac[i].name;
options.add(new SelectOption(ac[i].id,s3));
}
}
else
{
options.add(new selectOption('03',s1));
options.add(new SelectOption('02',s2));
}
return options;
}


public String getCountries()
{
return co;
}

public void setCountries(String c)
{
this.co = c;
}
public boolean getIsvalid() // this is Isvalid() method and want to put true
false depending co value
{ if(co.equals('01')) { return true; } else if(co.equals('02')) { return false; } else return true; } //--The convert button logic--// //-This logic is for getting the task information from database - // Task task; public Task gettask() { if (task == null) task = new Task(); return task; } //--This is logic geting the lead information as well as record owner from the database--// public Lead getLead() { Lead a; a= [select owner.id,owner.type,owner.name,Record_Owner__c,company,Group_Company__c from Lead where id = :ApexPages.currentPage().getParameters().get('id')]; a.Record_Owner__c=a.owner.id; return a; } }

 

  in short i want to do is:
                        if my select option compaont value is none  then want to put Isvalid() = true
                        and my select option compontat value is attach to exsisting means then want to put Isvalid() = true and             redirect page to convetcontact  page

thanks & regards
Amar joshi


Message Edited by amar joshi on 10-13-2008 01:54 PM