• up_sky
  • NEWBIE
  • 15 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 2
    Replies

Hi All,

 

   

I created a VF page with required input fields and a validation rule along with a command buttons ( "Update" buttons). While submitting the information if I does not input on one of the required fields, It displays the validation rule error message and at the same time all fields are get cleared.

 

But, I like to keep all data on the fields, but display error message.


How to resolve this "Fields get cleared" problem... Please suggest me

 

Thanks,

 

 

 

<apex:page Controller="MyAccount">
    <apex:form >    
    <apex:outputPanel id="AuthorizedContacts">    
    <apex:message/>
    <h2>{!primaryContact.Name}</h2><br/>
    <apex:commandbutton action="{!addAuthContact}" value="Add Contact" rerender="AuthorizedContacts" rendered="{!addAuthContact == false}"/>
    
        <apex:repeat value="{!newAuth}" var="a">
        <apex:outputpanel rendered="{!addAuthContact}">
            {!a.Contact_Type__c}<br/>
            <h4>Name &amp; Contact</h4><br/>
              
                FIRST NAME* <apex:inputField value="{!a.FirstName}" id="contact-first-name" required="true"/>
                LAST NAME* <apex:inputField value="{!a.LastName}"  id="contact-last-name" required="true"/>
                PHONE* <apex:inputField value="{!a.Phone}"  id="contact-phone" required="true"/>
                EMAIL ADDRESS* <apex:inputField value="{!a.Email}"  id="contact-email" required="true"/> 
                
            <h4>Contact Address</h4><br/>
            
                ADDRESS 1 <br/><apex:inputText value="{!a.Contact_Address_Line_1__c}"  id="contact-addr-1"/><br/>
                ADDRESS 2 <br/><apex:inputText value="{!a.Contact_Address_Line_2__c}"  id="contact-addr-2"/><br/>
                CITY <br/><apex:inputText value="{!a.Contact_Town_City__c}"  id="contact-city"/><br/>
                POST CODE <br/><apex:inputText value="{!a.Contact_Postal_Code__c}"  id="contact-postal"/><br/>
                COUNTY <br/><apex:inputText value="{!a.Contact_County__c}"  id="County"/><br/>
                
                COUNTRY<br/>
                <apex:SelectList value="{!CountryName}" size="1">
                    <apex:selectOptions value="{!lstCountry}"></apex:selectOptions>
                </apex:SelectList><br/>
            
            <h4>Is This Authorized Contact Part of Your:</h4><br/>
                <apex:Inputcheckbox value="{!a.IsHousehold__c}"/>
                <label>Household</label>
                <apex:Inputcheckbox value="{!a.IsBusiness__c}"/>
                <label >Business</label><br/>
                <apex:messages rendered="{!IsValidate}" styleClass="errorMsg"/><br/>
            <apex:commandbutton styleClass="cancel" action="{!cancelAuth}" value="Cancel" immediate="true" rerender="AuthorizedContacts"/>
            <apex:commandButton styleClass="button-medium" action="{!saveAuth}" value="Save Updates" rerender="AuthorizedContacts"/>
        
          </apex:outputPanel>      
        </apex:repeat>
        </apex:outputPanel>
    </apex:form>
</apex:page>

 

 

public class MyAccount {
    
    private Id uid;
    public Id aid{get;set;}
    public Id cid{get;set;}
	
	public string CountryName {get;set;}
	
    public Boolean IsValidate{get;set;}
    public Boolean addAuthContact{get;set;}
    
    public User objUser{get;set;} 
    public Contact primaryContact;
	
    public list<Contact> newAuth;
	
    public MyAccount(){
	
        uid = UserInfo.getUserId();
        getObjUser();    
    }
    
    public List<SelectOption> getlstCountry()
    {  list<SelectOption> options = new list<SelectOption>(); 
        try{
            list<Country__c> ls = [select Name,LZ_Country_Id__c,Id from Country__c];
            
			 	Country__c uk = [select Name,LZ_Country_Id__c,Id from Country__c Where Name = 'United Kingdom'];
            
			 	options.add(new SelectOption(uk.Id,uk.Name));
				
            for(Country__c o:ls){
                if(o.Name != 'United Kingdom')
                options.add(new SelectOption(o.Id,o.Name));
            }
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        }  
        return options;
    }
	
