0

I have a custom button that when pressed, checks a field called "convert_to_service_catalogue__c".

This checkbox in combination with many other fields then triggers a process builder to fire.

I am finding that for users of a certain profile, the process builder doesn't fire. However there is nothing in the process builder criteria that restricts it by user logged in profile.

The error contains "a flow trigger failed to execute the flow with version id"

Interestingly. When I turn off the flow, the button works perfectly, so it seems there is something wrong with my process builder, but not sure what?

Below is the execute javascript for my button.

 {!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
 {!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

 var result = sforce.apex.execute("ProductAction","convertToService",

 {product2:"{!Product2.Id}"}); 
 window.location.href = '/'+result[0].Id+'/e';

 // Check result in console window 
 console.log(result[0]); 

 // If this result starts with a string equal to the id key for the object     

type you are accessing, relocate the browser to that page 
if (result[0].startsWith('001')) {
window.location.href = '/' + result[0] + '/e';
} else {
// Otherwise, show the error message to the viewer 
alert(result[0]);
}

Below that is the class for button.

global class ProductAction {
WebService static String convertToService(Id product2) {
    string result; // Return a string telling us if this worked or not
    Id currentProfile = UserInfo.getProfileId();  // Get the current user profile Id
    Id CurrentUser = UserInfo.getUserId(); // Get the current user Id

    Set<Id> allowedProfiles = new Set<Id>(); // Create a new set to profile Ids
    for (Profile p: [SELECT Id, Name FROM Profile WHERE Name = 'System Administrator']) {// Get the System Administrator profile
        allowedProfiles.add(p.Id); // Add them to the set
    }

    Set<Id> allowedUsers = new Set<Id>(); // Create a new set to store User Ids
    for (User u: [SELECT Id FROM User WHERE Id = '005w0000004j93kAAA' OR Id = '005w0000004Noi6']) {//Select Joy Palmer and Andy McGregor Id's and select Jeremey Sharp and Mark O'Leary once they're in SF}
        allowedUsers.add(u.Id);// Add them to the set
    }
    Product2 prod = [SELECT Convert_to_Service_catalogue__c, R_D_Service_Owner__r.id , Project_Owner__r.Id From Product2 WHERE Id = :product2]; // Get the product

    if( //If...
        (currentUser == prod.R_D_Service_Owner__r.id) || // They own it
        (currentUser == prod.Project_Owner__r.id) || // They own it 
        (allowedProfiles.contains(currentProfile)) || //They're a system admin
        (allowedUsers.contains(currentUser))// They're a specific user
        ) {
            //Do stuff!
            prod.Convert_to_Service_Catalogue__c = true;

            UPDATE prod;

            result = 'Success!';


        }   
    else {// Otherwise...
          // Do nothing
          result = 'Go Away!';
        }  
       // Return a message
       return result;
    }

}

  • 1
    the general solution here is in you need to populate all field used in process builder or else it will throw error. So check for field some fields might be blank. Also you should receive an email(if you are the admin) check that you will get more details from email. – Tushar Sharma Nov 15 '16 at 17:12
1

Add a try catch exception in your Code, and return the ErrorMessage.

Your code can throw Exception

global class ProductAction {
WebService static String convertToService(Id product2) {
    string result; // Return a string telling us if this worked or not
    try{
        Id currentProfile = UserInfo.getProfileId();  // Get the current user profile Id
    Id CurrentUser = UserInfo.getUserId(); // Get the current user Id

    Set<Id> allowedProfiles = new Set<Id>(); // Create a new set to profile Ids
    for (Profile p: [SELECT Id, Name FROM Profile WHERE Name = 'System Administrator']) {// Get the System Administrator profile
        allowedProfiles.add(p.Id); // Add them to the set
    }

    Set<Id> allowedUsers = new Set<Id>(); // Create a new set to store User Ids
    for (User u: [SELECT Id FROM User WHERE Id = '005w0000004j93kAAA' OR Id = '005w0000004Noi6']) { //Select Joy Palmer and Andy McGregor Id's and select Jeremey Sharp and Mark O'Leary once they're in SF
        allowedUsers.add(u.Id);// Add them to the set
    }
    Product2 prod = [SELECT Convert_to_Service_catalogue__c, R_D_Service_Owner__r.id , Project_Owner__r.Id From Product2 WHERE Id = :product2]; // Get the product

    if( //If...
        (currentUser == prod.R_D_Service_Owner__r.id) || // They own it
        (currentUser == prod.Project_Owner__r.id) || // They own it 
        (allowedProfiles.contains(currentProfile)) || //They're a system admin
        (allowedUsers.contains(currentUser))// They're a specific user
        ) {
            //Do stuff!
            prod.Convert_to_Service_Catalogue__c = true;

            UPDATE prod;

            result = 'Success!';


        }   
    else {// Otherwise...
          // Do nothing
          result = 'Go Away!';
        }  
       // Return a message
       return result;
    }
}catch(Exception ex){
    result = 'Error! '+ ex.getMessage();
    return result;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.