You need to sign in to do that
Don't have an account?
Aditya Rayavarapu 5
Command button action to reference inputfield
Hello,
In my controller, I have:
public Contact c {get; set;}
public Contact cont {get; set;}
Public String acc3{get;set;}
Public String acc2{get;set;}
public controller(){
acc3 = ApexPages.currentPage().getParameters().get('Master_Id__c');
if(acc3 != null)
{
this.c= [ SELECT Master_Id__c
FROM Contact
WHERE Master_Id__c = : acc3 ];
}
else
{this.c= new Contact ();}
acc2 = ApexPages.currentPage().getParameters().get('LastName');
if(acc2 != null)
{
this.cont= [ SELECT LastName
FROM Contact
WHERE LastName = : acc2 ];
}
else
{this.cont= new Contact(ReportsTo=new contact(Master_Id__c='xxxx')); }
}
For string acc2, in the else statement, I have hardcoded the value to 'xxxx'. However, I want that value to be the same as the string in acc3 (which is an input field in my VF page). So it would look something like (Master_Id__c='!acc3'));
However, I can't seem to get the syntax for it correctly.
Any suggestions on how to correctly reference the string acc3?
Thanks
In my controller, I have:
public Contact c {get; set;}
public Contact cont {get; set;}
Public String acc3{get;set;}
Public String acc2{get;set;}
public controller(){
acc3 = ApexPages.currentPage().getParameters().get('Master_Id__c');
if(acc3 != null)
{
this.c= [ SELECT Master_Id__c
FROM Contact
WHERE Master_Id__c = : acc3 ];
}
else
{this.c= new Contact ();}
acc2 = ApexPages.currentPage().getParameters().get('LastName');
if(acc2 != null)
{
this.cont= [ SELECT LastName
FROM Contact
WHERE LastName = : acc2 ];
}
else
{this.cont= new Contact(ReportsTo=new contact(Master_Id__c='xxxx')); }
}
For string acc2, in the else statement, I have hardcoded the value to 'xxxx'. However, I want that value to be the same as the string in acc3 (which is an input field in my VF page). So it would look something like (Master_Id__c='!acc3'));
However, I can't seem to get the syntax for it correctly.
Any suggestions on how to correctly reference the string acc3?
Thanks
new contact(Master_Id__c=acc3)
I have tried that, but it does not work
Error message:
System.DmlException: Insert failed. First exception on row 0; first error: MISSING_ARGUMENT, Master_Id__c not specified: []
I have also tried
='!acc3'
=get.acc3
=!acc3
=get<acc3>
=get<String>{acc3}
and similar syntaxes, but none of them work
this.cont= new Contact(Master_Id__c=acc3)
but verify what you are getting the value for acc3. system.debug('acc3 :' + acc3).
Contact c1 = new Contact(Master_Id__c=acc3);
insert c1;
this.cont = new Contact(ReportTo = c1.id);
insert this.cont;
I have tried that as well, It does not work.
Salesforce only accepts standard lookups to insert parent and child in the same action, and only specific syntax
So the final code was:
acc2 = ApexPages.currentPage().getParameters().get('LastName');
if(acc2 != null)
{
this.cont= [ SELECT LastName
FROM Contact
WHERE LastName = : acc2 ];
}
else
{this.cont= new Contact() ; }
}
public PageReference save() {
insert c;
this.cont= New Contact(ReportsTo= new Contact(Master_Id__c = c.Master_Id__c),LastName=cont.LastName);
insert cont;
Thanks a lot for your help Balaji!!