    public void getObjUser(){
        try {
            uid = Apexpages.currentPage().getParameters().get('id');
            if(uid != null){
            objUser = [Select   User.ContactId,
                                User.AccountId,
                                User.UserType
                        From    User
                        Where   User.Id = :uid ];
            cid = objUser.ContactId;
            aid = objUser.AccountId;    
            }
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        } 
    }
    
    public Contact getprimaryContact(){
        try
        {
            if(cid != null){
                primaryContact = [Select    Contact.Id,
                                            Contact.Name,
                                    From    Contact
                                    Where   Contact.Id =:cid];
            }
        }catch(Exception ex){
            System.debug('Error From ' + ex.getMessage());
        } 
        return primaryContact;
    }    
  
    public list<Contact> getnewAuth(){
        try
            {   
                newAuth = new list<Contact>();
                Contact ac = new Contact();
                if(aid != null) {
                    ac.AccountId = aid;
                    ac.Contact_Type__c = 'Authorized Contact';
                } 
                newAuth.add(ac);    
        }
        catch(Exception ex)
        {
                System.debug('Error From' + ex.getMessage());
        }   
         return newAuth;
    }
    
    public PageReference addAuthContact(){
        try{
            getnewAuth();
            addAuthContact = true;
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        }
        return null;
    }   
     
    public PageReference cancelAuth(){
        try{
            newAuth = null;
            addAuthContact = false;
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        }
        return null;
    }
    
    public PageReference saveAuth() {  
        
         try{
        List<Contact> tempCon = new List<Contact>();
        if(newAuth != null)  {      
            for(Contact t : newAuth)
            {
                t.Contact_Country__c = CountryName ;                
                tempCon.add(t);
            }
        }
        insert tempCon;
        addAuthContact = false;
        }catch(DmlException ex){
        	if(newAuth[0].IsBusiness__c == false && newAuth[0].IsHousehold__c == false){
        		IsValidate = true;
        	}        	
            ApexPages.addMessages(ex);
        }
        return null;
    }
}

 

 

 

  • August 19, 2013
  • Like
  • 0

Hi All,

 

   

I created a VF page with required input fields and a validation rule along with a command buttons ( "Update" buttons). While submitting the information if I does not input on one of the required fields, It displays the validation rule error message and at the same time all fields are get cleared.

 

But, I like to keep all data on the fields, but display error message.


How to resolve this "Fields get cleared" problem... Please suggest me

 

Thanks,

 

 

 

<apex:page Controller="MyAccount">
    <apex:form >    
    <apex:outputPanel id="AuthorizedContacts">    
    <apex:message/>
    <h2>{!primaryContact.Name}</h2><br/>
    <apex:commandbutton action="{!addAuthContact}" value="Add Contact" rerender="AuthorizedContacts" rendered="{!addAuthContact == false}"/>
    
        <apex:repeat value="{!newAuth}" var="a">
        <apex:outputpanel rendered="{!addAuthContact}">
            {!a.Contact_Type__c}<br/>
            <h4>Name &amp; Contact</h4><br/>
              
                FIRST NAME* <apex:inputField value="{!a.FirstName}" id="contact-first-name" required="true"/>
                LAST NAME* <apex:inputField value="{!a.LastName}"  id="contact-last-name" required="true"/>
                PHONE* <apex:inputField value="{!a.Phone}"  id="contact-phone" required="true"/>
                EMAIL ADDRESS* <apex:inputField value="{!a.Email}"  id="contact-email" required="true"/> 
                
            <h4>Contact Address</h4><br/>
            
                ADDRESS 1 <br/><apex:inputText value="{!a.Contact_Address_Line_1__c}"  id="contact-addr-1"/><br/>
                ADDRESS 2 <br/><apex:inputText value="{!a.Contact_Address_Line_2__c}"  id="contact-addr-2"/><br/>
                CITY <br/><apex:inputText value="{!a.Contact_Town_City__c}"  id="contact-city"/><br/>
                POST CODE <br/><apex:inputText value="{!a.Contact_Postal_Code__c}"  id="contact-postal"/><br/>
                COUNTY <br/><apex:inputText value="{!a.Contact_County__c}"  id="County"/><br/>
                
                COUNTRY<br/>
                <apex:SelectList value="{!CountryName}" size="1">
                    <apex:selectOptions value="{!lstCountry}"></apex:selectOptions>
                </apex:SelectList><br/>
            
            <h4>Is This Authorized Contact Part of Your:</h4><br/>
                <apex:Inputcheckbox value="{!a.IsHousehold__c}"/>
                <label>Household</label>
                <apex:Inputcheckbox value="{!a.IsBusiness__c}"/>
                <label >Business</label><br/>
                <apex:messages rendered="{!IsValidate}" styleClass="errorMsg"/><br/>
            <apex:commandbutton styleClass="cancel" action="{!cancelAuth}" value="Cancel" immediate="true" rerender="AuthorizedContacts"/>
            <apex:commandButton styleClass="button-medium" action="{!saveAuth}" value="Save Updates" rerender="AuthorizedContacts"/>
        
          </apex:outputPanel>      
        </apex:repeat>
        </apex:outputPanel>
    </apex:form>
