I have a method (not a wire, because its not possible), that are supposed to retrieve new data every time I click a button. But it only give me the same data that I got when i clicked the button the first time.
But when I refresh the whole page and click the button, then I get the new data that I want when I click the button. But when I click again, I get the same data as I got after I clicked the button the first time after refresh.
I have removed (cacheable=true), so I have no idea how to do this. Does anyone have any idea? Even thought this.serviceAppointment.Id value changes, I still get the same data as the first time method is called.
Problem: It makes a new thread every time I click the button because it wont get the new thread Id after the first time
Apex:
public static String getThreadFreelanceId(String serviceAppointmentId) {
String Id='';
ServiceAppointment serviceAppointment=[SELECT HOT_WorkOrderLineItem__r.WorkOrderId FROM ServiceAppointment WHERE Id=:serviceAppointmentId];
try{
Thread__c thread = [SELECT Id FROM Thread__c WHERE CRM_Related_Object__c=:serviceAppointment.HOT_WorkOrderLineItem__r.WorkOrderId LIMIT 1];
if (thread.Id != null) {
Id=thread.Id;
return Id;
}
return Id;
}catch(Exception E){
}
return Id;
}
Method that is called when button click:
goToThread() {
getThreadFreelanceId({ serviceAppointmentId: this.serviceAppointment.Id }).then((result) => {
if (result != '') {
this.freelanceThreadId = result;
} else {
createThread({ recordId: this.serviceAppointment.Id, accountId: this.serviceAppointment.accountId })
.then((result) => {
this.freelanceThreadId = result;
})
.catch((error) => {
});
}
});
}