0

I have a requirement that i need to perform dynamic dml operations and when i have custom object registration and vf pages like login and registration And registration object with fields name,password,email.When i entered name dynamically in vf page if i entered name is existed in object it returns null if i entered name is doesn't exist in object then we need to insert the data and go to login page. Please check my code:

ApexClass

public class Registrationapex_Rum {

public String rumname{set;get;}

public String password{set;get;}

public String email{set;get;}

public list<Registartion__c> reg{set;get;}

public void search(){

reg=[select Rum_Name__c,Password__c,E_Mail__c from Registartion__c where Rum_Name__c=:rumname];

for(Registartion__c rl:reg){

if(rl.Rum_Name__c==rumname){

clear();

}else{

create();

}
}
}

public PageReference create(){

Registartion__c r=new Registartion__c();

r.Rum_Name__c=rumname;

r.Password__c=password;

r.E_Mail__c=email;

insert r;

PageReference p=new PageReference('/apex/loginpage_Rum');

return p;

}

public void clear(){

rumname=null;

password=null;

email=null;

}
}

VF Page:

<apex:page controller="Registrationapex_Rum">

<apex:form >

<apex:pageBlock title="Registration" id="pb1">
<apex:pageBlockSection columns="1">

<apex:pageBlockSectionItem >
<apex:outputLabel value="Rum Name"/>
<apex:inputText value="{!rumname}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Password"/>
<apex:inputText value="{!password}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="E-mail"/>
<apex:inputText value="{!email}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:commandButton value="Submit" action="{!search}"/>
<apex:commandButton value="Clear" action="{!clear}" reRender="pb1"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Thanks In Advance Sampath

1
  • Your code is very hard to read, and it's not really clear what the concrete problem is. Could you try to make it a bit more clear? – rael_kid Mar 11 '16 at 9:38
0

The minimum change to get this to work is I think this:

public PageReference search() {
    Integer existingCount = [
            select count()
            from Registartion__c
            where Rum_Name__c = :rumname
            ];
    if (existingCount == 0) {
        return create();
    } else {
        return null;
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.