</apex:page>

 

 

public class MyAccount {
    
    private Id uid;
    public Id aid{get;set;}
    public Id cid{get;set;}
	
	public string CountryName {get;set;}
	
    public Boolean IsValidate{get;set;}
    public Boolean addAuthContact{get;set;}
    
    public User objUser{get;set;} 
    public Contact primaryContact;
	
    public list<Contact> newAuth;
	
    public MyAccount(){
	
        uid = UserInfo.getUserId();
        getObjUser();    
    }
    
    public List<SelectOption> getlstCountry()
    {  list<SelectOption> options = new list<SelectOption>(); 
        try{
            list<Country__c> ls = [select Name,LZ_Country_Id__c,Id from Country__c];
            
			 	Country__c uk = [select Name,LZ_Country_Id__c,Id from Country__c Where Name = 'United Kingdom'];
            
			 	options.add(new SelectOption(uk.Id,uk.Name));
				
            for(Country__c o:ls){
                if(o.Name != 'United Kingdom')
                options.add(new SelectOption(o.Id,o.Name));
            }
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        }  
        return options;
    }
	
    public void getObjUser(){
        try {
            uid = Apexpages.currentPage().getParameters().get('id');
            if(uid != null){
            objUser = [Select   User.ContactId,
                                User.AccountId,
                                User.UserType
                        From    User
                        Where   User.Id = :uid ];
            cid = objUser.ContactId;
            aid = objUser.AccountId;    
            }
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        } 
    }
    
    public Contact getprimaryContact(){
        try
        {
            if(cid != null){
                primaryContact = [Select    Contact.Id,
                                            Contact.Name,
                                    From    Contact
                                    Where   Contact.Id =:cid];
            }
        }catch(Exception ex){
            System.debug('Error From ' + ex.getMessage());
        } 
        return primaryContact;
    }    
  
    public list<Contact> getnewAuth(){
        try
            {   
                newAuth = new list<Contact>();
                Contact ac = new Contact();
                if(aid != null) {
                    ac.AccountId = aid;
                    ac.Contact_Type__c = 'Authorized Contact';
                } 
                newAuth.add(ac);    
        }
        catch(Exception ex)
        {
                System.debug('Error From' + ex.getMessage());
        }   
         return newAuth;
    }
    
    public PageReference addAuthContact(){
        try{
            getnewAuth();
            addAuthContact = true;
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        }
        return null;
    }   
     
    public PageReference cancelAuth(){
        try{
            newAuth = null;
            addAuthContact = false;
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        }
        return null;
    }
    
