I want to create a keyword search referring to "UserName__c" api on Salesforce Apex class.
compile error Unexpected token 'UserName__c'.
public with sharing class AccountListCon {
static List<String> TARGET_FIELDS = new List<String>{
'Name'
,'UserName__c'
,'CompanyName__c'
};
public SearchCondition condition{ get;set; }
public String UserName__c results { get;set; }
public String sortingField { get;set; }
public void init(){
this.condition = new SearchCondition();
this.results = new String UserName__c();
}
public PageReference clear(){
init();
return null;
}
There is no such type String UserName__c. It's not entirely clear what you want to do here, but I suspect you intend just to declare a String variable. The fact that you're looking for values in some field whose API name is UserName__c is not relevant to the type system
public String UserName__c results { get;set; } is wrong. Is this supposed to be just
public String results { get;set; } ?
Related
I have some object like this:
public class ResponseBase
{
public string eventType { get; }
public string eventSourceGuid { get; }
}
public class QueryDevicesResponse : ResponseBase
{
public new static string eventType { get => "queryDevicesResponse"; }
public new string eventSourceGuid { get => "0"; }
public EventData eventData { get; set; }
}
eventType field is static because I'm trying to:
minimize lines of code
use it like "application-wide" string stored (in source code) together with DTO class definition, and use it in some switch and if statements without instantiating QueryDevicesResponse.
When I call:
QueryDevicesResponse queryDevicesResponse = QueryDevicesResponse.Mock();
JsonSerializer.Serialize.JsonSerializer.Serialize(queryDevicesResponse);
I'm getting JSON without eventType field. I guess this is because field is static.
Can I change JsonSerializer behavior to include also static fields?
This is similar question, but this is about Newtonsoft.Json:
Why can't JSON .Net serialize static or const member variables?
Alternatively:
How can I replace static modifier to get similar behavior and keep code small?
Requirement:
Trying to populate all UNIQUE record in Angular Drop Down List
I am using predefined Table have already data.
REST API URL => http://localhost:8080/getAllCategory
Facing Problem:
API is giving the reponse in JSON Array like [xxx,yyyy,zzzz]. So I am thinking if I can convert JSON Array with some label value which can solve my problem.
Either any other way to get over with this issue.
Note :
If I am not using the native query and using the below code then I am getting all the table value in JSON with label and populating all the record in drop down but I want only UNIQUE
#Repository
public interface CategoryRepository extends JpaRepository<ccCategory,Integer>
{}
My Implementation :
Model :
#Table(name = "cccategory")
public class ccCategory
{
#Id
#Column(name = "[catid]")
public Integer catID;
#Column(name = "[categoryname]")
public String categoryName;
#Column(name = "[active]")
public int active;
public ccCategory() {
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
public int getActive() {
return active;
}
public void setActive(int active) {
this.active = active;
}
}
Repository:
#Repository
public interface CategoryRepository extends JpaRepository<ccCategory,Integer>
{
public static final String FIND_CATEGORYNAME = "SELECT DISTINCT catID,categoryName from ccCategory";
#Query(value = FIND_CATEGORYNAME, nativeQuery = true)
List<ccCategory> getByactive(int active);
}
Controller :
#GetMapping("/getAllCategory")
public List<Object> getAllCategory() {
// public List<ccCategory> getAllCategory() {
System.out.println("***** Call : API getAllCategory() ******");
List<Object> cCategory = categoryRepository.getCategoryName();
return categoryData;
}
When I bind data with custom controller, the following code works well.
public class searchContactCtrl {
String searchText;
public String getSearchText(){
return searchText;
}
public void setSearchText(String s ){
searchText =s;
}
}
but if I changed getter method of "searchText" as below, an error was occured.
public class searchContactCtrl {
public String searchText{get;}
public void setSearchText(String s ){
searchText =s;
}
}
Error message:
Compile Error: member variable not visible for assignment
Why is this happening?
You will need to define a private setter for the searchText property. E.g.
public class searchContactCtrl {
public String searchText {
get;
private set;
}
public void setSearchText(String s) {
searchText = s;
}
}
Or you could just remove the private modifier and directly set searchText without the setSearchText method.
How do I obtain values of an array that is located inside a java object in a jsp page?
I have set an object attribute so that in the jsp page I can call the object like so
${obj.property}
My question is how would I obtain property String [] example from Object obj?
<c:forEach var="prop" items="${obj.example}">
<td>${prop}</td>
</c:forEach>
I get Errors that tell me the class obj.Obj does not have the property property 'example'
and obviously I don't get the data out.
Actual errors:
org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'roommate.Roommate' does not have the property 'favProfessors'.
javax.el.PropertyNotFoundException: The class 'roommate.Roommate' does not have the property 'favProfessors'
And my actual class:
package roommate;
public class Roommate{
public String firstname;
public String lastname;
public String gender;
public String place;
public String[] favProfessors;
public Roommate(String fname, String lname, String roommateGender, String hangout,String[] professors) {
firstname= fname;
lastname= lname;
gender= roommateGender;
place= hangout;
favProfessors= professors;
}
public String getFirstname()
{
return firstname;
}
public void setFirstname(String newFirstname)
{
this.firstname = newFirstname;
}
public String getLastname()
{
return lastname;
}
public void setLastname(String newLastname)
{
this.lastname = newLastname;
}
public String getGender()
{
return gender;
}
public void setGender(String newGender)
{
this.gender = newGender;
}
public String getHangout()
{
return place;
}
public void setHangout(String newPlace)
{
this.place = newPlace;
}
public String[] getProfessors()
{
return favProfessors;
}
public void setProfessors(final String[] newfavProfessors)
{
this.favProfessors = newfavProfessors;
}
public void addRoommate(String fname, String lname, String roommateGender, String hangout,String[] professors)
{
}
}
I create the object in my servlet as well ass the Atrribute
String [] profArray = request.getParameterValues("professor");
Roommate roommate= new Roommate(
session.getAttribute("fname").toString(),
session.getAttribute("lname").toString(),
session.getAttribute("gender").toString(),
session.getAttribute("hangout").toString(),
profArray);
session.setAttribute("roommate",roommate);
I asked this earlier but did not receive a clear answer. I think my issue is in pulling the data out in the jsp alone in my forEach that I mentioned at the top
javax.el.PropertyNotFoundException: The class 'roommate.Roommate' does not have the property 'favProfessors'
Java is right. You do not have a getFavProfessors() method in that class. It's instead the following:
public String[] getProfessors()
{
return favProfessors;
}
You have 2 options: use ${roommate.professors} instead, or fix the getter method name to be getFavProfessors().
In contrary to what most starters think, EL does not access private properties directly. EL just calls the public getter/setter methods according the Javabeans specification. The real private property behind it can have a completely different name or even not exist at all.
ok I have this (beginner again)
.
// ADD FRIEND TO FRIEND LIST
Query<FriendList> query1 = mongo.createQuery(FriendList.class);
query1.field("lowerCaseUserName").equal(on.lowerCaseUserName);
query1.field("passwordHash").equal(on.passwordHash);
query1.field("uuid").equal(on.uuid);
UpdateOperations<FriendList>up1=mongo.createUpdateOperations(FriendList.class).add("friendList",buddyUuid,false);
Im inserting a friend into the Array. The "friendList" is a String Array.
Would like to be able to implement removal now.
Can i just write the same code and replace the ".add" with removexxx...something?
Im thinking it's a good ide but maybe not :)
#Entity
public class FriendList {
#Id private ObjectId id;
public Date lastAccessedDate;
#Indexed(name="uuid", unique=true,dropDups=true)
private String uuid;
#Indexed(value=IndexDirection.ASC, name="lowerCaseUserName", unique=true,dropDups=true)
public String lowerCaseUserName;
public String passwordHash = "";
List<String> friendList;
public void setUuid(String uuid) {
this.uuid = uuid;
}
public List<String> getFriendList() {
return friendList;
}
public void insertFriend(String friend) {
this.friendList.add(friend);
}
// #PrePersist void prePersist() {
// lastAccessedDate = new Date();
// }
}
Query<FriendList> query1 = mongo.createQuery(FriendList.class);
query1.field("lowerCaseUserName").equal(on.lowerCaseUserName);
query1.field("passwordHash").equal(on.passwordHash);
query1.field("uuid").equal(on.uuid);
UpdateOperations<FriendList>up1=mongo.createUpdateOperations(FriendList.class).removeAll("friendList",buddyUuid);
This should remove the buddyUuid from the list.
If you could guarantee that the friendList contains unique UUID's then you could use removeFirst || removeLast method.
removeFirst/Last/All
Hope this helps!