You need to sign in to do that
Don't have an account?
plai_highwire
executing apex via a custom button
I have a junction object called Predecessor Cases that has two lookup fields back to cases. The two fields are called successor case and predecessor case.
I created a custom button that executes some apex code. When i click on the custom button, nothing is happening. Am I not passing the right info to execute the apex code?
Apex Class:
global class AdjustDate {
WebService static void AdjustDate(Id CaseId){
Set<ID> sid = new Set<ID>();
Integer DaysToAdd = 1;
//Get a list of all Predecessor objects that has a match on the predecessor field to the case ID
List<Predecessor_Case__c> successor = [SELECT ID,Predecessor_Case__c, Successor_Case__c, Successor_case__r.id FROM Predecessor_Case__c WHERE Predecessor_Case__r.id =: CaseId ];
//Add the successor case ids that match those predecessor cases to a set
for(Predecessor_Case__c pc : successor){
sid.add(pc.Successor_Case__r.id);
}
//Get a list of all cases that match that of the sid
List<Case> successcases = [SELECT ID, Estimated_Launch_Date__c, Days_To_Add__c FROM Case WHERE ID IN: sid];
// Do the calculations for those cases
for(Case c: successcases){
c.Estimated_Launch_Date__c += DaysToAdd;
c.Actual_Approval_Date__c = date.today();
}
}
}
Custom button:
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
sforce.apex.execute(
"AdjustDate",
"adjustdate",
{id:"{!Case.Id}"})
I created a custom button that executes some apex code. When i click on the custom button, nothing is happening. Am I not passing the right info to execute the apex code?
Apex Class:
global class AdjustDate {
WebService static void AdjustDate(Id CaseId){
Set<ID> sid = new Set<ID>();
Integer DaysToAdd = 1;
//Get a list of all Predecessor objects that has a match on the predecessor field to the case ID
List<Predecessor_Case__c> successor = [SELECT ID,Predecessor_Case__c, Successor_Case__c, Successor_case__r.id FROM Predecessor_Case__c WHERE Predecessor_Case__r.id =: CaseId ];
//Add the successor case ids that match those predecessor cases to a set
for(Predecessor_Case__c pc : successor){
sid.add(pc.Successor_Case__r.id);
}
//Get a list of all cases that match that of the sid
List<Case> successcases = [SELECT ID, Estimated_Launch_Date__c, Days_To_Add__c FROM Case WHERE ID IN: sid];
// Do the calculations for those cases
for(Case c: successcases){
c.Estimated_Launch_Date__c += DaysToAdd;
c.Actual_Approval_Date__c = date.today();
}
}
}
Custom button:
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
sforce.apex.execute(
"AdjustDate",
"adjustdate",
{id:"{!Case.Id}"})
The name of your parameter is CaseId not id
Your method name should be AdjustDate not adjustdate
I also assume that you put the button in a case layout not in a predecessor case layout. otherwise the {!Case.Id} wont work.
You could also update the api version to something newer just in case there has been some bug fix :
Custom button:
{!REQUIRESCRIPT("/soap/ajax/28.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/28.0/apex.js")}
sforce.apex.execute(
"AdjustDate",
"AdjustDate",
{CaseId:"{!Case.Id}"})