    public PageReference saveAuth() {  
        
         try{
        List<Contact> tempCon = new List<Contact>();
        if(newAuth != null)  {      
            for(Contact t : newAuth)
            {
                t.Contact_Country__c = CountryName ;                
                tempCon.add(t);
            }
        }
        insert tempCon;
        addAuthContact = false;
        }catch(DmlException ex){
        	if(newAuth[0].IsBusiness__c == false && newAuth[0].IsHousehold__c == false){
        		IsValidate = true;
        	}        	
            ApexPages.addMessages(ex);
        }
        return null;
    }
}

 

 

 

 

 

 

  • August 14, 2013
  • Like
  • 0

I am writing some unit tests for one of my apex classmethods that is defined as follows:

 

I got error System.NullPointerException: Attempt to de-refference a null object. My Code Coverage is 30%

 

public with sharing class CMIARequest {
	private Map<String, String> cmds;
		
	private CMIARequest(MAP<String, String> cmds) {
		this.cmds = cmds;		
	}
	
	public static CMIARequest construct(MAP<String, String> cmds) {
		string cmd = ApexPages.currentPage().getParameters().get('command');
		if (cmd == null)
			throw new CMIAException('No command specific');
		return new CMIARequest(cmds);
	}
	
	public boolean validate() {		 
		String sid = cmds.get('sid');
		if (sid == null)
			throw new CMIAException('no session ID specific');
		return CMIASessionManager.validateSession(sid);
	}
	
	public String getSessionID() {
		return cmds.get('sid');
	}
	
	public String getCommand() {
		return cmds.get('command');
	}	
	
	public String getParam(String key) {
		return cmds.get(key);
	}
	
	public String getRequestString() {
		Set<String> keys = cmds.keySet();
		CMIAJsonEntryMap m = new CMIAJsonEntryMap();
		for (String k : keys) {
			m.addEntry(k, cmds.get(k));
		}
		return m.render();
	}
	
	static testmethod void unitTest() {
		
		String key = 'MyKey';
		String command = 'getSfUserInfo';
		Map<String, String> cmds;
		
		string cmd = ApexPages.currentPage().getParameters().put('command',command);
		CMIARequest.construct(cmds);
	
        CMIARequest cmr = new CMIARequest(cmds);
        Boolean validate = cmr.validate();
        cmr.getSessionID();
        cmr.getCommand();
        cmr.getParam(key);
        cmr.getRequestString();
        
		}
}

 

  • March 23, 2012
  • Like
  • 0

Hello

 

I am new to Apex and just starting to learn it, so I would appreciate any help here.

 

I was informed the class needs to pass 75% before I can depoly it to my production org

 

Can anyone help me write a Test Class for this?

 

public class CMIAExecResult {
	public static CMIAJsonEntryMap createErrorResult(String msg) {
		CMIAJsonEntryMap r = new CMIAJsonEntryMap();
		r.addEntry(new CMIAJsonEntryPair('result', CMIAJsonEntryBool.R_FALSE));
		r.addEntry(new CMIAJsonEntryPair('msg', new CMIAJsonEntryString(msg)));
		return r;
	}

	public static CMIAJsonEntryMap createSuccessResult() {
		CMIAJsonEntryMap r = new CMIAJsonEntryMap();
		r.addEntry(new CMIAJsonEntryPair('result', CMIAJsonEntryBool.R_TRUE));
		return r;
	}
	
}

 For reference class

public class CMIAJsonEntryMap implements CMIAJsonEntry {
	private LIST<CMIAJsonEntryPair> pairs;

	public CMIAJsonEntryMap() {
		pairs = new LIST<CMIAJsonEntryPair>();
	}
	
	public void addEntry(CMIAJsonEntryPair p) {
		pairs.add(p);
	}
	
	public void addEntry(String key, CMIAJsonEntry value) {
		pairs.add(new CMIAJsonEntryPair(key, value));
	}
	
	public void addEntry(String key, boolean value) {
		pairs.add(new CMIAJsonEntryPair(key, value ? CMIAJsonEntryBool.R_TRUE : CMIAJsonEntryBool.R_FALSE));
	}

	public void addEntry(String key, double value) {
		pairs.add(new CMIAJsonEntryPair(key, new CMIAJsonEntryDouble(value)));
	}
	
