i'm trying to write an apex class that checks a chekbox, on a custom object when a specific Date is less than 30 days from todays date. The class is supposed to run once a week to constantly check for Records that are supposed to be updated. I have absolutely no knowledge in Apex and my code is made up from various snippeds that I found in other Threads. I think I almost got it, but it keeps showing this error message: Method does not exist or incorrect signature: void DateCheck() from the type CustomersDateCheck.
Can somebody help me out here?
global class CustomersDateCheck implements Schedulable {
global void execute(SchedulableContext sc) {
DateCheck();}
public static void DateCheck(Customers__c[] objects){
for(Customers__c obj: objects){
if(obj.DateField > Date.today()){
continue;
}
else{
obj.FlowUpdateHelper__c = true;
}
}
}
}
Thanks in advance!
please pass the parameter in the function call that you are calling inside the execute method.
DateCheck(pass parameter)
Pass the List by query to customer object to fetch the required records.
e.g.
global void execute(SchedulableContext sc) {
List<Customers__c> customersList = [SELECT Id FROM Customers__c];
DateCheck();
}
OR
global void execute(SchedulableContext sc) {
Customers__c[] customersList = [SELECT Id FROM Customers__c];
DateCheck(customersList);
}
Related
How would you implement a matching system to check when two values are the same in one collection from different documents? This code has to call a function to run every-time it detects that the two values are matching.
As mentioned in the documentation :
Cloud Firestore provides powerful query functionality for specifying which documents you want to retrieve from a collection or collection group. These queries > can also be used with either get() or addSnapshotListener(), as described in Get Data and Get Realtime Updates.
I will recommend you to use a unique identifier for each entry and then you can add a listener that will match each data from the collections.
Syntax :
query.addListenerForSingleValueEvent(new ValueEventListener() {
#Override public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
// dataSnapshot is the "issue" node with all children with id 0
for (DataSnapshot issue : dataSnapshot.getChildren()) {
// do something with the individual "issues"
} } }
You can refer to the Stackoverflow answer where Frank has explained it briefly with the following function code.
public interface AlreadyBookedCallback {
void onCallback(boolean isAlreadyBooked);
}
private void alreadyBooked(final String boname, final String bodept, final String botime, AlreadyBookedCallback callback) {
CollectionReference cref=db.collection("bookingdetails");
Query q1=cref.whereEqualTo("time",botime).whereEqualTo("dept",bodept);
q1.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
#Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for (DocumentSnapshot ds : queryDocumentSnapshots) {
String rname, rdept, rtime;
rname = ds.getString("name");
rdept = ds.getString("dept");
rtime = ds.getString("time");
if (rdept.equals(botime)) {
if (rtime.equals(botime)) {
isExisting = true;
}
}
}
callback.onCallback(isExisting)
}
});
}
For more information you can also refer to this thread on how to check duplicate values in documents.
I have a keyd stream of data that looks like:
{
summary:Integer
uid:String
key:String
.....
}
I need to aggregate the summary values in some time range, and once I achieved a specifc number , to flush the summary and all the of the UID'S that influenced the summary to database/log file.
after the first flush , I want to discare all the uid's from the memory , and just flush every new item immediatelly.
So I tried this aggregate function.
public class AggFunc implements AggregateFunction<Item, Acc, Tuple2<Integer,List<String>>>{
private static final long serialVersionUID = 1L;
#Override
public Acc createAccumulator() {
return new Acc());
}
#Override
public Acc add(Item value, Acc accumulator) {
accumulator.inc(value.getSummary());
accumulator.addUid(value.getUid);
return accumulator;
}
#Override
public Tuple2<Integer,List<String>> getResult(Acc accumulator) {
List<String> newL = Lists.newArrayList(accumulator.getUids());
accumulator.setUids(Lists.newArrayList());
return Tuple2.of(accumulator.getSum(), newL);
}
#Override
public Acc merge(Acc a, Acc b) {
.....
}
}
and in the aggregate process function , I flush the list to state, and if I need to save to dataBase I'm clearing the state and save flag in the state to indicate it.
But it seems crooked to me. And I'm not sure if that would work well for me.
Is there a better solution to this situation?
Work with a state inside a rich function. Keep adding the uid in your state and when the window triggers to flush the values. This page from the official documentation has an example.
https://ci.apache.org/projects/flink/flink-docs-release-1.11/dev/stream/state/state.html#using-keyed-state
For your case a ListState will work well.
EDIT:
The solution above is for non-window case. for window case simply use the aggrgation with apply function that can have a rich window function
I am currently using selenium with Java,And want to implement cucumber to make test script more readable.
Currently facing issue while passing argument to java method where Enum is expected as parameter.
I would also like to know if there are any other known limitations of cucumber-java before migrating current framework.
The answer is: Yes
You can use all kind of different types in your scenario: primitive types, own classes (POJOs), enums, ...
Scenario :
Feature: Setup Enum and Print value
In order to manage my Enum
As a System Admin
I want to get the Enum
Scenario: Verify Enum Print
When I supply enum value "GET"
Step definition code :
import cucumber.api.java.en.When;
public class EnumTest {
#When("^I supply enum value \"([^\"]*)\"$")
public void i_supply_enum_value(TestEnum arg1) throws Throwable {
testMyEnum(arg1);
}
public enum TestEnum {
GET,
POST,
PATCH
}
protected void testMyEnum(TestEnum testEnumValue) {
switch (testEnumValue) {
case GET:
System.out.println("Enum Value GET");
break;
case POST:
System.out.println("Enum Value POST");
break;
default:
System.out.println("Enum Value PATCH");
break;
}
}
}
Let me know how you are doing. I could try to help you.
This youtube lecture of about 11 minutes gives a good way of doing it.
https://www.youtube.com/watch?v=_N_ca6lStrU
For example,
// enum, obviously in a separate file,
public enum MessageBarButtonType {
Speak, Clear, Delete, Share
}
// method for parameter type. if you want to use a different method name, you could do #ParameterType(name="newMethodName", value="Speak|Clear|Delete|Share") according to the video.
#ParameterType("Speak|Clear|Delete|Share")
public MessageBarButtonType MessageBarButtonType(String buttonType) {
return MessageBarButtonType.valueOf(buttonType);
}
// use like this. the name inside {} should match the name of method, though I just used the type name.
#Then("Select message bar {MessageBarButtonType} button")
public void select_message_bar_button(MessageBarButtonType buttonType) {
...
}
First register a transformer based on an ObjectMapper, then you can just use enums as would be expected.
private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule());
#DefaultParameterTransformer
#DefaultDataTableEntryTransformer
#DefaultDataTableCellTransformer
public Object defaultTransformer(Object fromValue, Type toValueType) {
JavaType javaType = objectMapper.constructType(toValueType);
return objectMapper.convertValue(fromValue, javaType);
}
Scenario: No.6 Parameter scenario enum
Given the professor level is ASSOCIATE
#Given("the professor level is {}")
public void theProfessorLevelIs(ProfLevels level) {
System.out.println(level);
System.out.println("");
}
public enum ProfLevels {
ASSISTANT, ASSOCIATE, PROFESSOR
}
Source
This is no more supported in latest io.cucumber maven group
https://github.com/cucumber/cucumber-jvm/issues/1393
I have WPF application and my work method play my files in different threads
This is my Global variable that update my UI:
public static int _totalFilesSent;
Now because i am implement INotifyPropertyChanged in my model i have also this:
public static int TotalFilesSent
{
get { return _totalFilesSent; }
set
{
_totalFilesSent = value;
OnStaticlPropertyChanged("TotalFilesSent");
}
}
(i didn't add the event function because this is not relevant here).
So every time i am update my Global variable this way:
Interlocked.Increment(ref _totalFilesSent );
Now because i need to update my UI with my INotifyPropertyChanged event i need to use TotalFilesSent instead of _totalFilesSent but in this way i got this compilation error:
A property, indexer or dynamic member access may not be passed as an
out or ref parameter.
What does it mean and how can i solved it ?
You may easily raise the StaticPropertyChanged event after calling Interlocked.Increment:
private static int _totalFilesSent;
public static int TotalFilesSent
{
get { return _totalFilesSent; }
}
public static void IncrementTotalFilesSent()
{
Interlocked.Increment(ref _totalFilesSent);
OnStaticPropertyChanged("TotalFilesSent");
}
first, I was only trying to update a modified model. Lets say, we talk about "Article" as a model.
The following method is implemented in a class called "Articles":
public static void SaveArticle(Article article)
{
if (article.Id == 0)
{
webEntities.Articles.Add(article);
}
else
{
webEntities.Articles.Attach(article);
webEntities.Entry(article).State = EntityState.Modified;
}
webEntities.SaveChanges();
}
So whenever I want to save an modified article in a controller action, I just have to call "Articles.SaveArticle(myArticle);", which works as expected.
So far so good but this means I would need to implement this redundantly for every model/entity.
Then I thought about something like a template-pattern. I.e. a class called "Entity" where "Article" inherits from "Entity".
Furthermore, a class called "Entities" contains a static method like this:
public static void SaveEntity(Entity entity)
{
if (Entity.Id == 0) // <-- Problem 1
{
webEntities.Entities.Add(entity); // <-- Problem 2
}
else
{
webEntities.Entities.Attach(entity); // <-- Problem 3
webEntities.Entry(entity).State = EntityState.Modified; // <-- Problem 4
}
webEntities.SaveChanges();
}
So I would not need to implement it redundantly but I don't know how to solve the problems mentioned in the code above.
Do I think too complicated or what would be a best practice to my problem?
Thanks in advance!
Kind regards
Use generics.
public static void Save<T>(T entity)
where T : class
{
webEntities.Set<T>().AddOrUpdate(entity);
webEntities.SaveChanges();
}
AddOrUpdate is an extension method in System.Data.Entity.Migrations.