- Avinash Ravisankar 13
- NEWBIE
- 0 Points
- Member since 2017
- 4i Apps
-
ChatterFeed
-
0Best Answers
-
2Likes Received
-
0Likes Given
-
7Questions
-
1Replies
Referencing multipicklist in Apex Trigger
Hi All,
I have a trigger to assign Contacts by criteria-based-Round Robin based on Project and Language parameters. The below code query was returning values as long as the Projects field was a picklist, now after I've converted it into a multipicklist, it doesn't seem to return any values. Please asist
I have a trigger to assign Contacts by criteria-based-Round Robin based on Project and Language parameters. The below code query was returning values as long as the Projects field was a picklist, now after I've converted it into a multipicklist, it doesn't seem to return any values. Please asist
trigger AssignSalesmanager on contact(before insert , after update) { String currentuser = [Select alias From User Where Id = :UserInfo.getUserId()].alias; system.debug(currentuser); if(currentuser == 'guest' || currentuser == 'oadmi') { if(Trigger.isBefore) { if(Trigger.IsInsert) { Map<String,List<round_robin__c>> mapOfLangUsers = new Map<String,List<round_robin__c>>(); Map<String,List<round_robin__c>> mapOfProjUsers = new Map<String,List<round_robin__c>>(); map<string,list<contact>> MapoflangandContacts = new map<string,list<contact>>(); map<string,list<contact>> MapofprojandContacts = new map<string,list<contact>>(); Set<String> projectValues = new Set<String>(); String projValues; Set<String> langValues = new Set<String>(); List<Contact> allContacts = new List<contact>(); Boolean hasModifiedUser = false; for(contact eachcontact: trigger.new){ if(!String.isBlank(eachcontact.Language__c) && !String.isBlank(eachcontact.Projects__c)) { allContacts.add(eachcontact); langValues.add(eachcontact.language__c); projectValues.add(eachcontact.projects__c); projvalues= String.valueOf(projectValues); } } if(MapoflangandContacts.size() > 0 && MapoflangandContacts!= null) { for(string strlang : MapoflangandContacts.keyset()){ integer i=0; for(Contact objContact : MapoflangandContacts.get(strlang)){ objContact.ownerid = mapOfLangUsers.get(objContact.Language__c)[i].Round_Robin_User__c; mapOfLangUsers.get(objContact.Language__c)[i].Count__c = mapOfLangUsers.get(objContact.Language__c)[i].Count__c+1; i++; if(i==mapOfLangUsers.get(objContact.Language__c).size()) i=0; } } list<round_robin__c> lstrb = new list<round_robin__c>(); for(list<round_robin__c> lstuser : mapOfLangUsers.values()){ lstrb.addall(lstuser); } update lstrb; } if(MapofprojandContacts.size() > 0 && MapofprojandContacts!= null) { for(string strProject : MapofprojandContacts.keyset()){ integer i=0; for(Contact objContact : MapofprojandContacts.get(strProject)){ objContact.ownerid = mapOfProjUsers.get(objContact.Projects__c)[i].Round_Robin_User__c; mapOfProjUsers.get(objContact.Projects__c)[i].Count__c = mapOfProjUsers.get(objContact.Projects__c)[i].Count__c+1; i++; if(i==mapOfProjUsers.get(objContact.Projects__c).size()) i=0; } } list<round_robin__c> lstrb = new list<round_robin__c>(); for(list<round_robin__c> lstuser : mapOfProjUsers.values()){ lstrb.addall(lstuser); } update lstrb; } if(allContacts.size() > 0 && allContacts!=null) { Integer recordCount = [select count() from contact]; system.debug('recordCount='+recordCount); Integer rr = [select Count() from round_robin__c where Is_Active__c = TRUE AND Language__c IN:langValues AND Projects__c INCLUDES (:projvalues) ]; system.debug('rr='+rr); if(rr!=0) { Integer index = Math.mod(recordCount+1,rr); list <round_robin__c> lstRoundSpecificUsers = [select id,name,Count__c,Round_Robin_User__c,Language__c,Projects__c from round_robin__c where Is_Active__c = TRUE AND Language__c IN:langValues AND Projects__c INCLUDES (:projvalues) ]; system.debug(lstRoundSpecificUsers ); Integer i; IF(i==null) {i=0;} for(contact eachContact : trigger.new) { system.debug('index='+index); eachContact.ownerId = lstRoundSpecificUsers[index].Round_Robin_User__c; } } } } } } if(trigger.isUpdate) { System.debug('----->Entered'); Map<Id,Id> mapOfContact = new Map<Id,Id>(); for(Contact con: trigger.new) { if(con.OwnerId != trigger.oldmap.get(con.id).ownerId) { System.debug('----->Entered111'); mapOfContact.put(con.Id,con.OwnerId); } } list<pba__Request__c> lstRequest = [select id,name,Contact_Owner__c,pba__Contact__c from pba__Request__c where pba__Contact__c IN:mapOfContact.keySet() ]; if(lstRequest.size() > 0) { for(pba__Request__c eachReq : lstRequest) { eachReq.OwnerId = mapOfContact.get(eachReq.pba__Contact__c); } } update lstRequest; } }
The system.debug statement for vairable rr keeps returning as 0 if I compare it with a set of values. It returns rows if I hardcode the values, which I don't want to. I want this to be dynamic.
How do i work around this.
Thanks,
Avinash
- Avinash Ravisankar 13
- April 06, 2017
- Like
- 2
Trying to capture UTM Parameters in Visualforce Site
Dear All,
I'm trying to pass UTM Parameters into hidden fields in my VF page. I'm not able to populate these fields at all. Could someone help out?
Visualforce Page:
I'm trying to pass UTM Parameters into hidden fields in my VF page. I'm not able to populate these fields at all. Could someone help out?
Visualforce Page:
<apex:page standardController="contact" extensions="FormController" showHeader="false" sidebar="false" standardStylesheets="false" > <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-90589553-1', 'auto'); ga('send', 'pageview'); </script> <script type="text/javascript"> // Parse the URL function getParameterByName(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } // Give the URL parameters variable names var source = getParameterByName('utm_source'); var medium = getParameterByName('utm_medium'); var campaign = getParameterByName('utm_campaign'); // Put the variable names into the hidden fields in the form. document.getElementsById("txt_source").value = source; document.getElementsById("txt_medium").value = medium; document.getElementsById("txt_campaign").value = campaign; </script> <script type="text/javascript"> //allows number and hyphen only function inputLimiter(e,allow) { var AllowableCharacters = ''; if (allow == 'Letters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';} if (allow == 'Numbers'){AllowableCharacters='1234567890';} if (allow == 'NameCharacters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.\'';} if (allow == 'NameCharactersAndNumbers'){AllowableCharacters='1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-\'';} if (allow == 'Currency'){AllowableCharacters='1234567890.';} var k = document.all?parseInt(e.keyCode): parseInt(e.which); if (k!=13 && k!=8 && k!=0){ if ((e.ctrlKey==false) && (e.altKey==false)) { return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1); } else { return true; } } else { return true; } } </script> <apex:form style="background-color:white"> <a class="button" href="http://www.omniyat.com/project/thesterling/" target="_blank" style="background-color:black;font-weight:normal; size:14pt font-family:Verdana;">LEARN MORE</a> <div class="header"> <a href = "http://www.omniyat.com/project/thesterling/" target="_blank"><img src = "https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000EjgQ&oid=00D7E0000000gNx&lastMod=1484130597000" align="left" /> </a> </div> </apex:form> <br/> <br/> <br/> <br/> <br/> <apex:form style="background-image: url('https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000EjwE&oid=00D7E0000000gNx&lastMod=1484176938000');background-size:cover "> <body> <br/> <div align = "right" Style="margin-right: 5cm;font-family:Verdana;font-size:16pt;">REGISTER FOR MORE INFO</div> <div align = "right" Style="margin-right: 4cm;"> <apex:panelGrid columns="1" > <apex:inputfield styleclass="in" value="{!con.FirstName}" html-placeholder=" First Name∗" style="width: 360px; height: 40px" /> <apex:outputText value="{!inputTextErrorMessage}" rendered="{!IF(con.FirstName = '', true, false)}" style="color:red"/> <br/> <apex:inputField styleclass="in" value="{!con.LastName__c}" html-placeholder=" Last Name∗" style="width: 360px; height: 40px" /> <apex:outputText value="{!inputTextErrorMessage2}" rendered="{!IF(con.LastName__c = '', true, false)}" style="color:red"/><br/> </apex:panelGrid> <apex:panelGrid columns="2" > <apex:inputField styleclass="in" value="{!con.Country_Code__c}" style="width: 120px; height: 40px" /> <apex:inputField styleclass="in" value="{!con.ContactPhone__c}" onkeypress="return inputLimiter(event,'Numbers');" id="Phone" html-placeholder=" Mobile Number∗" style="width: 235px; height: 40px" /> </apex:panelGrid> <apex:outputText value="{!inputTextErrorMessage4}" rendered="{!IF(OR(con.ContactPhone__c = null,con.Country_Code__c = 'CountryCode*'), true, false)}" style="color:red"/><br/> <apex:panelGrid columns="1" > <apex:inputField styleclass="in" value="{!con.email}" html-placeholder=" Email Address∗" style="width: 360px; height: 40px" /> <apex:outputText value="{!inputTextErrorMessage5}" rendered="{!IF(con.email = '', true, false)}" style="color:red"/><br/> <apex:inputField styleclass="in" value="{!con.Nationality__c}" html-placeholder=" Nationality∗" style="width: 364px; height: 40px"/> <apex:outputText value="{!inputTextErrorMessage6}" rendered="{!IF(con.Nationality__c = 'Nationality*', true, false)}" style="color:red"/><br/> <apex:inputField styleclass="in" value="{!con.Preferred_Time_to_Call__c}" style="width: 364px; height: 40px"/> <apex:inputHidden value="{!con.Visitor_ID__c}" /> <apex:inputHidden value="{!con.Source__c}" id="txt_source" /> <apex:inputHidden value="{!con.Campaign__c}" id="txt_campaign_name"/> <apex:inputHidden value="{!con.Content__c}" id="txt_content" /> <apex:inputHidden value="{!con.Medium__c}" id="txt_medium" /> <apex:inputHidden value="{!con.Count_of_Sessions__c}" /> <apex:inputHidden value="{!con.Count_of_Pageviews__c}"/> <br/> <div class="g-recaptcha" data-sitekey='6LfhchEUAAAAADq1zE8wGqviN92b2IemvHSEmvuK'></div> <script src='https://www.google.com/recaptcha/api.js'></script> <apex:outputText value="{!inputTextErrorMessage3}" style="color:red"/> <br/> </apex:panelGrid> <span style="color:black;font-size:16pt;margin-right: 3cm;font-weight:bold;font-family:Verdana;">AGENT <apex:inputCheckbox value="{!con.Agent__c}" styleClass="myCheckBox" /></span> <apex:commandButton style=" margin-right: 1cm;; background:#c00;width:75px;height:30px;color:white;font-size:12pt;" action="{!submit}" value="Submit" /></div> <p></p><br/><br/> <script src='https://www.google.com/recaptcha/api.js'></script> </body> </apex:form> <br/> <apex:form > <img src="https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000EjvL&oid=00D7E0000000gNx&lastMod=1484163217000" style="width:100%"/> </apex:form> <br/> <center> <h2>Visit Sterling show apartment on level 26, One by Omniyat Tower, Business Bay</h2></center> <apex:form > <apex:panelGrid columns="3" > <img src="https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000EjvQ&oid=00D7E0000000gNx&lastMod=1484164048000" style="width:33%"/> <img src="https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000Ejva&oid=00D7E0000000gNx&lastMod=1484164450000" style="width:33%"/> <img src="https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000EjvV&oid=00D7E0000000gNx&lastMod=1484164361000" style="width:33%"/> </apex:panelGrid> </apex:form> <br/> <apex:form > <img src = "https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000Ejvf&oid=00D7E0000000gNx&lastMod=1484167712000" style="width:100%"/> </apex:form> <center><img src="https://c.cs86.content.force.com/servlet/servlet.ImageServer?id=0157E000000Ei3I&oid=00D7E0000000gNx&lastMod=1484172389000"/> </center> <center> <p3>For further information, contact one of our sales executives or <br/> call us on 800 666 or email at sales@omniyat.com</p3><br/></center> <br/> <script src='https://www.google.com/recaptcha/api.js'></script> <style> h1 { color:white; font-size:18pt; } h2 { align:center; color:grey; font-size:18pt; } h3 { align:right; color:black; font-size:16pt; } p { color:black; font-size:18pt; } p5 { color:red; font-size:10pt; } p3 { color:black; font-size:14pt; text-align: center; } .in { font-size:10pt; color:white; width:82%; background-color:black; } label { display: block; width: 150px; color:#ffffff; font-family:"Verdana" } .button { display: block; width: 115px; height: 25px; background: #4E9CAF; padding: 10px; text-align: center; border-radius: 5px; color: white; font-weight: bold; float:right; } input[type=checkbox] { border: 0px; width: 2%; height: 2em; background-color: #ffa500; } @-ms-viewport{ width: device-width; } header { background-color:white; } } </style> </apex:page>
Thanks,
Avinash
- Avinash Ravisankar 13
- January 21, 2017
- Like
- 0
Require help developing a test class for this Extension
Hi,
Below are my main class and test class. I've only been able to achieve 49% coverage so far. Can someone help out please?
Apex Class:
Thanks,
Avinash
Below are my main class and test class. I've only been able to achieve 49% coverage so far. Can someone help out please?
Apex Class:
public class FormController { public FormController() { } //public string email ; public Apexpages.StandardController controller; public Apexpages.StandardController control; public contact con {get;set;} public FormController (ApexPages.StandardController stdController) { this.con = (contact)stdController.getRecord(); this.controller = stdController; } public String FirstName{ get; set; } public String LastName{ get; set; } public String email{ get; set; } public String Phone{ get; set; } public String inputTextErrorMessage {get; set;} public String inputTextErrorMessage2 {get; set;} public String inputTextErrorMessage3 {get; set;} public String inputTextErrorMessage4 {get; set;} public String inputTextErrorMessage5 {get; set;} public String inputTextErrorMessage6 {get; set;} public String inputTextErrorMessage7 {get; set;} private String baseUrl = 'https://www.google.com/recaptcha/api/siteverify'; private String secret = '6LfhchEUAAAAAHB6OuvyEp093srAR0qkpu1vx-Yl'; public String sitekey { get{return '6LfhchEUAAAAADq1zE8wGqviN92b2IemvHSEmvuK';} } public String response { get { return ApexPages.currentPage().getParameters().get('g-recaptcha-response'); } } public PageReference submit() { String responseBody = makeRequest(baseUrl, 'secret=' + secret + '&response='+ response ); String success = getValueFromJson(responseBody, 'success'); if(success.equalsIgnoreCase('true')){ System.debug('Entered into save'); if(con.FirstName == null) {inputTextErrorMessage='Please enter "First Name"'; } if(con.LastName__c == null) {inputTextErrorMessage2='Please enter "Last Name"'; } if(con.Country_Code__c == 'CountryCode*' || con.ContactPhone__c == null) {inputTextErrorMessage4='Please choose "Country Code" & enter "Mobile Number"'; } if(con.Email == null) {inputTextErrorMessage5='Please enter "Email"'; } if(con.Nationality__c == 'Nationality*') {inputTextErrorMessage6='Please choose "Nationality"'; } if(con.Preferred_Time_to_Call__c == 'Preferred time to Call* (GMT +4)') {inputTextErrorMessage7='Please choose "Preferred time to Call"'; return null;} con.LastName = con.LastName__c ; string conname = con.FirstName+' '+con.LastName__c; system.debug('conname====>'+conname ); integer flag =1; list<contact> conlist = [select name,email from contact ]; for(contact c:conlist){ if(c.name == conname && c.email == con.email){ pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = c.id; r.status__c = 'Pending'; try{ list<pba__Request__c> relist = [select id,pba__Contact__c,status__c, createddate from pba__Request__c]; for(pba__Request__c req:relist) { if(r.pba__Contact__c == req.pba__Contact__c) { if((req.status__c == 'Active' || req.status__c == 'Pending')&& (req.createddate.date().daysbetween(System.today()))<7) { pagereference pg = new pagereference('https://c.cs86.visual.force.com/apex/OmniyatErrMsg'); return pg; return null; } } } } catch(DMLException e) { return null; } insert r; flag++; } } system.debug('flag==='+flag); if(flag==1) { insert con; pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = con.id; r.status__c = 'Active'; insert r; } pagereference pg = new pagereference('http://omniyat-omniyat.cs86.force.com/thankyou'); return pg; } else{ inputTextErrorMessage3='Please verify Captcha'; return null; } } private String makeRequest(string url, string body) { HttpResponse response = null; HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('POST'); req.setBody (body); try { Http http = new Http(); response = http.send(req); return response.getBody(); } catch(System.Exception e) { System.debug('ERROR: ' + e); } return '{"success":false}'; } public string getValueFromJson ( String strJson, String field ){ JSONParser parser = JSON.createParser(strJson); while (parser.nextToken() != null) { if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)) { if(parser.getText() == field){ // Get the value. parser.nextToken(); return parser.getText(); } } } return null; } }Test Class: 49% coverage
@isTest public class FormController_Test{ public static testmethod void FormController_Test1() { Test.StartTest(); PageReference pageRef = new pagereference('https://cs86.visual.force.com/apex/OmniyatErrMsg'); Test.setCurrentPage(pageRef); PageReference pageRef1 = new pagereference('http://omniyat-omniyat.cs86.force.com/thankyou'); Test.setCurrentPage(pageRef1); Contact conTemp = new Contact(); conTemp.FirstName = 'Full'; conTemp.LastName__c = 'Name'; conTemp.LastName = conTemp.LastName__c; conTemp.Nationality__c = 'India'; conTemp.Preferred_time_to_call__c = 'Forenoon'; conTemp.Country_Code__c = 'Afghanistan +93'; conTemp.Email = 'test@test.com'; conTemp.Phone = '9191919191'; FormController contrl = new FormController(); contrl.Con = conTemp; contrl.submit(); pba__Request__c reqTemp1 = new pba__Request__c(); reqTemp1.pba__Contact__c = conTemp.Id; reqTemp1.Status__c = 'Closed'; insert reqTemp1; Contact conTemp1 = new Contact(); conTemp1.FirstName = 'Full'; conTemp1.LastName__c = 'Name'; conTemp1.Nationality__c = 'India'; conTemp1.Preferred_time_to_call__c = 'Forenoon'; conTemp1.Country_Code__c = 'Afghanistan +93'; conTemp1.Email = 'test@test.com'; conTemp1.Phone = '9191919191'; conTemp1.LastName = conTemp1.LastName__c; ApexPages.StandardController sc = new ApexPages.StandardController(conTemp1); FormController ControllerObj = new FormController(sc); ControllerObj.inputTextErrorMessage = 'test'; System.assertEquals(ControllerObj.inputTextErrorMessage , 'test'); ControllerObj.inputTextErrorMessage2 = 'test'; System.assertEquals(ControllerObj.inputTextErrorMessage2 , 'test'); ControllerObj.inputTextErrorMessage3 = 'test'; System.assertEquals(ControllerObj.inputTextErrorMessage3 , 'test'); ControllerObj.inputTextErrorMessage4 = 'test'; System.assertEquals(ControllerObj.inputTextErrorMessage4 , 'test'); ControllerObj.inputTextErrorMessage5 = 'test'; System.assertEquals(ControllerObj.inputTextErrorMessage5 , 'test'); ControllerObj.inputTextErrorMessage6 = 'test'; System.assertEquals(ControllerObj.inputTextErrorMessage6 , 'test'); ControllerObj.inputTextErrorMessage7 = 'Forenoon'; System.assertEquals(ControllerObj.inputTextErrorMessage7 , 'Forenoon'); ControllerObj.FirstName = 'test'; System.assertEquals(ControllerObj.FirstName , 'test'); ControllerObj.LastName= 'test'; System.assertEquals(ControllerObj.LastName, 'test'); ControllerObj.Email= 'test@test.com'; System.assertEquals(ControllerObj.Email, 'test@test.com'); ControllerObj.Phone= '1111'; System.assertEquals(ControllerObj.Phone, '1111'); ControllerObj.submit(); pba__Request__c reqTemp2 = new pba__Request__c(); reqTemp2.pba__Contact__c = conTemp.Id; reqTemp2.Status__c = 'Active'; insert reqTemp2; Test.StopTest(); } }
Thanks,
Avinash
- Avinash Ravisankar 13
- January 12, 2017
- Like
- 0
unable to cover following lines in Test Class
Hi,
I have a main class with the following lines inside of it. I'm unable to cover these if blocks in my test class. Please help out.
Thanks,
Avinash
I have a main class with the following lines inside of it. I'm unable to cover these if blocks in my test class. Please help out.
if(con.FirstName == null) {inputTextErrorMessage='Please enter "First Name"'; } if(con.LastName__c == null) {inputTextErrorMessage2='Please enter "Last Name"'; } if(con.Country_Code__c == null || con.ContactPhone__c == null) {inputTextErrorMessage4='Please choose "Country Code" & enter "Mobile Number"'; } if(con.Email == null) {inputTextErrorMessage5='Please enter "Email"'; } if(con.Nationality__c == 'Nationality*') {inputTextErrorMessage6='Please choose "Nationality"'; } if(con.Preferred_Time_to_Call__c == 'Preferred time to Call* (GMT +4)') {inputTextErrorMessage7='Please choose "Preferred time to Call"'; return null;} con.LastName = con.LastName__c ; string conname = con.FirstName+' '+con.LastName__c; system.debug('conname====>'+conname ); integer flag =1; list<contact> conlist = [select name,email from contact ]; for(contact c:conlist){ if(c.name == conname && c.email == con.email){ pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = c.id; r.status__c = 'Pending'; try{ list<pba__Request__c> relist = [select id,pba__Contact__c,status__c, createddate from pba__Request__c]; for(pba__Request__c req:relist) { if(r.pba__Contact__c == req.pba__Contact__c) { if((req.status__c == 'Active' || req.status__c == 'Pending')&& (req.createddate.date().daysbetween(System.today()))<7) { pagereference pg = new pagereference('https://c.cs86.visual.force.com/apex/OmniyatErrMsg'); return pg; return null; } } } } catch(DMLException e) { return null; } insert r; flag++; } } system.debug('flag==='+flag); if(flag==1) { insert con; pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = con.id; r.status__c = 'Active'; insert r; } /*ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please verify the captcha'); ApexPages.addMessage(errorMsg); return null;*/ pagereference pg = new pagereference('http://omniyat-omniyat.cs86.force.com/thankyou'); return pg; }
Thanks,
Avinash
- Avinash Ravisankar 13
- January 11, 2017
- Like
- 0
Please help me write a Test Class
Hi,
Could someone please help me write a test class for this below code?. What I've written covers only 34% of the code.
Test Class
Could someone please help me write a test class for this below code?. What I've written covers only 34% of the code.
public class FormController { public FormController() { } public string email ; public Apexpages.StandardController controller; public Apexpages.StandardController control; public contact con {get;set;} public FormController (ApexPages.StandardController stdController) { this.con = (contact)stdController.getRecord(); this.controller = stdController; } public class ReCaptchaController { public ReCaptchaController() { } public contact cont {get;set;} public ReCaptchaController.ReCaptchaController(ApexPages.StandardController control){ this.cont = (contact)control.getRecord(); } public String FirstName{ get; set; } public String LastName{ get; set; } public String email{ get; set; } public String Phone{ get; set; } private String baseUrl = 'https://www.google.com/recaptcha/api/siteverify'; private String secret = '6LfeAxEUAAAAALR8nFYrEBlv8SVx8TpxujF4hqqk'; public String sitekey { get{return '6LfeAxEUAAAAABhd_5yXn6X6nq355jbF0nvtEoQD';} } public String response { get { return ApexPages.currentPage().getParameters().get('g-recaptcha-response'); } } public PageReference doVerify () { String responseBody = makeRequest(baseUrl, 'secret=' + secret + '&response='+ response ); String success = getValueFromJson(responseBody, 'success'); if(success.equalsIgnoreCase('true')){ Contact con = new COntact( LastName = LastName , FirstName= FirstName, email=email); try{ insert con; pagereference p = new pagereference('https://cs86.salesforce.com/003/o'+con.id); return p; } Catch(exception e){ ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Unexpected error while creating contact'); ApexPages.addMessage(errorMsg); return null; } }else{ ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please verify the captcha'); ApexPages.addMessage(errorMsg); return null; } } private String makeRequest(string url, string body) { HttpResponse response = null; HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('POST'); req.setBody (body); try { Http http = new Http(); response = http.send(req); return response.getBody(); } catch(System.Exception e) { System.debug('ERROR: ' + e); } return '{"success":false}'; } public string getValueFromJson ( String strJson, String field ){ JSONParser parser = JSON.createParser(strJson); while (parser.nextToken() != null) { if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)) { if(parser.getText() == field){ // Get the value. parser.nextToken(); return parser.getText(); } } } return null; } } public pagereference submit(){ try { System.debug('Entered into save'); if(con.FirstName == null || con.LastName == null || con.Nationality__c == 'Nationality*' || con.Email == null || con.Country_Code__c == 'Code*' || con.Preferred_Time_to_Call__c == 'Preferred time to Call*') { ApexPages.addMessage(new Apexpages.Message(ApexPages.severity.error,'Please fill all mandatory fields.')); return null; } } catch(DMLException e) { return null; } string conname = con.FirstName+' '+con.LastName; system.debug('conname====>'+conname ); integer flag =1; list<contact> conlist = [select name,email from contact ]; for(contact c:conlist){ if(c.name == conname && c.email == con.email){ pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = c.id; r.status__c = 'Pending'; try{ list<pba__Request__c> relist = [select id,pba__Contact__c,status__c, createddate from pba__Request__c]; for(pba__Request__c req:relist) { if(r.pba__Contact__c == req.pba__Contact__c) { if((req.status__c == 'Active' || req.status__c == 'Pending')&& (req.createddate.date().daysbetween(System.today()))<7) { pagereference pg = new pagereference('https://c.cs86.visual.force.com/apex/OmniyatErrMsg'); return pg; return null; } } } } catch(DMLException e) { return null; } insert r; flag++; } } system.debug('flag==='+flag); if(flag==1) { insert con; pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = con.id; r.status__c = 'Active'; insert r; } /*ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please verify the captcha'); ApexPages.addMessage(errorMsg); return null;*/ pagereference pg = new pagereference('http://omniyat-omniyat.cs86.force.com/thankyou'); return pg; } }
Test Class
@isTest public class FormController_Test{ public static testmethod void FormController_Test1() { Test.StartTest(); PageReference pageRef = new pagereference('https://cs86.visual.force.com/apex/OmniyatErrMsg'); Test.setCurrentPage(pageRef); PageReference pageRef1 = new pagereference('http://omniyat-omniyat.cs86.force.com/thankyou'); Test.setCurrentPage(pageRef1); Contact conTemp = new Contact(); conTemp.FirstName = 'Full'; conTemp.LastName = 'Name'; conTemp.Nationality__c = 'India'; conTemp.Preferred_time_to_call__c = 'Forenoon'; conTemp.Country_Code__c = 'Afghanistan +93'; conTemp.Email = 'test@test.com'; conTemp.Phone = '9191919191'; FormController contrl = new FormController(); contrl.Con = conTemp; contrl.submit(); pba__Request__c reqTemp1 = new pba__Request__c(); reqTemp1.pba__Contact__c = conTemp.Id; reqTemp1.Status__c = 'Closed'; insert reqTemp1; Contact conTemp1 = new Contact(); conTemp1.FirstName = 'Full'; conTemp1.LastName = 'Name'; conTemp1.Nationality__c = 'India'; conTemp1.Preferred_time_to_call__c = 'Forenoon'; conTemp1.Country_Code__c = 'Afghanistan +93'; conTemp1.Email = 'test@test.com'; conTemp1.Phone = '9191919191'; //FormController contr2 = new FormController(); //contr2.Con = conTemp1; //contr2.submit(); ApexPages.StandardController sc = new ApexPages.StandardController(conTemp1); FormController ControllerObj = new FormController(sc); ControllerObj.submit(); pba__Request__c reqTemp2 = new pba__Request__c(); reqTemp2.pba__Contact__c = conTemp.Id; reqTemp2.Status__c = 'Active'; insert reqTemp2; Test.StopTest(); } }
- Avinash Ravisankar 13
- January 11, 2017
- Like
- 0
Need help writing a test class for controller with Captcha
Hi All,
Could someone please help me write a test class for this controller? I'm only able to achieve 34% coverage with what I have so far.
TIA!
Apex Class
Could someone please help me write a test class for this controller? I'm only able to achieve 34% coverage with what I have so far.
TIA!
Apex Class
public class FormController { public FormController() { } public string email ; public Apexpages.StandardController controller; public Apexpages.StandardController control; public contact con {get;set;} public FormController (ApexPages.StandardController stdController) { this.con = (contact)stdController.getRecord(); this.controller = stdController; } public class ReCaptchaController { public ReCaptchaController() { } public contact cont {get;set;} public ReCaptchaController.ReCaptchaController(ApexPages.StandardController control){ this.cont = (contact)control.getRecord(); } public String FirstName{ get; set; } public String LastName{ get; set; } public String email{ get; set; } public String Phone{ get; set; } private String baseUrl = 'https://www.google.com/recaptcha/api/siteverify'; private String secret = '6LfeAxEUAAAAALR8nFYrEBlv8SVx8TpxujF4hqqk'; public String sitekey { get{return '6LfeAxEUAAAAABhd_5yXn6X6nq355jbF0nvtEoQD';} } public String response { get { return ApexPages.currentPage().getParameters().get('g-recaptcha-response'); } } public PageReference doVerify () { String responseBody = makeRequest(baseUrl, 'secret=' + secret + '&response='+ response ); String success = getValueFromJson(responseBody, 'success'); if(success.equalsIgnoreCase('true')){ Contact con = new COntact( LastName = LastName , FirstName= FirstName, email=email); try{ insert con; pagereference p = new pagereference('https://cs86.salesforce.com/003/o'+con.id); return p; } Catch(exception e){ ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Unexpected error while creating contact'); ApexPages.addMessage(errorMsg); return null; } }else{ ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please verify the captcha'); ApexPages.addMessage(errorMsg); return null; } } private String makeRequest(string url, string body) { HttpResponse response = null; HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('POST'); req.setBody (body); try { Http http = new Http(); response = http.send(req); return response.getBody(); } catch(System.Exception e) { System.debug('ERROR: ' + e); } return '{"success":false}'; } public string getValueFromJson ( String strJson, String field ){ JSONParser parser = JSON.createParser(strJson); while (parser.nextToken() != null) { if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)) { if(parser.getText() == field){ // Get the value. parser.nextToken(); return parser.getText(); } } } return null; } } public pagereference submit(){ try { System.debug('Entered into save'); if(con.FirstName == null || con.LastName == null || con.Nationality__c == 'Nationality*' || con.Email == null || con.Country_Code__c == 'Code*' || con.Preferred_Time_to_Call__c == 'Preferred time to Call*') { ApexPages.addMessage(new Apexpages.Message(ApexPages.severity.error,'Please fill all mandatory fields.')); return null; } } catch(DMLException e) { return null; } string conname = con.FirstName+' '+con.LastName; system.debug('conname====>'+conname ); integer flag =1; list<contact> conlist = [select name,email from contact ]; for(contact c:conlist){ if(c.name == conname && c.email == con.email){ pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = c.id; r.status__c = 'Pending'; try{ list<pba__Request__c> relist = [select id,pba__Contact__c,status__c, createddate from pba__Request__c]; for(pba__Request__c req:relist) { if(r.pba__Contact__c == req.pba__Contact__c) { if((req.status__c == 'Active' || req.status__c == 'Pending')&& (req.createddate.date().daysbetween(System.today()))<7) { pagereference pg = new pagereference('https://c.cs86.visual.force.com/apex/OmniyatErrMsg'); return pg; return null; } } } } catch(DMLException e) { return null; } insert r; flag++; } } system.debug('flag==='+flag); if(flag==1) { insert con; pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = con.id; r.status__c = 'Active'; insert r; } pagereference pg = new pagereference('http://omniyat-omniyat.cs86.force.com/thankyou'); return pg; } }Test Class
@isTest public class FormController_Test{ public static testmethod void FormController_Test1() { Test.StartTest(); PageReference pageRef = new pagereference('https://cs86.visual.force.com/apex/OmniyatErrMsg'); Test.setCurrentPage(pageRef); PageReference pageRef1 = new pagereference('http://omniyat-omniyat.cs86.force.com/thankyou'); Test.setCurrentPage(pageRef1); Contact conTemp = new Contact(); conTemp.FirstName = 'Full'; conTemp.LastName = 'Name'; conTemp.Nationality__c = 'India'; conTemp.Preferred_time_to_call__c = 'Forenoon'; conTemp.Country_Code__c = 'Afghanistan +93'; conTemp.Email = 'test@test.com'; conTemp.Phone = '9191919191'; FormController contrl = new FormController(); contrl.Con = conTemp; contrl.submit(); pba__Request__c reqTemp1 = new pba__Request__c(); reqTemp1.pba__Contact__c = conTemp.Id; reqTemp1.Status__c = 'Closed'; insert reqTemp1; Contact conTemp1 = new Contact(); conTemp1.FirstName = 'Full'; conTemp1.LastName = 'Name'; conTemp1.Nationality__c = 'India'; conTemp1.Preferred_time_to_call__c = 'Forenoon'; conTemp1.Country_Code__c = 'Afghanistan +93'; conTemp1.Email = 'test@test.com'; conTemp1.Phone = '9191919191'; //FormController contr2 = new FormController(); //contr2.Con = conTemp1; //contr2.submit(); ApexPages.StandardController sc = new ApexPages.StandardController(conTemp1); FormController ControllerObj = new FormController(sc); ControllerObj.submit(); pba__Request__c reqTemp2 = new pba__Request__c(); reqTemp2.pba__Contact__c = conTemp.Id; reqTemp2.Status__c = 'Active'; insert reqTemp2; Test.StopTest(); } }
- Avinash Ravisankar 13
- January 10, 2017
- Like
- 0
Trigger does not display error msg on screen
I have a before insert trigger on an object called Request that has to throw an error when a condition gets satisified. The trigger works, but it does not display the error on the vf page itself. It goes into the application to display the same. Please help out.
Apex Trigger trigger ReqValidation on pba__Request__c (before insert) { list<pba__Request__c> relist = [select id,pba__Contact__c,status__c, createddate from pba__Request__c]; for(pba__Request__c r :trigger.new){ for(pba__Request__c req:relist){ if(r.pba__Contact__c == req.pba__Contact__c){ if((req.status__c == 'Active' || req.status__c == 'Pending')&& (req.createddate.date().daysbetween(System.today()))<7) { r.adderror('Close the Active or Pending request'); } } } } }
VF Page <apex:page standardController="contact" extensions="FormController" showHeader="false" sidebar="false" > <apex:form style="background-color:black"> <apex:pageMessages /> <body> <center> <apex:panelGrid columns="1" > <apex:inputfield styleclass="in" value="{!con.FirstName}" html-placeholder=" First Name∗" style="width: 360px; height: 40px" /> <apex:inputField styleclass="in" value="{!con.LastName}" html-placeholder=" Last Name∗" style="width: 360px; height: 40px" /> </apex:panelGrid> <apex:panelGrid columns="2" > <apex:inputField styleclass="in" value="{!con.Country_Code__c}" style="width: 80px; height: 40px" /> <apex:inputField styleclass="in" value="{!con.Phone}" html-placeholder=" Mobile Number∗" style="width: 280px; height: 40px" /> </apex:panelGrid> <apex:panelGrid columns="1" > <apex:inputField styleclass="in" value="{!con.email}" required="true" html-placeholder=" Email Address∗" style="width: 360px; height: 40px" /> <apex:inputField styleclass="in" value="{!con.Nationality__c}" html-placeholder=" Nationality∗" style="width: 360px; height: 40px"/> <apex:inputField styleclass="in" value="{!con.Preferred_Time_to_Call__c}" style="width: 360px; height: 40px"/> <div class="g-recaptcha" data-sitekey='6LfeAxEUAAAAABhd_5yXn6X6nq355jbF0nvtEoQD'></div> <script src='https://www.google.com/recaptcha/api.js'></script> <br/> </apex:panelGrid> <apex:panelGrid columns="3"> <apex:outputLabel value="AGENT" styleClass="in" style="font-size:12px; margin-left: 1cm; font-family:Verdana"/> <apex:selectradio value="{!con.Agent__c}" > <apex:selectOption itemValue="Yes" itemLabel="Yes"> </apex:selectOption> <apex:selectOption itemValue="Yes" itemLabel="No"> </apex:selectOption> </apex:selectradio></apex:panelGrid> <apex:commandButton style=" margin-right: 7cm; background:#c00;width:75px;height:30px;color:white;font-size:12pt;" action="{!submit}" value="Submit" /></center> <p></p><br/><br/> <script src='https://www.google.com/recaptcha/api.js'></script> </body> </apex:form> <script src='https://www.google.com/recaptcha/api.js'></script> <style> h1 { color:white; font-size:18pt; } p { color:black; font-size:18pt; } .in { font-size:10pt; color:white; width:82%; background-color: #000000; } label { display: block; width: 150px; color:#ffffff; font-family:"Verdana" } input[type=checkbox] { border: 0px; width: 2%; height: 2em; background-color: #ffa500; } </style> </apex:page>
Apex Class public class FormController { public string email ; //public string Nationality__c; //public string Preferred_Time_to_Call__c; public Apexpages.StandardController controller; public Apexpages.StandardController control; public contact con {get;set;} public FormController (ApexPages.StandardController stdController) { this.con = (contact)stdController.getRecord(); this.controller = stdController; } public class ReCaptchaController { public contact cont {get;set;} public ReCaptchaController.ReCaptchaController(ApexPages.StandardController control){ this.cont = (contact)control.getRecord(); // this.stdController= control; } public String FirstName{ get; set; } public String LastName{ get; set; } public String email{ get; set; } public String Phone{ get; set; } // public string Nationality__c{ get; set; } // public String Preferred_Time_to_Call__c{ get; set; } private String baseUrl = 'https://www.google.com/recaptcha/api/siteverify'; private String secret = '6LfeAxEUAAAAALR8nFYrEBlv8SVx8TpxujF4hqqk'; public String sitekey { get{return '6LfeAxEUAAAAABhd_5yXn6X6nq355jbF0nvtEoQD';} } public String response { get { return ApexPages.currentPage().getParameters().get('g-recaptcha-response'); } } // this method is called when the button is clicked public PageReference doVerify () { String responseBody = makeRequest(baseUrl, 'secret=' + secret + '&response='+ response ); String success = getValueFromJson(responseBody, 'success'); if(success.equalsIgnoreCase('true')){ Contact con = new COntact( LastName = LastName , FirstName= FirstName, email=email); try{ insert con; pagereference p = new pagereference('https://cs86.salesforce.com/003/o'+con.id); return p; } Catch(exception e){ ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Unexpected error while creating contact'); ApexPages.addMessage(errorMsg); return null; } }else{ ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please verify the captcha'); ApexPages.addMessage(errorMsg); return null; } } /** * Make request to verify captcha * @return response message from google */ private String makeRequest(string url, string body) { HttpResponse response = null; HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('POST'); req.setBody (body); try { Http http = new Http(); response = http.send(req); return response.getBody(); } catch(System.Exception e) { System.debug('ERROR: ' + e); } return '{"success":false}'; } /** * to get value of the given json string * @params * - strJson json string given * - field json key to get the value from * @return string value */ public string getValueFromJson ( String strJson, String field ){ JSONParser parser = JSON.createParser(strJson); while (parser.nextToken() != null) { if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)) { if(parser.getText() == field){ // Get the value. parser.nextToken(); return parser.getText(); } } } return null; } } // ================================================= // public pagereference submit(){ try { System.debug('Entered into save'); if(con.FirstName == null || con.LastName == null || con.Nationality__c == 'Nationality*' || con.Email == null || con.Country_Code__c == 'Code*' ||con.Phone == null || con.Preferred_Time_to_Call__c == 'Preferred time to Call*') { ApexPages.addMessage(new Apexpages.Message(ApexPages.severity.error,'Please fill all mandatory fields.')); return null; } } catch(DMLException e) { return null; } string conname = con.FirstName+' '+con.LastName; system.debug('conname====>'+conname ); integer flag =1; list<contact> conlist = [select name,email from contact ]; for(contact c:conlist){ if(c.name == conname && c.email == con.email){ pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = c.id; r.status__c = 'Pending'; insert r; flag++; } } system.debug('flag==='+flag); if(flag==1) { insert con; pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = con.id; r.status__c = 'Pending'; insert r; } // ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please verify the captcha'); // ApexPages.addMessage(errorMsg); //return null; pagereference pg = new pagereference('http://omniyat-omniyat.cs86.force.com/thankyou'); //setredirect(true); return pg; //return pg; } }
- Avinash Ravisankar 13
- January 09, 2017
- Like
- 0
Referencing multipicklist in Apex Trigger
Hi All,
I have a trigger to assign Contacts by criteria-based-Round Robin based on Project and Language parameters. The below code query was returning values as long as the Projects field was a picklist, now after I've converted it into a multipicklist, it doesn't seem to return any values. Please asist
I have a trigger to assign Contacts by criteria-based-Round Robin based on Project and Language parameters. The below code query was returning values as long as the Projects field was a picklist, now after I've converted it into a multipicklist, it doesn't seem to return any values. Please asist
trigger AssignSalesmanager on contact(before insert , after update) { String currentuser = [Select alias From User Where Id = :UserInfo.getUserId()].alias; system.debug(currentuser); if(currentuser == 'guest' || currentuser == 'oadmi') { if(Trigger.isBefore) { if(Trigger.IsInsert) { Map<String,List<round_robin__c>> mapOfLangUsers = new Map<String,List<round_robin__c>>(); Map<String,List<round_robin__c>> mapOfProjUsers = new Map<String,List<round_robin__c>>(); map<string,list<contact>> MapoflangandContacts = new map<string,list<contact>>(); map<string,list<contact>> MapofprojandContacts = new map<string,list<contact>>(); Set<String> projectValues = new Set<String>(); String projValues; Set<String> langValues = new Set<String>(); List<Contact> allContacts = new List<contact>(); Boolean hasModifiedUser = false; for(contact eachcontact: trigger.new){ if(!String.isBlank(eachcontact.Language__c) && !String.isBlank(eachcontact.Projects__c)) { allContacts.add(eachcontact); langValues.add(eachcontact.language__c); projectValues.add(eachcontact.projects__c); projvalues= String.valueOf(projectValues); } } if(MapoflangandContacts.size() > 0 && MapoflangandContacts!= null) { for(string strlang : MapoflangandContacts.keyset()){ integer i=0; for(Contact objContact : MapoflangandContacts.get(strlang)){ objContact.ownerid = mapOfLangUsers.get(objContact.Language__c)[i].Round_Robin_User__c; mapOfLangUsers.get(objContact.Language__c)[i].Count__c = mapOfLangUsers.get(objContact.Language__c)[i].Count__c+1; i++; if(i==mapOfLangUsers.get(objContact.Language__c).size()) i=0; } } list<round_robin__c> lstrb = new list<round_robin__c>(); for(list<round_robin__c> lstuser : mapOfLangUsers.values()){ lstrb.addall(lstuser); } update lstrb; } if(MapofprojandContacts.size() > 0 && MapofprojandContacts!= null) { for(string strProject : MapofprojandContacts.keyset()){ integer i=0; for(Contact objContact : MapofprojandContacts.get(strProject)){ objContact.ownerid = mapOfProjUsers.get(objContact.Projects__c)[i].Round_Robin_User__c; mapOfProjUsers.get(objContact.Projects__c)[i].Count__c = mapOfProjUsers.get(objContact.Projects__c)[i].Count__c+1; i++; if(i==mapOfProjUsers.get(objContact.Projects__c).size()) i=0; } } list<round_robin__c> lstrb = new list<round_robin__c>(); for(list<round_robin__c> lstuser : mapOfProjUsers.values()){ lstrb.addall(lstuser); } update lstrb; } if(allContacts.size() > 0 && allContacts!=null) { Integer recordCount = [select count() from contact]; system.debug('recordCount='+recordCount); Integer rr = [select Count() from round_robin__c where Is_Active__c = TRUE AND Language__c IN:langValues AND Projects__c INCLUDES (:projvalues) ]; system.debug('rr='+rr); if(rr!=0) { Integer index = Math.mod(recordCount+1,rr); list <round_robin__c> lstRoundSpecificUsers = [select id,name,Count__c,Round_Robin_User__c,Language__c,Projects__c from round_robin__c where Is_Active__c = TRUE AND Language__c IN:langValues AND Projects__c INCLUDES (:projvalues) ]; system.debug(lstRoundSpecificUsers ); Integer i; IF(i==null) {i=0;} for(contact eachContact : trigger.new) { system.debug('index='+index); eachContact.ownerId = lstRoundSpecificUsers[index].Round_Robin_User__c; } } } } } } if(trigger.isUpdate) { System.debug('----->Entered'); Map<Id,Id> mapOfContact = new Map<Id,Id>(); for(Contact con: trigger.new) { if(con.OwnerId != trigger.oldmap.get(con.id).ownerId) { System.debug('----->Entered111'); mapOfContact.put(con.Id,con.OwnerId); } } list<pba__Request__c> lstRequest = [select id,name,Contact_Owner__c,pba__Contact__c from pba__Request__c where pba__Contact__c IN:mapOfContact.keySet() ]; if(lstRequest.size() > 0) { for(pba__Request__c eachReq : lstRequest) { eachReq.OwnerId = mapOfContact.get(eachReq.pba__Contact__c); } } update lstRequest; } }
The system.debug statement for vairable rr keeps returning as 0 if I compare it with a set of values. It returns rows if I hardcode the values, which I don't want to. I want this to be dynamic.
How do i work around this.
Thanks,
Avinash
- Avinash Ravisankar 13
- April 06, 2017
- Like
- 2
unable to cover following lines in Test Class
Hi,
I have a main class with the following lines inside of it. I'm unable to cover these if blocks in my test class. Please help out.
Thanks,
Avinash
I have a main class with the following lines inside of it. I'm unable to cover these if blocks in my test class. Please help out.
if(con.FirstName == null) {inputTextErrorMessage='Please enter "First Name"'; } if(con.LastName__c == null) {inputTextErrorMessage2='Please enter "Last Name"'; } if(con.Country_Code__c == null || con.ContactPhone__c == null) {inputTextErrorMessage4='Please choose "Country Code" & enter "Mobile Number"'; } if(con.Email == null) {inputTextErrorMessage5='Please enter "Email"'; } if(con.Nationality__c == 'Nationality*') {inputTextErrorMessage6='Please choose "Nationality"'; } if(con.Preferred_Time_to_Call__c == 'Preferred time to Call* (GMT +4)') {inputTextErrorMessage7='Please choose "Preferred time to Call"'; return null;} con.LastName = con.LastName__c ; string conname = con.FirstName+' '+con.LastName__c; system.debug('conname====>'+conname ); integer flag =1; list<contact> conlist = [select name,email from contact ]; for(contact c:conlist){ if(c.name == conname && c.email == con.email){ pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = c.id; r.status__c = 'Pending'; try{ list<pba__Request__c> relist = [select id,pba__Contact__c,status__c, createddate from pba__Request__c]; for(pba__Request__c req:relist) { if(r.pba__Contact__c == req.pba__Contact__c) { if((req.status__c == 'Active' || req.status__c == 'Pending')&& (req.createddate.date().daysbetween(System.today()))<7) { pagereference pg = new pagereference('https://c.cs86.visual.force.com/apex/OmniyatErrMsg'); return pg; return null; } } } } catch(DMLException e) { return null; } insert r; flag++; } } system.debug('flag==='+flag); if(flag==1) { insert con; pba__Request__c r = new pba__Request__c(); r.pba__Contact__c = con.id; r.status__c = 'Active'; insert r; } /*ApexPages.Message errorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please verify the captcha'); ApexPages.addMessage(errorMsg); return null;*/ pagereference pg = new pagereference('http://omniyat-omniyat.cs86.force.com/thankyou'); return pg; }
Thanks,
Avinash
- Avinash Ravisankar 13
- January 11, 2017
- Like
- 0