	public void addEntry(String key, integer value) {
		pairs.add(new CMIAJsonEntryPair(key, new CMIAJsonEntryInt(value)));		
	}
	
	public void addEntry(String key, String value) {
		pairs.add(new CMIAJsonEntryPair(key, new CMIAJsonEntryString(value)));		
	}
	
	public String render() {
		String r = '{';
		integer last = pairs.size() - 1;
		for (integer i = 0; i < pairs.size(); i++) {
			r = r + pairs.get(i).render();
			if (i != last)
				r = r + ', ';
		}
		return r + ' }' + '\n';
	}
		 

static testmethod void testOne() {

        CMIAJsonEntryMap cmj = new CMIAJsonEntryMap();

		String str1='test';
		
		CMIAJsonEntry cmia1;
		
		cmj.addEntry(str1,cmia1);
		
		CMIAJsonEntryPair cmia= new CMIAJsonEntryPair();
		
		cmj.addEntry(cmia);
		
		Boolean bol= true;
		
		cmj.addEntry(str1,bol);
		
		Double value1=4.124563;
		
		cmj.addEntry(str1,value1);
		
		Integer int1=898;
		
		cmj.addEntry(str1,int1);
		
		String str2='test2';
		
		cmj.addEntry(str1,str2);
		
		cmj.render();
		}
}

 

and

public class CMIAJsonEntryPair implements CMIAJsonEntry {
	private String key;
	private CMIAJsonEntry value;
	
	public CMIAJsonEntryPair(){
		
	}
		
	public CMIAJsonEntryPair(String key, CMIAJsonEntry value) {
		this.key = key;
		this.value = value;
	}
	
	public String render() {
		return '"' + key + '" : ' + value.render();
	}
	
	static testmethod void testOne() {

           String key = 'mykey';

           CMIAJsonEntry cmiaMap;   // any concrete class that implements CMIAJsonEntry could go here.

           CMIAJsonEntryPair cmia = new CMIAJsonEntryPair( key, cmiaMap );

           String rendered  =  cmia.render(); 


	}
}

 Thank you in advance,

 

Apple

 

  • March 19, 2012
  • Like
  • 0

I am new to Apex and just starting to learn it, so I would appreciate any help here. 

 

I  want to add list to my string, For Example:

 

If My array is:  Attendee[] = [a, b, c, d]

 

My string should be:  String AttendeeName = 'a,b,c,d';

 

but below code return:   ', b'

 

Set<ID> setAttendee = new Set<ID>();
	
	for(Event e:trigger.new){
		setAttendee.add(e.Id);
	}
	
	list<EventAttendee> Attendee = [Select	EventAttendee.Attendee.Name
					From	EventAttendee
					Where	EventAttendee.EventId IN :setAttendee];
									
	String AttendeeName;	
	
	for(EventAttendee a:Attendee){
		
		AttendeeName = ', ' + a.Attendee.Name;
	}

 

 

Thank you in advance,

 

Apple

 

  • March 14, 2012
  • Like
  • 0

Hello

 

I am new to Apex and just starting to learn it, so I would appreciate any help here.

 

I was informed the class needs to pass 75% before I can depoly it to my production org

 

Can anyone help me write a Test Class for this?

 

   

    for this not need to have test

public interface CMIAJsonEntry {
	String render();
}

  this is require for test class:

public class CMIAJsonEntryPair implements CMIAJsonEntry {
	private String key;
	private CMIAJsonEntry value;
	
	public CMIAJsonEntryPair(String key, CMIAJsonEntry value) {
		this.key = key;
		this.value = value;
	}
	
	public String render() {
		return '"' + key + '" : ' + value.render();
	}
}

 and this

public class CMIAJsonEntryMap implements CMIAJsonEntry {
	private LIST<CMIAJsonEntryPair> pairs;

	public CMIAJsonEntryMap() {
		pairs = new LIST<CMIAJsonEntryPair>();
	}
	
	public void addEntry(CMIAJsonEntryPair p) {
		pairs.add(p);
	}
	
	public void addEntry(String key, CMIAJsonEntry value) {
		pairs.add(new CMIAJsonEntryPair(key, value));
	}
	
