-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
23Questions
-
14Replies
Need help in test class for Messaging.Singleemailmessage and meta data
Hi All,
I have written a apex class to send email. I am new to test classes. I want to write test class for this. Please suggest how to cover my apex class.
This is my code.
Thanks in Advance
Please help me
I have written a apex class to send email. I am new to test classes. I want to write test class for this. Please suggest how to cover my apex class.
This is my code.
public class UtilityCont{ public static List<cotacts1__c> PSEContacts = new List<cotacts1__c>(); public static void EmailtoSRRTTeam(Instal_Prod__c IP) { try{ User usr = [select Id, username from User where Id = :UserInfo.getUserId()]; Account acc = [Select ShippingCountry from Account where id =: IP.Company__c]; PSEContacts = [Select Id,Email__c from cotacts1__c where Countries_in_Cluster__c =: acc.ShippingCountry]; EmailTemplate templateId = [Select id from EmailTemplate where name = :System.Label.SRRTEmailTemp]; if(usr!=null) { Messaging.Singleemailmessage mail = new Messaging.Singleemailmessage(); list<String> toEmailIDs = new list<String>(); Integer i=0; for (cotacts1__c singleCCEmail: PSEContacts) { toEmailIDs.add(singleCCEmail.Email__c); mail.setTargetObjectId(userinfo.getUserId()); mail.setToAddresses(toEmailIDs); mail.setTreatTargetObjectAsRecipient(false); mail.setTemplateID(templateId.Id); mail.setWhatId(IP.Id); mail.setSaveAsActivity(false); } Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } catch(Exception ex) { } } public static String getUserContactNumber(){ ContactNumber__mdt record; try { String userLocale = UserInfo.getLocale(); String countryCode= userLocale.substring(3,5); record= [SELECT MasterLabel,DeveloperName,ContactNumber__c FROM ContactNumber__mdt where DeveloperName=:countryCode]; } catch(Exception ex) { } return record.ContactNumber__c; } }
Thanks in Advance
Please help me
- Harsha Shri
- April 11, 2018
- Like
- 0
Need help in User object Test class
Hi All,
I have written apex class related to user object.
I am very new to test classes. Can someone please help me with this. Following are my classes
Please help me in wrtting test class for this.
Thanks in Advance
I have written apex class related to user object.
I am very new to test classes. Can someone please help me with this. Following are my classes
public class UserController { public static List <UserWrapper> fetchUser(String searchKeyWord,String sortField,Boolean isAsc) { profile p =[Select Name from Profile where Id =: userinfo.getProfileid()]; List<UserWrapper> UserRec = new List<UserWrapper>(); String searchKey = '%'+searchKeyWord + '%'; List < User > returnList = new List < User > (); List < User > lstOfUser=new List < User > (); List<String> profiles= new List<String>(); String sSoql=''; String emailRegex = '^[a-zA-Z0-9._|\\\\%#~`=?&/$^*!}{+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$'; Pattern MyPattern = Pattern.compile(emailRegex); Matcher MyMatcher = MyPattern.matcher(searchKeyWord); String pn='Label3'; profiles= pn.split(','); if(p.Name.equals('Customer Portal Manager')){ List<Contact> con = [select ID from Contact where AccountID in(select id from Account)]; if (!MyMatcher.matches()){ sSoql='select Name, Email from User where Name LIKE \''+ searchKey+'\' and IsActive = true and Profile.Name in :profiles and Id != \''+Userinfo.getUserId()+'\' and ContactID in:con'; }else{ sSoql='select Name, Email from User where Email LIKE \''+ searchKey+'\' and IsActive = true and Profile.Name in :profiles and Id != \''+Userinfo.getUserId()+'\' and ContactID in:con'; } } else{ if (!MyMatcher.matches()){ sSoql='select Name, Email from User where Name LIKE \''+ searchKey+'\' and IsActive = true and Profile.Name in :profiles and Id != \''+Userinfo.getUserId()+'\''; } else{ sSoql='select Name, Email from User where Email LIKE \''+ searchKey+'\' and IsActive = true and Profile.Name in :profiles and Id != \''+Userinfo.getUserId()+'\''; } } if (sortField != '' && sortField != Null) { sSoql += ' order by ' + sortField; if(isAsc!=Null) { if (isAsc) { sSoql += ' asc NULLS LAST'; } else { sSoql += ' desc'; } } } try { lstOfUser= Database.query(sSoql); }Catch(Exception e) { System.debug('exception in user'+e); } for (User acc: lstOfUser) { UserWrapper user_rec = new UserWrapper(); user_rec.UserEmail=acc.Email; user_rec.Name=acc.Name; user_rec.userID=acc.Id; user_rec.isSelected=true; UserRec.add(user_rec); } return UserRec; } public static String getUserName(String UserID){ return [select name from User where ID=:UserID].Name; } public static List<UserWrapper> performAction(String userRecords,List<UserWrapper> selectedUsers){ List<UserWrapper> storeresult = new List<userWrapper>(); if(!string.isBlank(userRecords)) { List<UserWrapper> lstUserRecords = (List<UserWrapper>) System.JSON.deserialize(userRecords,List<UserWrapper>.class); for(UserWrapper objPositionRecords:lstUserRecords) { if(objPositionRecords.isSelected) { storeresult.add(objPositionRecords); } } selectedUsers.addAll(storeresult); } return selectedUsers; } public static List<UserWrapper> removeUsers(String removeUsers){ List<UserWrapper> remove_Users = new List<userWrapper>(); if(!string.isBlank(removeUsers)) { List<UserWrapper> rmvUserRecords = (List<UserWrapper>) System.JSON.deserialize(removeUsers,List<UserWrapper>.class); for(UserWrapper objPositionRecords:rmvUserRecords) { if(!objPositionRecords.isSelected) { remove_Users.add(objPositionRecords); } } } return remove_Users; } }
public class UserWrapper { public boolean isSelected; public String UserEmail; public String Name; public String userID; public UserWrapper() { isSelected = false; UserEmail=''; Name = ''; } }
Please help me in wrtting test class for this.
Thanks in Advance
- Harsha Shri
- April 09, 2018
- Like
- 0
Redirect issue in VF Page commandbutton
HI All,
I am having redirect issue in VF page. When I am using reRender and rendered together in commanad button I am getting this issue. If I am not using rerender in command button, It is redirecting to the path what I mentioned in pagereference methond.
This is my code.
Please help me how to resolve this issue.
Thanks in Advance
I am having redirect issue in VF page. When I am using reRender and rendered together in commanad button I am getting this issue. If I am not using rerender in command button, It is redirecting to the path what I mentioned in pagereference methond.
This is my code.
public class SaveRecords{ public PageReference saveToCollege() { Boolean saved = false; saved = Class2.saveCollegeData(WrapperData.result,collegeId); if(saved) { PageReference pg=new PageReference('/'+collegeId ); return pg; } } } <apex:page standardcontroller="College__c" controller="SaveRecords"> <apex:form> <apex:pageBlock id="mySelectedPB1"> some code </apex:pageBlock> <apex:commandButton action="{!saveToCollege}" value="Link to College" rerender="mySelectedPB1" rendered="{!if(WrapperData.result != null,true,false)}"/> </apex:form> </apex:page>
Please help me how to resolve this issue.
Thanks in Advance
- Harsha Shri
- March 28, 2018
- Like
- 0
Rerender issue in Visualforce page commandbutton
Hi All,
I am having rerender issue in VF page.
Problem:
when I am putting reRender and rendred together in a commandbutton, when clicking on commandbutton it is not redirecting to the actual page what I mentioned on pagereference method.
This is my code
Apex class:
Please suggest me where it is going wrong
Thanks in Advance
I am having rerender issue in VF page.
Problem:
when I am putting reRender and rendred together in a commandbutton, when clicking on commandbutton it is not redirecting to the actual page what I mentioned on pagereference method.
This is my code
Apex class:
public class SaveRecords{ public PageReference saveToCollege() { Boolean saved = false; saved = Class2.saveCollegeData(WrapperData.result,collegeId); if(saved) { PageReference pg=new PageReference('/'+collegeId ); return pg; } } }VF Page code:
<apex:page> <apex:form> <apex:pageBlock id="mySelectedPB1"> some code </apex:pageBlock> <apex:commandButton action="{!linkToProject}" value="Link to Project" rerender="mySelectedPB1" rendered="{!if(WrapperData.result != null,true,false)}"/> </apex:form> </apex:page>
Please suggest me where it is going wrong
Thanks in Advance
- Harsha Shri
- March 27, 2018
- Like
- 0
Need help in test class for Integration
Hi All,
I am new to test classes. Can you please help me in test classes for my controller class.
public class class2
{
public List<Map<String,String>> getQueryResults(Map<String,String> QueryInfo)
{
List<Map<String,String>> listqueryRes = new List<Map<String,String>>();
String tableName=QueryInfo.get('TableName');
if(tableName.equals(Class3.TBLNAME))
{
listqueryRes = getOrder(QueryInfo);
}
}
private List<Map<String,String>> getOrder(Map<String,String> QueryInfo)
{
String operationName=null;
class4.IntegrationResp extRespData=null;
List<Map<String,String>> listOrder= new List<Map<String,String>>();
Map<String,String> maplistOrder=null;
operationName=class3.OP_ORDER_DETAILS;
extRespData = getExtRespData(operationName,mapQueryInfo);
class4.DetailsResponse getSalesOrdResp=(class4.DetailsResponse)extRespData;
List<class4.OUTPUT_DETAILS> OutputList=getSalesOrdResp.OUTPUT_DETAILS;
for(class4.ORDER_OUTPUT_DETAILS resp: OutputList)
{
maplistOrder=new Map<String,String>();
maplistOrder.put('F1',resp.F1);
maplistOrder.put('F2',resp.F2);
listOrder.add(maplistOrder);
}
return listOrder;
}
}
Please help me in test classes for the above two controller.
Thanks in Advance
I am new to test classes. Can you please help me in test classes for my controller class.
public class class1 { public List<Map<String,String>> queryhand(DataSource.QueryContext qc) { List<Map<String,String>> listC = new List<Map<String,String>>(); class2 dataQueryService= new class2(); Map<String,String> queryCont=new Map<String,String>(); queryCont = getContext(qc); listC = dataQueryService.getQueryResults(queryCont); return listC; } private Map<String,String> getContext(DataSource.QueryContext qc) { Map<String,String> contexMap = new Map<String,String>(); String SOQLObject = qc.tableSelection.columnsSelected.get(0).tableName; DataSource.Filter filter = qc.tableSelection.filter; contexMap.put('TableName',SOQLObject ); contexMap.put('ColumnName',filter.columnName); return contexMap; } }
public class class2
{
public List<Map<String,String>> getQueryResults(Map<String,String> QueryInfo)
{
List<Map<String,String>> listqueryRes = new List<Map<String,String>>();
String tableName=QueryInfo.get('TableName');
if(tableName.equals(Class3.TBLNAME))
{
listqueryRes = getOrder(QueryInfo);
}
}
private List<Map<String,String>> getOrder(Map<String,String> QueryInfo)
{
String operationName=null;
class4.IntegrationResp extRespData=null;
List<Map<String,String>> listOrder= new List<Map<String,String>>();
Map<String,String> maplistOrder=null;
operationName=class3.OP_ORDER_DETAILS;
extRespData = getExtRespData(operationName,mapQueryInfo);
class4.DetailsResponse getSalesOrdResp=(class4.DetailsResponse)extRespData;
List<class4.OUTPUT_DETAILS> OutputList=getSalesOrdResp.OUTPUT_DETAILS;
for(class4.ORDER_OUTPUT_DETAILS resp: OutputList)
{
maplistOrder=new Map<String,String>();
maplistOrder.put('F1',resp.F1);
maplistOrder.put('F2',resp.F2);
listOrder.add(maplistOrder);
}
return listOrder;
}
}
Please help me in test classes for the above two controller.
Thanks in Advance
- Harsha Shri
- February 27, 2018
- Like
- 0
Need help in test classes
Hi All,
I am new to test classes. Can you please help me in test classes for my controller class.
Please help me in test classes for the above two controller.
Thanks in Advance
I am new to test classes. Can you please help me in test classes for my controller class.
public class class1 { public List<Map<String,String>> queryhand(DataSource.QueryContext qc) { List<Map<String,String>> listC = new List<Map<String,String>>(); class2 dataQueryService= new class2(); Map<String,String> queryCont=new Map<String,String>(); queryCont = getContext(qc); listC = dataQueryService.getQueryResults(queryCont); return listC; } private Map<String,String> getContext(DataSource.QueryContext qc) { Map<String,String> contexMap = new Map<String,String>(); String SOQLObject = qc.tableSelection.columnsSelected.get(0).tableName; DataSource.Filter filter = qc.tableSelection.filter; contexMap.put('TableName',SOQLObject ); contexMap.put('ColumnName',filter.columnName); return contexMap; } }
public class class2 { public List<Map<String,String>> getQueryResults(Map<String,String> QueryInfo) { List<Map<String,String>> listqueryRes = new List<Map<String,String>>(); String tableName=QueryInfo.get('TableName'); if(tableName.equals(Class3.TBLNAME)) { listqueryRes = getOrder(QueryInfo); } } private List<Map<String,String>> getOrder(Map<String,String> QueryInfo) { String operationName=null; class4.IntegrationResp extRespData=null; List<Map<String,String>> listOrder= new List<Map<String,String>>(); Map<String,String> maplistOrder=null; operationName=class3.OP_ORDER_DETAILS; extRespData = getExtRespData(operationName,mapQueryInfo); class4.DetailsResponse getSalesOrdResp=(class4.DetailsResponse)extRespData; List<class4.OUTPUT_DETAILS> OutputList=getSalesOrdResp.OUTPUT_DETAILS; for(class4.ORDER_OUTPUT_DETAILS resp: OutputList) { maplistOrder=new Map<String,String>(); maplistOrder.put('F1',resp.F1); maplistOrder.put('F2',resp.F2); listOrder.add(maplistOrder); } return listOrder; } }
Please help me in test classes for the above two controller.
Thanks in Advance
- Harsha Shri
- February 26, 2018
- Like
- 0
Make Visualforce page as responsive design
Hi All,
I have developed a VF page by using standard controller. I have alignment issue. Please see below image.
If you see above image Account name and produ order number are not in same line.
I want to make all elements in the above visualforce page as responsive desing. even I minimize screen also, I dont want to distract the fields.
Please help me how to make this as responsive
Thanks in Advance
I have developed a VF page by using standard controller. I have alignment issue. Please see below image.
If you see above image Account name and produ order number are not in same line.
I want to make all elements in the above visualforce page as responsive desing. even I minimize screen also, I dont want to distract the fields.
Please help me how to make this as responsive
<apex:page standardController="Account" showHeader="true"> <apex:form > <apex:sectionHeader title="title1"/> <apex:pageBlock title="title2" tabStyle="account"> <apex:pageBlockSection title="PBS2" collapsible="false" id="myPbSec2" columns="2"> <apex:outputField value="{!account.name}"/> <apex:outputField value="{!account.description}"/> <apex:outputPanel > <span style="margin-left:102px"><apex:outputLabel value="Produ Order Number"/><span style="margin-left:18px"><apex:inputtext label="" id="ST"/> <apex:commandButton value="Button1!" /></span></span> </apex:outputPanel> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Thanks in Advance
- Harsha Shri
- February 21, 2018
- Like
- 0
VF Page alignment Issue - Need help
Hi All,
I have developed a VF page by using standard controller. I have alignment issue. Please see below image.
If you see above image Account name and produ order number are not in same line. If I use showheader="false" then there is no alignment issue.
I want it as responsive design that even if i expand or minimize screen I want both fields shoud be aligned.
Please help me in this
Thanks in Advance
I have developed a VF page by using standard controller. I have alignment issue. Please see below image.
If you see above image Account name and produ order number are not in same line. If I use showheader="false" then there is no alignment issue.
I want it as responsive design that even if i expand or minimize screen I want both fields shoud be aligned.
<apex:page standardController="Account" showHeader="true"> <apex:form > <apex:sectionHeader title="title1"/> <apex:pageBlock title="title2" tabStyle="account"> <apex:pageBlockSection title="PBS2" collapsible="false" id="myPbSec2" columns="2"> <apex:outputField value="{!account.name}"/> <apex:outputField value="{!account.description}"/> <apex:outputPanel > <span style="margin-left:102px"><apex:outputLabel value="Produ Order Number"/><span style="margin-left:18px"><apex:inputtext label="" id="ST"/> <apex:commandButton value="Button1!" /></span></span> </apex:outputPanel> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Please help me in this
Thanks in Advance
- Harsha Shri
- February 20, 2018
- Like
- 0
Help in Select all functionality for check box
Hi All,
I have written code for check box select all functionality. It is working, but is having one issue please help me. I am sharing my code.
Here if I check main check box, it is selecting all checkboxes under it. If I am unselecting all, it is unselecting all.
But issue is, If I unselect any check box from result check box main checkbox is not getting unselected. the below image is reference. 1st check is main check box. when I deselect 3rd checkbox the 1st one should uncheck. right now it is not happening. Please help me
Thanks in Advance
I have written code for check box select all functionality. It is working, but is having one issue please help me. I am sharing my code.
public class Mainclass{ public WrapperClass viewWrapper {get;set;} public void SelectAll(){ if(viewwrapper.check){ for(WrapperClass.SearchItem s : viewWrapper.resultList) { s.checked = true; } } else { for(WrapperClass.SearchItem s : viewWrapper.resultList) { s.checked = false; } } } }
public class WrapperClass { public Boolean check{get;set;} public List<SearchItem> resultList{ get; set; } public class SearchItem { public Boolean checked{ get; set; } \\ some other fields are also there } }
<apex:page> <apex:form> <apex:coloumn> <apex:facet> <apex:inputCheckbox style="margin:2px;" value="{!viewWrapper.check}"> <apex:actionSupport action="{!selectAll}" event="onclick" reRender="resultsBlock"/></apex:inputCheckbox> </apex:facet> </apex:coloumn> </apex:form> </apex:page>
Here if I check main check box, it is selecting all checkboxes under it. If I am unselecting all, it is unselecting all.
But issue is, If I unselect any check box from result check box main checkbox is not getting unselected. the below image is reference. 1st check is main check box. when I deselect 3rd checkbox the 1st one should uncheck. right now it is not happening. Please help me
Thanks in Advance
- Harsha Shri
- February 14, 2018
- Like
- 0
One child record should have one Parent
Hi All,
I have two object one is Bank__c and another one is customer__c. Customer data I am getting from external system (SAP). From SAP I will select the customers and then I will select the bank to map. All customers will showing everytime. If Customer1 is linked to Bank1 then Customer1 sholud not be allowed to map to another Bank. How can I do this?
Please help me.
Thanks in Advance
I have two object one is Bank__c and another one is customer__c. Customer data I am getting from external system (SAP). From SAP I will select the customers and then I will select the bank to map. All customers will showing everytime. If Customer1 is linked to Bank1 then Customer1 sholud not be allowed to map to another Bank. How can I do this?
Please help me.
Thanks in Advance
- Harsha Shri
- February 13, 2018
- Like
- 0
DML exception on VF Page
Hi All,
I have a button on visualforce page to save records into custom object. I have created a uniqie text field and workflow to prevent duplicate values.
but, when I am clicking on save button from VF page it is throwing following error.
I know this error is showing because of unique values are found while creating record.
I do not want to show this error, I want to show some standard message like already record is there. How can I handle this using apex?
please help me
Thanks in Advance
I have a button on visualforce page to save records into custom object. I have created a uniqie text field and workflow to prevent duplicate values.
but, when I am clicking on save button from VF page it is throwing following error.
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []
I know this error is showing because of unique values are found while creating record.
I do not want to show this error, I want to show some standard message like already record is there. How can I handle this using apex?
please help me
Thanks in Advance
- Harsha Shri
- February 12, 2018
- Like
- 0
Prevent duplicate records using apex program not trigger
Hi All,
I want to prevent duplicate records while saving. I do not want to create trigger for this. I want to do it in apex class. Here is my requirement.
I have two object. one is bank__c and another one is customer__c. both are having master detail. master is bank__c and child is customer__c.
Right now I am saving records as below.
here data variable is wrapper list that I am assigning to accountnum__c.
I want to prevent duplicate records with duplicate num__c. I dont want to create trigger for this. I want to do changes only apex class.
Please suggest me how to do this.
Please help me.
Thanks in Advance
I want to prevent duplicate records while saving. I do not want to create trigger for this. I want to do it in apex class. Here is my requirement.
I have two object. one is bank__c and another one is customer__c. both are having master detail. master is bank__c and child is customer__c.
Right now I am saving records as below.
cus.add(new customer__c(bank__c=bankId,accountnum__c=data.num__c));
here data variable is wrapper list that I am assigning to accountnum__c.
I want to prevent duplicate records with duplicate num__c. I dont want to create trigger for this. I want to do changes only apex class.
Please suggest me how to do this.
Please help me.
Thanks in Advance
- Harsha Shri
- February 11, 2018
- Like
- 0
Need help in test class for List and Map
Hi All,
I need help in test class for List and Map. I am adding values into list and returning map as list.
This is my controller class
Please help in wirtitng test class for this.
Thank you in Advance
I need help in test class for List and Map. I am adding values into list and returning map as list.
This is my controller class
public class viewMethod { public viewWrapper initViewWrapper(){ viewWrapper viewWrapper=new viewWrapper(); viewWrapper.searchOptions=new List<SelectOption>(); viewWrapper.searchOptions.add(new SelectOption('CEO','CEO')); viewWrapper.searchOptions.add(new SelectOption('Manager','Manager')); return viewWrapper; } public viewWrapper dataview(responseWrap.resp iResp){ viewWrapper viewWrapper=null; if(iResp!=null){ } return viewWrapper; } public List<Map<String,String>> DataasList(responseWrap.resp iResp){ List<Map<String,String>> mapList=new List<Map<String,String>>(); Map<String,String> recMap=null; if(iResp!=null){ responseWrap.SearchResponse searchResp=(responseWrap.SearchResponse) iResp; List<responseWrap.Order_Output> OList=searchResp.Order_Output; if(!OList.isEmpty()){ for(responseWrap.Order_Output res: OList){ recMap=new Map<String,String>(); recMap.put('Country',res.country); recMap.put('State',res.state); mapList.add(recMap); } } } return mapList; } }
Please help in wirtitng test class for this.
Thank you in Advance
- Harsha Shri
- January 30, 2018
- Like
- 0
Need help in Test class for wrapper class
Hi All,
I need help in writing test class for wrapper class. This is my class
Please help me with test class
Thank you very much
I need help in writing test class for wrapper class. This is my class
public class Wrapper{ public class Item { public Boolean checked{ get; set; } public Sobject sobj { get; set;} public O2r__x O1{ get; set;} public O1r__x O2{ get; set;} public String Type{ get; set;} public String ExternalID{ get; set;} public String id{ get; set;} public String sname{ get; set;} public Double net{ get; set;} public Item(Sobject so,String type){ sobj=so; if(type=='chp'){ O2=(O1r__x)so; ExternalID=O2.ExternalID; id=O2.id; sname=O2.sname__c; net=O2.net__c; } if(type=='odr'){ O1=(O2r__x)so; ExternalID=O1.ExternalID; id=O1.id; sname=O1.sname__c; } this.Type=type; checked = false; } } }
Please help me with test class
Thank you very much
- Harsha Shri
- January 24, 2018
- Like
- 0
Need help in Test class for external datasource
Hi All,
I am weak in writing test class. I have written a controller class related to external object. I want to write test class for the same.
This is my controller class
Thanks in Advance
I am weak in writing test class. I have written a controller class related to external object. I want to write test class for the same.
This is my controller class
global class DataSourcCon extends DataSource.Connection { public String LookupUrl {get; set;} global DataSourcCon(DataSource.ConnectionParams connectionParams) { } global DataSourcCon(DataSource.ConnectionParams connectionParams, String baseURL) { LookupUrl = baseURL; } override public DataSource.TableResult query(DataSource.QueryContext context) { String SOQLObject = context.tableSelection.columnsSelected.get(0).tableName; DataSource.Filter filter = context.tableSelection.filter; String validslordNumber = '666'; String validgoId = '900'; List<Map<String,String>> resultMap=new List<Map<String,String>>(); if(SOQLObject == 'sp_ord') { IntClass intdord = new IntClass(); IntClass.SearchParameters searchParameter = new IntClass.SearchParameters(); if(filter != null && filter.columnName != null && filter.columnValue != null) { if(filter.columnName == 'g_o_Id') { searchParameter.oppgRecId = String.valueof(filter.columnValue); } else if(filter.columnName == 'sl_ord_number') { searchParameter.slordNumber = String.valueof(filter.columnValue); } } else { searchParameter.oppgRecId = validgoId; } intdord.searchParam = searchParameter; IntWrap.SearchslordResponse resp = null; IntServ service = new IntServ(); resp = (IntWrap.SearchslordResponse) service.getordchapByCriteria(intdord); IntViHel helper=new IntViHel(); resultMap = helper.getResponseDataAsListMap(resp); return DataSource.TableResult.get(context,resultMap); } else if(SOQLObject == 'chap') { IntClass intdchap = new IntClass(); IntClass.SearchParameters searchParameter = new IntClass.SearchParameters(); if(filter != null && filter.columnName != null && filter.columnValue != null) { if(filter.columnName == 'g_o_Id') { searchParameter.oppgRecId = String.valueof(filter.columnValue); } else if(filter.columnName == 'sp_ord') { searchParameter.slordNumber = String.valueof(filter.columnValue); } } else { searchParameter.oppgRecId = validgoId; } intdchap.searchParam = searchParameter; IntWrap.SearchslordResponse resp = null; IntServ service = new IntServ(); resp = (IntWrap.SearchslordResponse) service.getordchapByCriteria(intdchap); IntViHel helper=new IntViHel(); resultMap = helper.getResponseDataAsListMap(resp); return DataSource.TableResult.get(context,resultMap); } else { return null; } } public DataSource.TableResult queryfromDBC(DataSource.QueryContext context) { System.PageReference lookupURL = Apexpages.currentPage(); if (context.tableSelection.columnsSelected.size() == 1 && context.tableSelection.columnsSelected.get(0).aggregation == DataSource.QueryAggregation.COUNT) { List<Map<String,Object>> rows = getRows(context); List<Map<String,Object>> response = DataSource.QueryUtils.filter(context, getRows(context)); List<Map<String, Object>> countResponse = new List<Map<String, Object>>(); Map<String, Object> countRow = new Map<String, Object>(); countRow.put(context.tableSelection.columnsSelected.get(0).columnName,response.size()); countResponse.add(countRow); return DataSource.TableResult.get(context,countResponse); } else { List<Map<String,Object>> filteredRows = DataSource.QueryUtils.filter(context, getRows(context)); List<Map<String,Object>> filteredRowsCustom = filterRows(context, getRows(context)); List<Map<String,Object>> sortedRows = DataSource.QueryUtils.sort(context, filteredRows); List<Map<String,Object>> limitedRows = DataSource.QueryUtils.applyLimitAndOffset(context,sortedRows); return DataSource.TableResult.get(context, limitedRows); } } override global List<DataSource.TableResult> search(DataSource.SearchContext c) { List<DataSource.TableResult> results = new List<DataSource.TableResult>(); for (DataSource.TableSelection tableSelection : c.tableSelections) { results.add(DataSource.TableResult.get(tableSelection, findRows(c))); } return results; } global override List<DataSource.UpsertResult> upsertRows(DataSource.UpsertContext context) { if (context.tableSelected == 'Sample') { List<DataSource.UpsertResult> results = new List<DataSource.UpsertResult>(); List<Map<String, Object>> rows = context.rows; for (Map<String, Object> row : rows){ HttpResponse response; if (row.get('ExternalId') == null){ response = null; } else { response = null; } Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped( response.getBody()); if (response.getStatusCode() == 200){ results.add(DataSource.UpsertResult.success( String.valueOf(m.get('id')))); } else { results.add(DataSource.UpsertResult.failure( String.valueOf(m.get('id')), 'The callout resulted in an error: ' + response.getStatusCode())); } } return results; } return null; } global override List<DataSource.DeleteResult> deleteRows(DataSource.DeleteContext context) { if (context.tableSelected == 'Sample'){ List<DataSource.DeleteResult> results = new List<DataSource.DeleteResult>(); for (String externalId : context.externalIds){ HttpResponse response = null; if (response.getStatusCode() == 200){ results.add(DataSource.DeleteResult.success(externalId)); } else { results.add(DataSource.DeleteResult.failure(externalId, 'Callout delete error:' + response.getBody())); } } return results; } return null; } private DataSource.DataType getFieldDataType(String dataType) { DataSource.DataType fieldType; if(dataType == 'Checkbox') fieldType = DataSource.DataType.BOOLEAN_TYPE; else if(dataType == 'Date/Time') fieldType = DataSource.DataType.DATETIME_TYPE; else if(dataType == 'Lookup Relationship') fieldType = DataSource.DataType.LOOKUP_TYPE; else if(dataType == 'External lookup relationship') fieldType = DataSource.DataType.EXTERNAL_LOOKUP_TYPE; else if(dataType == 'Indirect lookup relationship') fieldType = DataSource.DataType.INDIRECT_LOOKUP_TYPE; else if(dataType == 'Number') fieldType = DataSource.DataType.NUMBER_TYPE; else if(dataType == 'Text (40)') fieldType = DataSource.DataType.STRING_SHORT_TYPE; else if(dataType == 'Text Area (255)') fieldType = DataSource.DataType.STRING_LONG_TYPE; else if(dataType == 'Text Area Long (32768)') fieldType = DataSource.DataType.STRING_LONG_TYPE; else if(dataType == 'URL') fieldType = DataSource.DataType.URL_TYPE; return fieldType; } private DataSource.Column setupCustomFieldData(ext_External_Field__c extField) { DataSource.DataType fieldType = getFieldDataType(extField.Data_Type__c); DataSource.Column fieldData; Integer fieldLength = 0; Integer fieldDecimalsLength = 0; if(fieldType == DataSource.DataType.NUMBER_TYPE) { fieldLength = ((extField.Length__c + extField.Decimal_Places__c) <= 18) ? Integer.valueof(extField.Length__c) : 16; fieldDecimalsLength = ((extField.Length__c + extField.Decimal_Places__c) <= 18) ? Integer.valueof(extField.Decimal_Places__c) : 2; } else if(fieldType == DataSource.DataType.STRING_SHORT_TYPE) { fieldLength = (extField.Data_Type__c == 'Text (40)') ? 40 : 255; } else if(fieldType == DataSource.DataType.STRING_LONG_TYPE) { fieldLength = 32768; } if(fieldType == DataSource.DataType.LOOKUP_TYPE) { fieldData = DataSource.Column.lookup(extField.Name, extField.ReferenceTo__c); } else if(fieldType == DataSource.DataType.EXTERNAL_LOOKUP_TYPE) { fieldData = DataSource.Column.externalLookup(extField.Name, extField.ReferenceTo__c); } else if(fieldType == DataSource.DataType.INDIRECT_LOOKUP_TYPE) { fieldData = DataSource.Column.indirectLookup(extField.Name, extField.ReferenceTo__c, extField.ReferenceTargetField__c); } else if(fieldType != DataSource.DataType.LOOKUP_TYPE && fieldType != DataSource.DataType.EXTERNAL_LOOKUP_TYPE && fieldType != DataSource.DataType.INDIRECT_LOOKUP_TYPE) { fieldData = DataSource.Column.get(extField.Name, extField.Field_Label__c, extField.Description__c, extField.Sortable__c, extField.Filterable__c, fieldType, fieldLength, fieldDecimalsLength, null, null); } return fieldData; } private DataSource.Table setupTableData(ext_External_Object__c extObj, List<DataSource.Column> columns_extObj) { DataSource.Table extObj_Table = new DataSource.Table(); extObj_Table.labelSingular = extObj.Label_Singular__c; extObj_Table.labelPlural = extObj.Label_Plural__c; extObj_Table.name = extObj.Name; extObj_Table.description = extObj.Description__c; extObj_Table.nameColumn = extObj.Name_Column__c; extObj_Table.columns = columns_extObj; return extObj_Table; } private List<Map<String,Object>> filterRows(DataSource.QueryContext context, List<Map<String,Object>> allRows){ List<Map<String,Object>> objRowList = new List<Map<String,Object>>(); DataSource.TableSelection tableSelection=null; String tableName = null; if(context != null){ tableSelection = context.tableSelection; tableName=tableSelection.tableSelected; if(tablename.equalsIgnoreCase('sp_ord')) { } } return objRowList; } private List<Map<String,Object>> getObjRows(DataSource.QueryContext c){ List<Map<String,Object>> objRowList=new List<Map<String,Object>>(); DataSource.TableSelection tableSelection=null; String tableName=null; if(c!=null){ tableSelection=c.tableSelection; tableName=tableSelection.tableSelected; } return objRowList; } private List<Map<String,Object>> getRows(DataSource.ReadContext context) { List<Map<String, Object>> rows = new List<Map<String, Object>>(); DataSource.QueryContext myContext = (DataSource.QueryContext)context; DataSource.Filter filter = myContext.tableSelection.filter; return rows; } private List<Map<String,Object>> findRows(DataSource.ReadContext context) { List<Map<String, Object>> rows = new List<Map<String, Object>>(); DataSource.ReadContext myContext = (DataSource.ReadContext)context; return rows; } private Map<String,Object> foundRow(Map<String,Object> foundRow) { Map<String,Object> row = new Map<String,Object>(); row.put('ExternalId', string.valueOf(foundRow.get('Id'))); row.put('DisplayUrl', string.valueOf(foundRow.get('DisplayUrl'))); row.put('Name', string.valueOf(foundRow.get('Name'))); return row; } private static HttpResponse makeGetCallout() { Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint('https://test.com'); req.setMethod('GET'); HttpResponse response=h.send(req); return response; } }Please help me how to write test class for this
Thanks in Advance
- Harsha Shri
- January 24, 2018
- Like
- 1
Help in test class for updating field method
Hi All,
I need help in test class.
I have written a method for external object that sync all fields when ever I add custom fields into it. I am sharing my code please help me to write a test class for this method
Thank in Advance
I need help in test class.
I have written a method for external object that sync all fields when ever I add custom fields into it. I am sharing my code please help me to write a test class for this method
global class dataSourceCon extends datasource.connection{ override global List<DataSource.Table> method1() { List<DataSource.Table> extObj = new List<DataSource.Table>(); for(ext_obj1__c Obj : [SELECT Id, Name, Description__c, Name_Col__c, Label_Plu__c, Label_Sin__c, (SELECT Id, Name, External_Ta__c, Data_Type__c, Decimal_Places__c, Desc__c, Field_Label__c, Filtera__c, Len__c, ReferenceTarFld__c, RefTo__c, Sort__c FROM External_Col__r ) FROM ext_obj1__c LIMIT 50 ]) { List<DataSource.Column> colu_Obj = new List<DataSource.Column>(); // Standard fields colu_Obj.add(DataSource.Column.url('DisplayUrl')); colu_Obj.add(DataSource.Column.text('ExternalId',255)); //Custom fields for(Exter_Field__c cusField : Obj.External_Col__r) { colu_Obj.add(setupCustomFieldData(cusField)); } // Table Data extObj.add(setupTableData(Obj, colu_Obj)); } return extObj; } }Please help me in writing test class for this. I am new to test class and I am struggling
Thank in Advance
- Harsha Shri
- January 11, 2018
- Like
- 0
Pagination for wrapper Search results
Hi All,
I want pagination functionality for wrapper list which dynamically showing results based search text.
Here is my code
01<apex:page controller="CategorySearchController">
02 <apex:form >
03 <apex:pageBlock >
04
05 <apex:pageBlockButtons >
06 <apex:commandButton action="{!back}" value="Back"/>
07 </apex:pageBlockButtons>
08 <apex:pageMessages />
09
10 <apex:pageBlockSection title="You Selected" columns="1">
11 <apex:pageBlockTable value="{!selectedCategories}" var="c">
12 <apex:column value="{!c.cat.Name}"/>
13 </apex:pageBlockTable>
14 </apex:pageBlockSection>
15
16 </apex:pageBlock>
17 </apex:form>
18</apex:page>
controller class
01public class CategorySearchController {
02
03 // the results from the search. do not init the results or a blank rows show up initially on page load
04 public List<categoryWrapper> searchResults {get;set;}
05 // the categories that were checked/selected.
06 public List<categoryWrapper> selectedCategories {
07 get {
08 if (selectedCategories == null) selectedCategories = new List<categoryWrapper>();
09 return selectedCategories;
10 }
11 set;
12 }
13
14 // the text in the search box
15 public string searchText {
16 get {
17 if (searchText == null) searchText = 'acc'; // prefill the serach box for ease of use
18 return searchText;
19 }
20 set;
21 }
22
23 // constructor
24 public CategorySearchController() {}
25
26 // fired when the search button is clicked
27 public PageReference search() {
28
29 if (searchResults == null) {
30 searchResults = new List<categoryWrapper>(); // init the list if it is null
31 } else {
32 searchResults.clear(); // clear out the current results if they exist
33 }
34 // Note: you could have achieved the same results as above by just using:
35 // searchResults = new List<categoryWrapper>();
36
37 // dynamic soql
38 String qry = 'Select c.Name, c.Id From account c Where c.Name LIKE \'%'+searchText+'%\' Order By c.Name';
39
40 for(account c : Database.query(qry)) {
41 //new wrapper by passing it the category in the constructor
42 CategoryWrapper cw = new CategoryWrapper(c);
43 // wrapper to the results
44 searchResults.add(cw);
45 }
46 return null;
47 }
48
49 public PageReference next() {
50
51 // clear out the currently selected categories
52 selectedCategories.clear();
53
54 // add the selected categories to a new List
55 for (CategoryWrapper cw : searchResults) {
56 if (cw.checked)
57 selectedCategories.add(new CategoryWrapper(cw.cat));
58 }
59
60 // ensure they selected at least one category or show an error message.
61 if (selectedCategories.size() > 0) {
62 return Page.Category_Results;
63 } else {
64 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Category.'));
65 return null;
66 }
67
68 }
69
70 // fired when the back button is clicked
71 public PageReference back() {
72 return Page.Category_Search;
73 }
74
75}
01public class CategoryWrapper {
02
03 public Boolean checked{ get; set; }
04 public account cat { get; set;}
05
06 public CategoryWrapper(){
07 cat = new account ();
08 checked = false;
09 }
10
11 public CategoryWrapper(account c){
12 cat = c;
13 checked = false;
14 }
15
16
17
18}
I want pagination for the records which are showing in dynamic wrapper list.
Please help me. Its urgent
Thanks in Advance
I want pagination functionality for wrapper list which dynamically showing results based search text.
Here is my code
01<apex:page controller="CategorySearchController">
02 <apex:form >
03 <apex:pageBlock >
04
05 <apex:pageBlockButtons >
06 <apex:commandButton action="{!back}" value="Back"/>
07 </apex:pageBlockButtons>
08 <apex:pageMessages />
09
10 <apex:pageBlockSection title="You Selected" columns="1">
11 <apex:pageBlockTable value="{!selectedCategories}" var="c">
12 <apex:column value="{!c.cat.Name}"/>
13 </apex:pageBlockTable>
14 </apex:pageBlockSection>
15
16 </apex:pageBlock>
17 </apex:form>
18</apex:page>
controller class
01public class CategorySearchController {
02
03 // the results from the search. do not init the results or a blank rows show up initially on page load
04 public List<categoryWrapper> searchResults {get;set;}
05 // the categories that were checked/selected.
06 public List<categoryWrapper> selectedCategories {
07 get {
08 if (selectedCategories == null) selectedCategories = new List<categoryWrapper>();
09 return selectedCategories;
10 }
11 set;
12 }
13
14 // the text in the search box
15 public string searchText {
16 get {
17 if (searchText == null) searchText = 'acc'; // prefill the serach box for ease of use
18 return searchText;
19 }
20 set;
21 }
22
23 // constructor
24 public CategorySearchController() {}
25
26 // fired when the search button is clicked
27 public PageReference search() {
28
29 if (searchResults == null) {
30 searchResults = new List<categoryWrapper>(); // init the list if it is null
31 } else {
32 searchResults.clear(); // clear out the current results if they exist
33 }
34 // Note: you could have achieved the same results as above by just using:
35 // searchResults = new List<categoryWrapper>();
36
37 // dynamic soql
38 String qry = 'Select c.Name, c.Id From account c Where c.Name LIKE \'%'+searchText+'%\' Order By c.Name';
39
40 for(account c : Database.query(qry)) {
41 //new wrapper by passing it the category in the constructor
42 CategoryWrapper cw = new CategoryWrapper(c);
43 // wrapper to the results
44 searchResults.add(cw);
45 }
46 return null;
47 }
48
49 public PageReference next() {
50
51 // clear out the currently selected categories
52 selectedCategories.clear();
53
54 // add the selected categories to a new List
55 for (CategoryWrapper cw : searchResults) {
56 if (cw.checked)
57 selectedCategories.add(new CategoryWrapper(cw.cat));
58 }
59
60 // ensure they selected at least one category or show an error message.
61 if (selectedCategories.size() > 0) {
62 return Page.Category_Results;
63 } else {
64 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Category.'));
65 return null;
66 }
67
68 }
69
70 // fired when the back button is clicked
71 public PageReference back() {
72 return Page.Category_Search;
73 }
74
75}
01public class CategoryWrapper {
02
03 public Boolean checked{ get; set; }
04 public account cat { get; set;}
05
06 public CategoryWrapper(){
07 cat = new account ();
08 checked = false;
09 }
10
11 public CategoryWrapper(account c){
12 cat = c;
13 checked = false;
14 }
15
16
17
18}
I want pagination for the records which are showing in dynamic wrapper list.
Please help me. Its urgent
Thanks in Advance
- Harsha Shri
- January 10, 2018
- Like
- 0
Pagination for wrapper Search results - emergency
Hi All,
I want pagination functionality for wrapper list which dynamically showing results based search text.
Here is my code
controller class
I want pagination for the records which are showing in dynamic wrapper list.
Please help me. Its urgent
Thanks in Advance
I want pagination functionality for wrapper list which dynamically showing results based search text.
Here is my code
<apex:page controller="CategorySearchController"> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton action="{!back}" value="Back"/> </apex:pageBlockButtons> <apex:pageMessages /> <apex:pageBlockSection title="You Selected" columns="1"> <apex:pageBlockTable value="{!selectedCategories}" var="c"> <apex:column value="{!c.cat.Name}"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
controller class
public class CategorySearchController { // the results from the search. do not init the results or a blank rows show up initially on page load public List<categoryWrapper> searchResults {get;set;} // the categories that were checked/selected. public List<categoryWrapper> selectedCategories { get { if (selectedCategories == null) selectedCategories = new List<categoryWrapper>(); return selectedCategories; } set; } // the text in the search box public string searchText { get { if (searchText == null) searchText = 'acc'; // prefill the serach box for ease of use return searchText; } set; } // constructor public CategorySearchController() {} // fired when the search button is clicked public PageReference search() { if (searchResults == null) { searchResults = new List<categoryWrapper>(); // init the list if it is null } else { searchResults.clear(); // clear out the current results if they exist } // Note: you could have achieved the same results as above by just using: // searchResults = new List<categoryWrapper>(); // dynamic soql String qry = 'Select c.Name, c.Id From account c Where c.Name LIKE \'%'+searchText+'%\' Order By c.Name'; for(account c : Database.query(qry)) { //new wrapper by passing it the category in the constructor CategoryWrapper cw = new CategoryWrapper(c); // wrapper to the results searchResults.add(cw); } return null; } public PageReference next() { // clear out the currently selected categories selectedCategories.clear(); // add the selected categories to a new List for (CategoryWrapper cw : searchResults) { if (cw.checked) selectedCategories.add(new CategoryWrapper(cw.cat)); } // ensure they selected at least one category or show an error message. if (selectedCategories.size() > 0) { return Page.Category_Results; } else { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Category.')); return null; } } // fired when the back button is clicked public PageReference back() { return Page.Category_Search; } }
public class CategoryWrapper { public Boolean checked{ get; set; } public account cat { get; set;} public CategoryWrapper(){ cat = new account (); checked = false; } public CategoryWrapper(account c){ cat = c; checked = false; } }
I want pagination for the records which are showing in dynamic wrapper list.
Please help me. Its urgent
Thanks in Advance
- Harsha Shri
- January 09, 2018
- Like
- 0
Error in External object SOQL Query
Hi All,
I am getting following when I am performing DML Operation
This is my code
Please help me in resolving this error
Thanks in Advance
I am getting following when I am performing DML Operation
System.ExternalObjectException: Salesforce System Error: 627698564-15996 (1450171494) (1450171494) : (System Code) Error is in expression '{!Search}' in component <apex:commandButton> in page cpm_lookup1: Class.CustomAccountLookupController.performSearch: line 34, column 1 Class.CustomAccountLookupController.runSearch: line 23, column 1 Class.CustomAccountLookupController.search: line 16, column 1
This is my code
public with sharing class CustomAccountLookupController { public Account account {get;set;} // new account to create public List<externalobj1__x> results{get;set;} // search results public string searchString{get;set;} // search keyword public CustomAccountLookupController() { account = new Account(); // get the current search string searchString = System.currentPageReference().getParameters().get('lksrch'); runSearch(); } // performs the keyword search public PageReference search() { runSearch(); return null; } // prepare the query and issue the search command private void runSearch() { // TODO prepare query string for complex serarches & prevent injections results = performSearch(searchString); } // run the search and return the records found. private List<externalobj1__x> performSearch(string searchString) { String soql = 'select id,externalid from externalobj1__x'; if(searchString != '' && searchString != null) soql = soql + ' where externalid LIKE \'%' + searchString +'%\''; soql = soql + ' limit 25'; System.debug(soql); return database.query(soql); } // save the new account record public PageReference saveAccount() { insert account; // reset the account account = new Account(); return null; } // used by the visualforce page to send the link to the right dom element public string getFormTag() { return System.currentPageReference().getParameters().get('frm'); } // used by the visualforce page to send the link to the right dom element for the text box public string getTextBox() { return System.currentPageReference().getParameters().get('txt'); } }
<apex:page controller="CustomAccountLookupController" title="Search" showHeader="false" sideBar="false" tabStyle="Account" id="pg"> <apex:form > <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel"> <!-- SEARCH TAB --> <apex:tab label="Search" name="tab1" id="tabOne"> <apex:actionRegion > <apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/> <apex:inputText id="txtSearch" value="{!searchString}" /> <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span> </apex:outputPanel> <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block"> <apex:pageBlock id="searchResults"> <apex:pageBlockTable value="{!results}" var="a" id="tblResults"> <apex:column > <apex:facet name="header"> <apex:outputPanel >Name</apex:outputPanel> </apex:facet> <apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.externalId}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.externalid}</apex:outputLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel> </apex:actionRegion> </apex:tab> <!-- NEW ACCOUNT TAB --> <apex:tab label="New Account" name="tab2" id="tabTwo"> <apex:pageBlock id="newAccount" title="New Account" > <apex:pageBlockButtons > <apex:commandButton value="Save"/> </apex:pageBlockButtons> <apex:pageMessages /> <apex:pageBlockSection columns="2"> </apex:pageBlockSection> </apex:pageBlock> </apex:tab> </apex:tabPanel> </apex:outputPanel> </apex:form> </apex:page>
Please help me in resolving this error
Thanks in Advance
- Harsha Shri
- January 08, 2018
- Like
- 0
Multi records selection from lookup in salesforce using apex
Hi All,
I want multi select record selection for lookup results and whatever I selected records I want to save it in related list.
How can I do this. If any one is having code rference for this please share.
Thanks in Advance
- Harsha Shri
- January 04, 2018
- Like
- 0
Need help in Test class for external datasource
Hi All,
I am weak in writing test class. I have written a controller class related to external object. I want to write test class for the same.
This is my controller class
Thanks in Advance
I am weak in writing test class. I have written a controller class related to external object. I want to write test class for the same.
This is my controller class
global class DataSourcCon extends DataSource.Connection { public String LookupUrl {get; set;} global DataSourcCon(DataSource.ConnectionParams connectionParams) { } global DataSourcCon(DataSource.ConnectionParams connectionParams, String baseURL) { LookupUrl = baseURL; } override public DataSource.TableResult query(DataSource.QueryContext context) { String SOQLObject = context.tableSelection.columnsSelected.get(0).tableName; DataSource.Filter filter = context.tableSelection.filter; String validslordNumber = '666'; String validgoId = '900'; List<Map<String,String>> resultMap=new List<Map<String,String>>(); if(SOQLObject == 'sp_ord') { IntClass intdord = new IntClass(); IntClass.SearchParameters searchParameter = new IntClass.SearchParameters(); if(filter != null && filter.columnName != null && filter.columnValue != null) { if(filter.columnName == 'g_o_Id') { searchParameter.oppgRecId = String.valueof(filter.columnValue); } else if(filter.columnName == 'sl_ord_number') { searchParameter.slordNumber = String.valueof(filter.columnValue); } } else { searchParameter.oppgRecId = validgoId; } intdord.searchParam = searchParameter; IntWrap.SearchslordResponse resp = null; IntServ service = new IntServ(); resp = (IntWrap.SearchslordResponse) service.getordchapByCriteria(intdord); IntViHel helper=new IntViHel(); resultMap = helper.getResponseDataAsListMap(resp); return DataSource.TableResult.get(context,resultMap); } else if(SOQLObject == 'chap') { IntClass intdchap = new IntClass(); IntClass.SearchParameters searchParameter = new IntClass.SearchParameters(); if(filter != null && filter.columnName != null && filter.columnValue != null) { if(filter.columnName == 'g_o_Id') { searchParameter.oppgRecId = String.valueof(filter.columnValue); } else if(filter.columnName == 'sp_ord') { searchParameter.slordNumber = String.valueof(filter.columnValue); } } else { searchParameter.oppgRecId = validgoId; } intdchap.searchParam = searchParameter; IntWrap.SearchslordResponse resp = null; IntServ service = new IntServ(); resp = (IntWrap.SearchslordResponse) service.getordchapByCriteria(intdchap); IntViHel helper=new IntViHel(); resultMap = helper.getResponseDataAsListMap(resp); return DataSource.TableResult.get(context,resultMap); } else { return null; } } public DataSource.TableResult queryfromDBC(DataSource.QueryContext context) { System.PageReference lookupURL = Apexpages.currentPage(); if (context.tableSelection.columnsSelected.size() == 1 && context.tableSelection.columnsSelected.get(0).aggregation == DataSource.QueryAggregation.COUNT) { List<Map<String,Object>> rows = getRows(context); List<Map<String,Object>> response = DataSource.QueryUtils.filter(context, getRows(context)); List<Map<String, Object>> countResponse = new List<Map<String, Object>>(); Map<String, Object> countRow = new Map<String, Object>(); countRow.put(context.tableSelection.columnsSelected.get(0).columnName,response.size()); countResponse.add(countRow); return DataSource.TableResult.get(context,countResponse); } else { List<Map<String,Object>> filteredRows = DataSource.QueryUtils.filter(context, getRows(context)); List<Map<String,Object>> filteredRowsCustom = filterRows(context, getRows(context)); List<Map<String,Object>> sortedRows = DataSource.QueryUtils.sort(context, filteredRows); List<Map<String,Object>> limitedRows = DataSource.QueryUtils.applyLimitAndOffset(context,sortedRows); return DataSource.TableResult.get(context, limitedRows); } } override global List<DataSource.TableResult> search(DataSource.SearchContext c) { List<DataSource.TableResult> results = new List<DataSource.TableResult>(); for (DataSource.TableSelection tableSelection : c.tableSelections) { results.add(DataSource.TableResult.get(tableSelection, findRows(c))); } return results; } global override List<DataSource.UpsertResult> upsertRows(DataSource.UpsertContext context) { if (context.tableSelected == 'Sample') { List<DataSource.UpsertResult> results = new List<DataSource.UpsertResult>(); List<Map<String, Object>> rows = context.rows; for (Map<String, Object> row : rows){ HttpResponse response; if (row.get('ExternalId') == null){ response = null; } else { response = null; } Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped( response.getBody()); if (response.getStatusCode() == 200){ results.add(DataSource.UpsertResult.success( String.valueOf(m.get('id')))); } else { results.add(DataSource.UpsertResult.failure( String.valueOf(m.get('id')), 'The callout resulted in an error: ' + response.getStatusCode())); } } return results; } return null; } global override List<DataSource.DeleteResult> deleteRows(DataSource.DeleteContext context) { if (context.tableSelected == 'Sample'){ List<DataSource.DeleteResult> results = new List<DataSource.DeleteResult>(); for (String externalId : context.externalIds){ HttpResponse response = null; if (response.getStatusCode() == 200){ results.add(DataSource.DeleteResult.success(externalId)); } else { results.add(DataSource.DeleteResult.failure(externalId, 'Callout delete error:' + response.getBody())); } } return results; } return null; } private DataSource.DataType getFieldDataType(String dataType) { DataSource.DataType fieldType; if(dataType == 'Checkbox') fieldType = DataSource.DataType.BOOLEAN_TYPE; else if(dataType == 'Date/Time') fieldType = DataSource.DataType.DATETIME_TYPE; else if(dataType == 'Lookup Relationship') fieldType = DataSource.DataType.LOOKUP_TYPE; else if(dataType == 'External lookup relationship') fieldType = DataSource.DataType.EXTERNAL_LOOKUP_TYPE; else if(dataType == 'Indirect lookup relationship') fieldType = DataSource.DataType.INDIRECT_LOOKUP_TYPE; else if(dataType == 'Number') fieldType = DataSource.DataType.NUMBER_TYPE; else if(dataType == 'Text (40)') fieldType = DataSource.DataType.STRING_SHORT_TYPE; else if(dataType == 'Text Area (255)') fieldType = DataSource.DataType.STRING_LONG_TYPE; else if(dataType == 'Text Area Long (32768)') fieldType = DataSource.DataType.STRING_LONG_TYPE; else if(dataType == 'URL') fieldType = DataSource.DataType.URL_TYPE; return fieldType; } private DataSource.Column setupCustomFieldData(ext_External_Field__c extField) { DataSource.DataType fieldType = getFieldDataType(extField.Data_Type__c); DataSource.Column fieldData; Integer fieldLength = 0; Integer fieldDecimalsLength = 0; if(fieldType == DataSource.DataType.NUMBER_TYPE) { fieldLength = ((extField.Length__c + extField.Decimal_Places__c) <= 18) ? Integer.valueof(extField.Length__c) : 16; fieldDecimalsLength = ((extField.Length__c + extField.Decimal_Places__c) <= 18) ? Integer.valueof(extField.Decimal_Places__c) : 2; } else if(fieldType == DataSource.DataType.STRING_SHORT_TYPE) { fieldLength = (extField.Data_Type__c == 'Text (40)') ? 40 : 255; } else if(fieldType == DataSource.DataType.STRING_LONG_TYPE) { fieldLength = 32768; } if(fieldType == DataSource.DataType.LOOKUP_TYPE) { fieldData = DataSource.Column.lookup(extField.Name, extField.ReferenceTo__c); } else if(fieldType == DataSource.DataType.EXTERNAL_LOOKUP_TYPE) { fieldData = DataSource.Column.externalLookup(extField.Name, extField.ReferenceTo__c); } else if(fieldType == DataSource.DataType.INDIRECT_LOOKUP_TYPE) { fieldData = DataSource.Column.indirectLookup(extField.Name, extField.ReferenceTo__c, extField.ReferenceTargetField__c); } else if(fieldType != DataSource.DataType.LOOKUP_TYPE && fieldType != DataSource.DataType.EXTERNAL_LOOKUP_TYPE && fieldType != DataSource.DataType.INDIRECT_LOOKUP_TYPE) { fieldData = DataSource.Column.get(extField.Name, extField.Field_Label__c, extField.Description__c, extField.Sortable__c, extField.Filterable__c, fieldType, fieldLength, fieldDecimalsLength, null, null); } return fieldData; } private DataSource.Table setupTableData(ext_External_Object__c extObj, List<DataSource.Column> columns_extObj) { DataSource.Table extObj_Table = new DataSource.Table(); extObj_Table.labelSingular = extObj.Label_Singular__c; extObj_Table.labelPlural = extObj.Label_Plural__c; extObj_Table.name = extObj.Name; extObj_Table.description = extObj.Description__c; extObj_Table.nameColumn = extObj.Name_Column__c; extObj_Table.columns = columns_extObj; return extObj_Table; } private List<Map<String,Object>> filterRows(DataSource.QueryContext context, List<Map<String,Object>> allRows){ List<Map<String,Object>> objRowList = new List<Map<String,Object>>(); DataSource.TableSelection tableSelection=null; String tableName = null; if(context != null){ tableSelection = context.tableSelection; tableName=tableSelection.tableSelected; if(tablename.equalsIgnoreCase('sp_ord')) { } } return objRowList; } private List<Map<String,Object>> getObjRows(DataSource.QueryContext c){ List<Map<String,Object>> objRowList=new List<Map<String,Object>>(); DataSource.TableSelection tableSelection=null; String tableName=null; if(c!=null){ tableSelection=c.tableSelection; tableName=tableSelection.tableSelected; } return objRowList; } private List<Map<String,Object>> getRows(DataSource.ReadContext context) { List<Map<String, Object>> rows = new List<Map<String, Object>>(); DataSource.QueryContext myContext = (DataSource.QueryContext)context; DataSource.Filter filter = myContext.tableSelection.filter; return rows; } private List<Map<String,Object>> findRows(DataSource.ReadContext context) { List<Map<String, Object>> rows = new List<Map<String, Object>>(); DataSource.ReadContext myContext = (DataSource.ReadContext)context; return rows; } private Map<String,Object> foundRow(Map<String,Object> foundRow) { Map<String,Object> row = new Map<String,Object>(); row.put('ExternalId', string.valueOf(foundRow.get('Id'))); row.put('DisplayUrl', string.valueOf(foundRow.get('DisplayUrl'))); row.put('Name', string.valueOf(foundRow.get('Name'))); return row; } private static HttpResponse makeGetCallout() { Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint('https://test.com'); req.setMethod('GET'); HttpResponse response=h.send(req); return response; } }Please help me how to write test class for this
Thanks in Advance
- Harsha Shri
- January 24, 2018
- Like
- 1
Need help in User object Test class
Hi All,
I have written apex class related to user object.
I am very new to test classes. Can someone please help me with this. Following are my classes
Please help me in wrtting test class for this.
Thanks in Advance
I have written apex class related to user object.
I am very new to test classes. Can someone please help me with this. Following are my classes
public class UserController { public static List <UserWrapper> fetchUser(String searchKeyWord,String sortField,Boolean isAsc) { profile p =[Select Name from Profile where Id =: userinfo.getProfileid()]; List<UserWrapper> UserRec = new List<UserWrapper>(); String searchKey = '%'+searchKeyWord + '%'; List < User > returnList = new List < User > (); List < User > lstOfUser=new List < User > (); List<String> profiles= new List<String>(); String sSoql=''; String emailRegex = '^[a-zA-Z0-9._|\\\\%#~`=?&/$^*!}{+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$'; Pattern MyPattern = Pattern.compile(emailRegex); Matcher MyMatcher = MyPattern.matcher(searchKeyWord); String pn='Label3'; profiles= pn.split(','); if(p.Name.equals('Customer Portal Manager')){ List<Contact> con = [select ID from Contact where AccountID in(select id from Account)]; if (!MyMatcher.matches()){ sSoql='select Name, Email from User where Name LIKE \''+ searchKey+'\' and IsActive = true and Profile.Name in :profiles and Id != \''+Userinfo.getUserId()+'\' and ContactID in:con'; }else{ sSoql='select Name, Email from User where Email LIKE \''+ searchKey+'\' and IsActive = true and Profile.Name in :profiles and Id != \''+Userinfo.getUserId()+'\' and ContactID in:con'; } } else{ if (!MyMatcher.matches()){ sSoql='select Name, Email from User where Name LIKE \''+ searchKey+'\' and IsActive = true and Profile.Name in :profiles and Id != \''+Userinfo.getUserId()+'\''; } else{ sSoql='select Name, Email from User where Email LIKE \''+ searchKey+'\' and IsActive = true and Profile.Name in :profiles and Id != \''+Userinfo.getUserId()+'\''; } } if (sortField != '' && sortField != Null) { sSoql += ' order by ' + sortField; if(isAsc!=Null) { if (isAsc) { sSoql += ' asc NULLS LAST'; } else { sSoql += ' desc'; } } } try { lstOfUser= Database.query(sSoql); }Catch(Exception e) { System.debug('exception in user'+e); } for (User acc: lstOfUser) { UserWrapper user_rec = new UserWrapper(); user_rec.UserEmail=acc.Email; user_rec.Name=acc.Name; user_rec.userID=acc.Id; user_rec.isSelected=true; UserRec.add(user_rec); } return UserRec; } public static String getUserName(String UserID){ return [select name from User where ID=:UserID].Name; } public static List<UserWrapper> performAction(String userRecords,List<UserWrapper> selectedUsers){ List<UserWrapper> storeresult = new List<userWrapper>(); if(!string.isBlank(userRecords)) { List<UserWrapper> lstUserRecords = (List<UserWrapper>) System.JSON.deserialize(userRecords,List<UserWrapper>.class); for(UserWrapper objPositionRecords:lstUserRecords) { if(objPositionRecords.isSelected) { storeresult.add(objPositionRecords); } } selectedUsers.addAll(storeresult); } return selectedUsers; } public static List<UserWrapper> removeUsers(String removeUsers){ List<UserWrapper> remove_Users = new List<userWrapper>(); if(!string.isBlank(removeUsers)) { List<UserWrapper> rmvUserRecords = (List<UserWrapper>) System.JSON.deserialize(removeUsers,List<UserWrapper>.class); for(UserWrapper objPositionRecords:rmvUserRecords) { if(!objPositionRecords.isSelected) { remove_Users.add(objPositionRecords); } } } return remove_Users; } }
public class UserWrapper { public boolean isSelected; public String UserEmail; public String Name; public String userID; public UserWrapper() { isSelected = false; UserEmail=''; Name = ''; } }
Please help me in wrtting test class for this.
Thanks in Advance
- Harsha Shri
- April 09, 2018
- Like
- 0
Redirect issue in VF Page commandbutton
HI All,
I am having redirect issue in VF page. When I am using reRender and rendered together in commanad button I am getting this issue. If I am not using rerender in command button, It is redirecting to the path what I mentioned in pagereference methond.
This is my code.
Please help me how to resolve this issue.
Thanks in Advance
I am having redirect issue in VF page. When I am using reRender and rendered together in commanad button I am getting this issue. If I am not using rerender in command button, It is redirecting to the path what I mentioned in pagereference methond.
This is my code.
public class SaveRecords{ public PageReference saveToCollege() { Boolean saved = false; saved = Class2.saveCollegeData(WrapperData.result,collegeId); if(saved) { PageReference pg=new PageReference('/'+collegeId ); return pg; } } } <apex:page standardcontroller="College__c" controller="SaveRecords"> <apex:form> <apex:pageBlock id="mySelectedPB1"> some code </apex:pageBlock> <apex:commandButton action="{!saveToCollege}" value="Link to College" rerender="mySelectedPB1" rendered="{!if(WrapperData.result != null,true,false)}"/> </apex:form> </apex:page>
Please help me how to resolve this issue.
Thanks in Advance
- Harsha Shri
- March 28, 2018
- Like
- 0
Rerender issue in Visualforce page commandbutton
Hi All,
I am having rerender issue in VF page.
Problem:
when I am putting reRender and rendred together in a commandbutton, when clicking on commandbutton it is not redirecting to the actual page what I mentioned on pagereference method.
This is my code
Apex class:
Please suggest me where it is going wrong
Thanks in Advance
I am having rerender issue in VF page.
Problem:
when I am putting reRender and rendred together in a commandbutton, when clicking on commandbutton it is not redirecting to the actual page what I mentioned on pagereference method.
This is my code
Apex class:
public class SaveRecords{ public PageReference saveToCollege() { Boolean saved = false; saved = Class2.saveCollegeData(WrapperData.result,collegeId); if(saved) { PageReference pg=new PageReference('/'+collegeId ); return pg; } } }VF Page code:
<apex:page> <apex:form> <apex:pageBlock id="mySelectedPB1"> some code </apex:pageBlock> <apex:commandButton action="{!linkToProject}" value="Link to Project" rerender="mySelectedPB1" rendered="{!if(WrapperData.result != null,true,false)}"/> </apex:form> </apex:page>
Please suggest me where it is going wrong
Thanks in Advance
- Harsha Shri
- March 27, 2018
- Like
- 0
Make Visualforce page as responsive design
Hi All,
I have developed a VF page by using standard controller. I have alignment issue. Please see below image.
If you see above image Account name and produ order number are not in same line.
I want to make all elements in the above visualforce page as responsive desing. even I minimize screen also, I dont want to distract the fields.
Please help me how to make this as responsive
Thanks in Advance
I have developed a VF page by using standard controller. I have alignment issue. Please see below image.
If you see above image Account name and produ order number are not in same line.
I want to make all elements in the above visualforce page as responsive desing. even I minimize screen also, I dont want to distract the fields.
Please help me how to make this as responsive
<apex:page standardController="Account" showHeader="true"> <apex:form > <apex:sectionHeader title="title1"/> <apex:pageBlock title="title2" tabStyle="account"> <apex:pageBlockSection title="PBS2" collapsible="false" id="myPbSec2" columns="2"> <apex:outputField value="{!account.name}"/> <apex:outputField value="{!account.description}"/> <apex:outputPanel > <span style="margin-left:102px"><apex:outputLabel value="Produ Order Number"/><span style="margin-left:18px"><apex:inputtext label="" id="ST"/> <apex:commandButton value="Button1!" /></span></span> </apex:outputPanel> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Thanks in Advance
- Harsha Shri
- February 21, 2018
- Like
- 0
Help in Select all functionality for check box
Hi All,
I have written code for check box select all functionality. It is working, but is having one issue please help me. I am sharing my code.
Here if I check main check box, it is selecting all checkboxes under it. If I am unselecting all, it is unselecting all.
But issue is, If I unselect any check box from result check box main checkbox is not getting unselected. the below image is reference. 1st check is main check box. when I deselect 3rd checkbox the 1st one should uncheck. right now it is not happening. Please help me
Thanks in Advance
I have written code for check box select all functionality. It is working, but is having one issue please help me. I am sharing my code.
public class Mainclass{ public WrapperClass viewWrapper {get;set;} public void SelectAll(){ if(viewwrapper.check){ for(WrapperClass.SearchItem s : viewWrapper.resultList) { s.checked = true; } } else { for(WrapperClass.SearchItem s : viewWrapper.resultList) { s.checked = false; } } } }
public class WrapperClass { public Boolean check{get;set;} public List<SearchItem> resultList{ get; set; } public class SearchItem { public Boolean checked{ get; set; } \\ some other fields are also there } }
<apex:page> <apex:form> <apex:coloumn> <apex:facet> <apex:inputCheckbox style="margin:2px;" value="{!viewWrapper.check}"> <apex:actionSupport action="{!selectAll}" event="onclick" reRender="resultsBlock"/></apex:inputCheckbox> </apex:facet> </apex:coloumn> </apex:form> </apex:page>
Here if I check main check box, it is selecting all checkboxes under it. If I am unselecting all, it is unselecting all.
But issue is, If I unselect any check box from result check box main checkbox is not getting unselected. the below image is reference. 1st check is main check box. when I deselect 3rd checkbox the 1st one should uncheck. right now it is not happening. Please help me
Thanks in Advance
- Harsha Shri
- February 14, 2018
- Like
- 0
DML exception on VF Page
Hi All,
I have a button on visualforce page to save records into custom object. I have created a uniqie text field and workflow to prevent duplicate values.
but, when I am clicking on save button from VF page it is throwing following error.
I know this error is showing because of unique values are found while creating record.
I do not want to show this error, I want to show some standard message like already record is there. How can I handle this using apex?
please help me
Thanks in Advance
I have a button on visualforce page to save records into custom object. I have created a uniqie text field and workflow to prevent duplicate values.
but, when I am clicking on save button from VF page it is throwing following error.
System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, duplicate value found: <unknown> duplicates value on record with id: <unknown>: []
I know this error is showing because of unique values are found while creating record.
I do not want to show this error, I want to show some standard message like already record is there. How can I handle this using apex?
please help me
Thanks in Advance
- Harsha Shri
- February 12, 2018
- Like
- 0
Pagination for wrapper Search results
Hi All,
I want pagination functionality for wrapper list which dynamically showing results based search text.
Here is my code
01<apex:page controller="CategorySearchController">
02 <apex:form >
03 <apex:pageBlock >
04
05 <apex:pageBlockButtons >
06 <apex:commandButton action="{!back}" value="Back"/>
07 </apex:pageBlockButtons>
08 <apex:pageMessages />
09
10 <apex:pageBlockSection title="You Selected" columns="1">
11 <apex:pageBlockTable value="{!selectedCategories}" var="c">
12 <apex:column value="{!c.cat.Name}"/>
13 </apex:pageBlockTable>
14 </apex:pageBlockSection>
15
16 </apex:pageBlock>
17 </apex:form>
18</apex:page>
controller class
01public class CategorySearchController {
02
03 // the results from the search. do not init the results or a blank rows show up initially on page load
04 public List<categoryWrapper> searchResults {get;set;}
05 // the categories that were checked/selected.
06 public List<categoryWrapper> selectedCategories {
07 get {
08 if (selectedCategories == null) selectedCategories = new List<categoryWrapper>();
09 return selectedCategories;
10 }
11 set;
12 }
13
14 // the text in the search box
15 public string searchText {
16 get {
17 if (searchText == null) searchText = 'acc'; // prefill the serach box for ease of use
18 return searchText;
19 }
20 set;
21 }
22
23 // constructor
24 public CategorySearchController() {}
25
26 // fired when the search button is clicked
27 public PageReference search() {
28
29 if (searchResults == null) {
30 searchResults = new List<categoryWrapper>(); // init the list if it is null
31 } else {
32 searchResults.clear(); // clear out the current results if they exist
33 }
34 // Note: you could have achieved the same results as above by just using:
35 // searchResults = new List<categoryWrapper>();
36
37 // dynamic soql
38 String qry = 'Select c.Name, c.Id From account c Where c.Name LIKE \'%'+searchText+'%\' Order By c.Name';
39
40 for(account c : Database.query(qry)) {
41 //new wrapper by passing it the category in the constructor
42 CategoryWrapper cw = new CategoryWrapper(c);
43 // wrapper to the results
44 searchResults.add(cw);
45 }
46 return null;
47 }
48
49 public PageReference next() {
50
51 // clear out the currently selected categories
52 selectedCategories.clear();
53
54 // add the selected categories to a new List
55 for (CategoryWrapper cw : searchResults) {
56 if (cw.checked)
57 selectedCategories.add(new CategoryWrapper(cw.cat));
58 }
59
60 // ensure they selected at least one category or show an error message.
61 if (selectedCategories.size() > 0) {
62 return Page.Category_Results;
63 } else {
64 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Category.'));
65 return null;
66 }
67
68 }
69
70 // fired when the back button is clicked
71 public PageReference back() {
72 return Page.Category_Search;
73 }
74
75}
01public class CategoryWrapper {
02
03 public Boolean checked{ get; set; }
04 public account cat { get; set;}
05
06 public CategoryWrapper(){
07 cat = new account ();
08 checked = false;
09 }
10
11 public CategoryWrapper(account c){
12 cat = c;
13 checked = false;
14 }
15
16
17
18}
I want pagination for the records which are showing in dynamic wrapper list.
Please help me. Its urgent
Thanks in Advance
I want pagination functionality for wrapper list which dynamically showing results based search text.
Here is my code
01<apex:page controller="CategorySearchController">
02 <apex:form >
03 <apex:pageBlock >
04
05 <apex:pageBlockButtons >
06 <apex:commandButton action="{!back}" value="Back"/>
07 </apex:pageBlockButtons>
08 <apex:pageMessages />
09
10 <apex:pageBlockSection title="You Selected" columns="1">
11 <apex:pageBlockTable value="{!selectedCategories}" var="c">
12 <apex:column value="{!c.cat.Name}"/>
13 </apex:pageBlockTable>
14 </apex:pageBlockSection>
15
16 </apex:pageBlock>
17 </apex:form>
18</apex:page>
controller class
01public class CategorySearchController {
02
03 // the results from the search. do not init the results or a blank rows show up initially on page load
04 public List<categoryWrapper> searchResults {get;set;}
05 // the categories that were checked/selected.
06 public List<categoryWrapper> selectedCategories {
07 get {
08 if (selectedCategories == null) selectedCategories = new List<categoryWrapper>();
09 return selectedCategories;
10 }
11 set;
12 }
13
14 // the text in the search box
15 public string searchText {
16 get {
17 if (searchText == null) searchText = 'acc'; // prefill the serach box for ease of use
18 return searchText;
19 }
20 set;
21 }
22
23 // constructor
24 public CategorySearchController() {}
25
26 // fired when the search button is clicked
27 public PageReference search() {
28
29 if (searchResults == null) {
30 searchResults = new List<categoryWrapper>(); // init the list if it is null
31 } else {
32 searchResults.clear(); // clear out the current results if they exist
33 }
34 // Note: you could have achieved the same results as above by just using:
35 // searchResults = new List<categoryWrapper>();
36
37 // dynamic soql
38 String qry = 'Select c.Name, c.Id From account c Where c.Name LIKE \'%'+searchText+'%\' Order By c.Name';
39
40 for(account c : Database.query(qry)) {
41 //new wrapper by passing it the category in the constructor
42 CategoryWrapper cw = new CategoryWrapper(c);
43 // wrapper to the results
44 searchResults.add(cw);
45 }
46 return null;
47 }
48
49 public PageReference next() {
50
51 // clear out the currently selected categories
52 selectedCategories.clear();
53
54 // add the selected categories to a new List
55 for (CategoryWrapper cw : searchResults) {
56 if (cw.checked)
57 selectedCategories.add(new CategoryWrapper(cw.cat));
58 }
59
60 // ensure they selected at least one category or show an error message.
61 if (selectedCategories.size() > 0) {
62 return Page.Category_Results;
63 } else {
64 ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Category.'));
65 return null;
66 }
67
68 }
69
70 // fired when the back button is clicked
71 public PageReference back() {
72 return Page.Category_Search;
73 }
74
75}
01public class CategoryWrapper {
02
03 public Boolean checked{ get; set; }
04 public account cat { get; set;}
05
06 public CategoryWrapper(){
07 cat = new account ();
08 checked = false;
09 }
10
11 public CategoryWrapper(account c){
12 cat = c;
13 checked = false;
14 }
15
16
17
18}
I want pagination for the records which are showing in dynamic wrapper list.
Please help me. Its urgent
Thanks in Advance
- Harsha Shri
- January 10, 2018
- Like
- 0
Error in External object SOQL Query
Hi All,
I am getting following when I am performing DML Operation
This is my code
Please help me in resolving this error
Thanks in Advance
I am getting following when I am performing DML Operation
System.ExternalObjectException: Salesforce System Error: 627698564-15996 (1450171494) (1450171494) : (System Code) Error is in expression '{!Search}' in component <apex:commandButton> in page cpm_lookup1: Class.CustomAccountLookupController.performSearch: line 34, column 1 Class.CustomAccountLookupController.runSearch: line 23, column 1 Class.CustomAccountLookupController.search: line 16, column 1
This is my code
public with sharing class CustomAccountLookupController { public Account account {get;set;} // new account to create public List<externalobj1__x> results{get;set;} // search results public string searchString{get;set;} // search keyword public CustomAccountLookupController() { account = new Account(); // get the current search string searchString = System.currentPageReference().getParameters().get('lksrch'); runSearch(); } // performs the keyword search public PageReference search() { runSearch(); return null; } // prepare the query and issue the search command private void runSearch() { // TODO prepare query string for complex serarches & prevent injections results = performSearch(searchString); } // run the search and return the records found. private List<externalobj1__x> performSearch(string searchString) { String soql = 'select id,externalid from externalobj1__x'; if(searchString != '' && searchString != null) soql = soql + ' where externalid LIKE \'%' + searchString +'%\''; soql = soql + ' limit 25'; System.debug(soql); return database.query(soql); } // save the new account record public PageReference saveAccount() { insert account; // reset the account account = new Account(); return null; } // used by the visualforce page to send the link to the right dom element public string getFormTag() { return System.currentPageReference().getParameters().get('frm'); } // used by the visualforce page to send the link to the right dom element for the text box public string getTextBox() { return System.currentPageReference().getParameters().get('txt'); } }
<apex:page controller="CustomAccountLookupController" title="Search" showHeader="false" sideBar="false" tabStyle="Account" id="pg"> <apex:form > <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel"> <!-- SEARCH TAB --> <apex:tab label="Search" name="tab1" id="tabOne"> <apex:actionRegion > <apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;"> <apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/> <apex:inputText id="txtSearch" value="{!searchString}" /> <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span> </apex:outputPanel> <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block"> <apex:pageBlock id="searchResults"> <apex:pageBlockTable value="{!results}" var="a" id="tblResults"> <apex:column > <apex:facet name="header"> <apex:outputPanel >Name</apex:outputPanel> </apex:facet> <apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.externalId}', false)" rendered="{!NOT(ISNULL(a.Id))}">{!a.externalid}</apex:outputLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel> </apex:actionRegion> </apex:tab> <!-- NEW ACCOUNT TAB --> <apex:tab label="New Account" name="tab2" id="tabTwo"> <apex:pageBlock id="newAccount" title="New Account" > <apex:pageBlockButtons > <apex:commandButton value="Save"/> </apex:pageBlockButtons> <apex:pageMessages /> <apex:pageBlockSection columns="2"> </apex:pageBlockSection> </apex:pageBlock> </apex:tab> </apex:tabPanel> </apex:outputPanel> </apex:form> </apex:page>
Please help me in resolving this error
Thanks in Advance
- Harsha Shri
- January 08, 2018
- Like
- 0
render VF page based on record type selection
Hi All,
I have the followwing VF page and controller class
when I am selecting selecting record type, VF page is not redering
Please help me if any correction need to do for above code
Thanks in Advance
I have the followwing VF page and controller class
<apex:page standardController="test__c" extensions="Recordtypes" id="pg"> <apex:form > <apex:pageBlock title="Recordtypes" id="pd"> <apex:selectList size="1" value="{!RecordTypes}" > <apex:actionSupport event="onchange" reRender="panel1,panel2" /> RecordTypes : <apex:selectOptions value="{!RecordTypes}"> </apex:selectOptions> </apex:selectList> <apex:outputPanel id="panel1"> <apex:pageBlockSection rendered="{!RecordTypes=='R1'}" > Field1 : <apex:inputText /> </apex:pageBlockSection> </apex:outputPanel> <apex:outputPanel id="panel2"> <apex:pageBlockSection rendered="{!RecordTypes=='R2'}" > Field2 : <apex:inputText /> </apex:pageBlockSection> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page>
public class Recordtypes { public list<selectoption> lstOfRectypes{set;get;} List<RecordType> recList; test__c t; ApexPages.StandardController controller; public Recordtypes (ApexPages.StandardController controller) { this.controller = controller; t = (test__c) Controller.getRecord(); } public list<SelectOption> getRecordTypes() { list<SelectOption> options = new list<SelectOption>(); for (list<RecordType> rts : [SELECT ID, name FROM RecordType WHERE SObjectType = 'test__c' ORDER BY name]) { for (RecordType rt : rts) { options.add(new SelectOption(rt.ID, rt.Name)); } } return options; } }I have written above code, to render VF page based on record type selection
when I am selecting selecting record type, VF page is not redering
Please help me if any correction need to do for above code
Thanks in Advance
- Harsha Shri
- January 03, 2018
- Like
- 0
Populate list values into apex:select
Hi All,
I am getting record types by using below list
List<RecordType> recList= new List<RecordType>([select id, name from recordtype where sobjecttype='obj1__c']);
I want to show this values in apex:select. How can I do this
I tried some ways, but not working.
Please help me
Thanks in Advance!!
I am getting record types by using below list
List<RecordType> recList= new List<RecordType>([select id, name from recordtype where sobjecttype='obj1__c']);
I want to show this values in apex:select. How can I do this
I tried some ways, but not working.
Please help me
Thanks in Advance!!
- Harsha Shri
- January 02, 2018
- Like
- 0