• plai_highwire
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
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}"})