	public void addEntry(String key, boolean value) {
		pairs.add(new CMIAJsonEntryPair(key, value ? CMIAJsonEntryBool.R_TRUE : CMIAJsonEntryBool.R_FALSE));
	}

	public void addEntry(String key, double value) {
		pairs.add(new CMIAJsonEntryPair(key, new CMIAJsonEntryDouble(value)));
	}
	
	public void addEntry(String key, integer value) {
		pairs.add(new CMIAJsonEntryPair(key, new CMIAJsonEntryInt(value)));		
	}
	
	public void addEntry(String key, String value) {
		pairs.add(new CMIAJsonEntryPair(key, new CMIAJsonEntryString(value)));		
	}
	
	public String render() {
		String r = '{';
		integer last = pairs.size() - 1;
		for (integer i = 0; i < pairs.size(); i++) {
			r = r + pairs.get(i).render();
			if (i != last)
				r = r + ', ';
		}
		return r + ' }';
	}
}

 Thank you in advance,

 

Apple

  • March 06, 2012
  • Like
  • 0

Hi All,

 

   

I created a VF page with required input fields and a validation rule along with a command buttons ( "Update" buttons). While submitting the information if I does not input on one of the required fields, It displays the validation rule error message and at the same time all fields are get cleared.

 

But, I like to keep all data on the fields, but display error message.


How to resolve this "Fields get cleared" problem... Please suggest me

 

Thanks,

 

 

 

<apex:page Controller="MyAccount">
    <apex:form >    
    <apex:outputPanel id="AuthorizedContacts">    
    <apex:message/>
    <h2>{!primaryContact.Name}</h2><br/>
    <apex:commandbutton action="{!addAuthContact}" value="Add Contact" rerender="AuthorizedContacts" rendered="{!addAuthContact == false}"/>
    
        <apex:repeat value="{!newAuth}" var="a">
        <apex:outputpanel rendered="{!addAuthContact}">
            {!a.Contact_Type__c}<br/>
            <h4>Name &amp; Contact</h4><br/>
              
                FIRST NAME* <apex:inputField value="{!a.FirstName}" id="contact-first-name" required="true"/>
                LAST NAME* <apex:inputField value="{!a.LastName}"  id="contact-last-name" required="true"/>
                PHONE* <apex:inputField value="{!a.Phone}"  id="contact-phone" required="true"/>
                EMAIL ADDRESS* <apex:inputField value="{!a.Email}"  id="contact-email" required="true"/> 
                
            <h4>Contact Address</h4><br/>
            
                ADDRESS 1 <br/><apex:inputText value="{!a.Contact_Address_Line_1__c}"  id="contact-addr-1"/><br/>
                ADDRESS 2 <br/><apex:inputText value="{!a.Contact_Address_Line_2__c}"  id="contact-addr-2"/><br/>
                CITY <br/><apex:inputText value="{!a.Contact_Town_City__c}"  id="contact-city"/><br/>
                POST CODE <br/><apex:inputText value="{!a.Contact_Postal_Code__c}"  id="contact-postal"/><br/>
                COUNTY <br/><apex:inputText value="{!a.Contact_County__c}"  id="County"/><br/>
                
                COUNTRY<br/>
                <apex:SelectList value="{!CountryName}" size="1">
                    <apex:selectOptions value="{!lstCountry}"></apex:selectOptions>
                </apex:SelectList><br/>
            
            <h4>Is This Authorized Contact Part of Your:</h4><br/>
                <apex:Inputcheckbox value="{!a.IsHousehold__c}"/>
                <label>Household</label>
                <apex:Inputcheckbox value="{!a.IsBusiness__c}"/>
                <label >Business</label><br/>
                <apex:messages rendered="{!IsValidate}" styleClass="errorMsg"/><br/>
            <apex:commandbutton styleClass="cancel" action="{!cancelAuth}" value="Cancel" immediate="true" rerender="AuthorizedContacts"/>
            <apex:commandButton styleClass="button-medium" action="{!saveAuth}" value="Save Updates" rerender="AuthorizedContacts"/>
        
          </apex:outputPanel>      
        </apex:repeat>
        </apex:outputPanel>
    </apex:form>
