You need to sign in to do that
Don't have an account?
Karthikeya Mullunja Ramakrishna
Public Class ContactUpdateServer {
public Contact objContact{get;set;}
public String currentRecordId {get;set;}
public Contact con{get;set;}
public List<contact> up = new List<Contact>();
List<ContactCreationCalloutParser.Profile> lstProfilemain = new List<ContactCreationCalloutParser.Profile>() ;
public ContactUpdateServer(ApexPages.StandardController controller) {
Boolean isValid = False;
currentRecordId = ApexPages.CurrentPage().getparameters().get('id');
con = [select SSO_Number__c,Name from Contact where id =: currentRecordId ];
system.debug('----- sso --- ' +con);
string searchstring = con.SSO_Number__c;
if(searchString.length() == 9){
// Check if search string is 9 digit long numeric value. i.e SSO number.
if(searchString.isNumeric()){
isValid = True;
}}
if(isValid){
system.debug('----isvalid----' +isValid);
HttpResponse s = ContactServer();
string token = ParseJSON(s);
ContactServer1(token);
}
}
Public HttpResponse ContactServer() {
REST CALL
}
public Pagereference updateContact(){
Contact objContact = new Contact();
for(ContactCreationCalloutParser.Profile objProfile : lstProfilemain)
{
objContact.Id = ApexPages.CurrentPage().getparameters().get('id');
objContact.Supervisorname__c = objProfile.supervisorname;
objContact.Type__c = objProfile.type_Z;
objContact.title = objProfile.title;
objContact.firstname = objProfile.firstname;
objContact.lastName = objProfile.lastName;
objContact.Email= objProfile.Email;
objContact.SSO_Number__c = objProfile.sso;
objContact.Phone= objProfile.workphone;
objContact.MailingStreet = objProfile.cdilocation;
objContact.Business__c = objProfile.business;
objContact.Url__c = objProfile.url;
objContact.Jobtitle__c = objProfile.jobtitle;
objContact.preferredname__c = objProfile.preferredname;
system.debug('----email --- '+ objContact.Email);}
try {
update objContact;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Update Successful'));
system.debug('---- update success ---');
}
catch(DmlException e)
{
System.debug('An unexpected error has occurred: ' + e.getMessage());
Apexpages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Update Failed. Please Contact Administrator.'));
}
return null;
}
Public Pagereference Goback(){
Contact objContact = new Contact();
objContact.Id = ApexPages.CurrentPage().getparameters().get('id');
PageReference pageRef = new PageReference('/' + objContact.Id);
pageRef.setRedirect(true);
return pageRef;
}
}
Please guide me to write a test class for updateContact() function
Suggestions to Text class
Public Class ContactUpdateServer {
public Contact objContact{get;set;}
public String currentRecordId {get;set;}
public Contact con{get;set;}
public List<contact> up = new List<Contact>();
List<ContactCreationCalloutParser.Profile> lstProfilemain = new List<ContactCreationCalloutParser.Profile>() ;
public ContactUpdateServer(ApexPages.StandardController controller) {
Boolean isValid = False;
currentRecordId = ApexPages.CurrentPage().getparameters().get('id');
con = [select SSO_Number__c,Name from Contact where id =: currentRecordId ];
system.debug('----- sso --- ' +con);
string searchstring = con.SSO_Number__c;
if(searchString.length() == 9){
// Check if search string is 9 digit long numeric value. i.e SSO number.
if(searchString.isNumeric()){
isValid = True;
}}
if(isValid){
system.debug('----isvalid----' +isValid);
HttpResponse s = ContactServer();
string token = ParseJSON(s);
ContactServer1(token);
}
}
Public HttpResponse ContactServer() {
REST CALL
}
public Pagereference updateContact(){
Contact objContact = new Contact();
for(ContactCreationCalloutParser.Profile objProfile : lstProfilemain)
{
objContact.Id = ApexPages.CurrentPage().getparameters().get('id');
objContact.Supervisorname__c = objProfile.supervisorname;
objContact.Type__c = objProfile.type_Z;
objContact.title = objProfile.title;
objContact.firstname = objProfile.firstname;
objContact.lastName = objProfile.lastName;
objContact.Email= objProfile.Email;
objContact.SSO_Number__c = objProfile.sso;
objContact.Phone= objProfile.workphone;
objContact.MailingStreet = objProfile.cdilocation;
objContact.Business__c = objProfile.business;
objContact.Url__c = objProfile.url;
objContact.Jobtitle__c = objProfile.jobtitle;
objContact.preferredname__c = objProfile.preferredname;
system.debug('----email --- '+ objContact.Email);}
try {
update objContact;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Update Successful'));
system.debug('---- update success ---');
}
catch(DmlException e)
{
System.debug('An unexpected error has occurred: ' + e.getMessage());
Apexpages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Update Failed. Please Contact Administrator.'));
}
return null;
}
Public Pagereference Goback(){
Contact objContact = new Contact();
objContact.Id = ApexPages.CurrentPage().getparameters().get('id');
PageReference pageRef = new PageReference('/' + objContact.Id);
pageRef.setRedirect(true);
return pageRef;
}
}
Please guide me to write a test class for updateContact() function