</apex:page>

 

 

public class MyAccount {
    
    private Id uid;
    public Id aid{get;set;}
    public Id cid{get;set;}
	
	public string CountryName {get;set;}
	
    public Boolean IsValidate{get;set;}
    public Boolean addAuthContact{get;set;}
    
    public User objUser{get;set;} 
    public Contact primaryContact;
	
    public list<Contact> newAuth;
	
    public MyAccount(){
	
        uid = UserInfo.getUserId();
        getObjUser();    
    }
    
    public List<SelectOption> getlstCountry()
    {  list<SelectOption> options = new list<SelectOption>(); 
        try{
            list<Country__c> ls = [select Name,LZ_Country_Id__c,Id from Country__c];
            
			 	Country__c uk = [select Name,LZ_Country_Id__c,Id from Country__c Where Name = 'United Kingdom'];
            
			 	options.add(new SelectOption(uk.Id,uk.Name));
				
            for(Country__c o:ls){
                if(o.Name != 'United Kingdom')
                options.add(new SelectOption(o.Id,o.Name));
            }
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        }  
        return options;
    }
	
    public void getObjUser(){
        try {
            uid = Apexpages.currentPage().getParameters().get('id');
            if(uid != null){
            objUser = [Select   User.ContactId,
                                User.AccountId,
                                User.UserType
                        From    User
                        Where   User.Id = :uid ];
            cid = objUser.ContactId;
            aid = objUser.AccountId;    
            }
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        } 
    }
    
    public Contact getprimaryContact(){
        try
        {
            if(cid != null){
                primaryContact = [Select    Contact.Id,
                                            Contact.Name,
                                    From    Contact
                                    Where   Contact.Id =:cid];
            }
        }catch(Exception ex){
            System.debug('Error From ' + ex.getMessage());
        } 
        return primaryContact;
    }    
  
    public list<Contact> getnewAuth(){
        try
            {   
                newAuth = new list<Contact>();
                Contact ac = new Contact();
                if(aid != null) {
                    ac.AccountId = aid;
                    ac.Contact_Type__c = 'Authorized Contact';
                } 
                newAuth.add(ac);    
        }
        catch(Exception ex)
        {
                System.debug('Error From' + ex.getMessage());
        }   
         return newAuth;
    }
    
    public PageReference addAuthContact(){
        try{
            getnewAuth();
            addAuthContact = true;
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        }
        return null;
    }   
     
    public PageReference cancelAuth(){
        try{
            newAuth = null;
            addAuthContact = false;
        }
        catch(Exception ex)
        {
            System.debug('Error From ' + ex.getMessage());
        }
        return null;
    }
    
    public PageReference saveAuth() {  
        
         try{
        List<Contact> tempCon = new List<Contact>();
        if(newAuth != null)  {      
            for(Contact t : newAuth)
            {
                t.Contact_Country__c = CountryName ;                
                tempCon.add(t);
            }
        }
        insert tempCon;
        addAuthContact = false;
        }catch(DmlException ex){
        	if(newAuth[0].IsBusiness__c == false && newAuth[0].IsHousehold__c == false){
        		IsValidate = true;
        	}        	
            ApexPages.addMessages(ex);
        }
        return null;
    }
}

 

 

 

  • August 19, 2013
  • Like
  • 0

Hello friends,

 

I want to add a html 5 attribute (Ex : - placeholder="First name") with <apex:inputText />. Is there any way to add html 5 attribute with <apex:inputText />.

 

I do not want to go manipulation using jQuery OR JavaScript , If we have essy solution for it.

 

I Tried below approch but it's not working.

 

<apex:page doctype="html-5.0" controller="RequestWizardController" sidebar="false" showHeader="false" >
     <apex:form>
            <apex:repeat value="idToItemRequest" var="rec">
                   <apex:inputText html-placeholder="First name" value="{! idToItemRequest[rec].Sample__c}" />
            </apex:repeat>
     </apex:form>
</apex:page>