• Josh Davis 13
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 4
    Questions
  • 2
    Replies
I'd like to have a list button to update a multi-select picklist field. The javascript below runs when I click it on a related contact list on an account page (I get the alert with the Id), but the checked record does not update. I suspect it's due to the multi-select field type, because this code worked for regular picklist in this answer.
I have enabled Account Contact Relationships, and want to update the Roles field in that object with a text value ("Former resident"). Here's the code:
{!REQUIRESCRIPT('/soap/ajax/30.0/connection.js')}

try{
    var selectedRecords = {!GETRECORDIDS( $ObjectType.AccountContactRelation )};
    if(selectedRecords.length > 0){
        var recordsToUpdate = [];
        for(var i = 0; i < selectedRecords.length; i++){
            var record = new sforce.SObject("AccountContactRelation"); 
 
            record.Id = selectedRecords[i];
            record.Roles = 'Former resident;'; /* also tried without inner semicolon */
            recordsToUpdate.push(record);
alert('Updated ' + selectedRecords[i] );  /* this works */
        }

        var result = sforce.connection.update(recordsToUpdate);  /* this doesn't work */

        location.reload();
    }
    else{
        alert('Please select at least one row');
    }
}
catch(e){
    alert(e);
}
I have a workflow that updates a Contact field when an Account field changes.
I also have a trigger that fires when a Contact is updated, IF this is true:
    if(!system.isBatch() && !system.isFuture() && TriggerExecution.isNew()) {
Both work on their own, but when the workflow updates a record, it doesn't fire the trigger.
Which of those three criteria would hold it up?
I'm new to VisualForce, so likely missing something simple. I have a simple flow that looks up a contact, and if it finds a match writes the matching contact.id to a text variable. I know this works because in a later step I refer to the variable to update the existing record. But I want this workflow to go to the lookup record when it's done. It sounds like the best way to do that is setting the finishlocation to a page reference that pulls the variable from the workflow. But that page reference keeps coming up null--so the variable value isn't getting pulled into the controller.

Here's my page. "HES_signup_test" is the name of the otherwise working workflow:
<apex:page controller="HESFlowToSchedule">
 <flow:interview name="HES_signup_test" interview="{!myflow}" finishlocation="{!ContactPage}">
  </flow:interview>
</apex:page>

Here's my controller, copied from an example at https://developer.salesforce.com/forums/?id=906F0000000QtIxIAK. "PassToSO" is the flow variable name.
public class HESFlowToSchedule {
    public Flow.Interview.HES_signup_test myflow {get; set;}
    public PageReference ContactPage {
        get {
            PageReference pageRef = new PageReference('/' + flowContactId );
            pageRef.setRedirect(true);
            return pageRef;
        }
        set { ContactPage = value; }
    }
    public String flowContactId {
        get {
            String strTemp = '';
            if(myflow != null) {
                strTemp = myflow.PassToSO; //also tried string.valueOf(myflow.getVariableValue('PassToSO'));
            }
            return strTemp;
        }
        set { flowContactId = value; }
    }
}
In this example, logs show StrTemp ends up null, even though PassToSO is successfully used in the workflow. PassToSO is set for Input and Output use.

I also tried this second construction, from https://developer.salesforce.com/docs/atlas.en-us.208.0.pages.meta/pages/pages_flows_advanced.htm:
public class HESFlowToSchedule {
    public Flow.Interview.HES_signup_test myflow {get; set;}
    public PageReference getcontactPage() {
        String apexPassToSO;
        if (myFlow==null) { return new PageReference('/0030q000001xgYH');}
        else {
            apexPassToSO = (String) myFlow.getVariableValue('PassToSO');
            if (apexPassToSO==null) {return new PageReference('/0033700000SEGA8');}
           else {
                return new PageReference('/' + apexPassToSO);
            }
        }
    }
and it pulled a null value.

Then I tried this, from https://help.salesforce.com/articleView?id=pages_flows_getting_values.htm&language=en_US&type=0, with same failure.
public class GetPassToSO {
    public Flow.Interview.HES_signup_test myflow { get; set; }
    public String apexPassToSO;
    public String getApexPassToSO() {
        return myflow.PassToSO;
    }
}
What am I missing?  Thanks for any clues!
I have a user who imports data in our production instance, and I wrote a scheduled apex to process that data. The most sure way to query the records to process is to use the user's LastModifiedById. However, I have to write and test the code in our sandbox, and test 75%+ to deploy to production. The user's production Id isn't recognized in sandbox, so no records are found and not enough of the code gets tested. How would you work around this?
I'd like to have a list button to update a multi-select picklist field. The javascript below runs when I click it on a related contact list on an account page (I get the alert with the Id), but the checked record does not update. I suspect it's due to the multi-select field type, because this code worked for regular picklist in this answer.
I have enabled Account Contact Relationships, and want to update the Roles field in that object with a text value ("Former resident"). Here's the code:
{!REQUIRESCRIPT('/soap/ajax/30.0/connection.js')}

try{
    var selectedRecords = {!GETRECORDIDS( $ObjectType.AccountContactRelation )};
    if(selectedRecords.length > 0){
        var recordsToUpdate = [];
        for(var i = 0; i < selectedRecords.length; i++){
            var record = new sforce.SObject("AccountContactRelation"); 
 
            record.Id = selectedRecords[i];
            record.Roles = 'Former resident;'; /* also tried without inner semicolon */
            recordsToUpdate.push(record);
alert('Updated ' + selectedRecords[i] );  /* this works */
        }

        var result = sforce.connection.update(recordsToUpdate);  /* this doesn't work */

        location.reload();
    }
    else{
        alert('Please select at least one row');
    }
}
catch(e){
    alert(e);
}
Hi

I am trying to create a custom button that will create a new event with a prepopulated field but I keep getting the error that my url is not valid. Can someone please help. Here is the URL.

https://cs18.salesforce.com/00U/e?who_id={!Case.AccountId}&what_id={!Case.Id}&retURL=%2F{!Case.Id}&RecordType=0122000000061K7&ent=Event&evt6={!Case.Description}
  • July 29, 2014
  • Like
  • 0
I have a working controller (below) that passes a variable from a flow to a destination URL (finishlocation) when the flow is complete.

As I am still learning APEX, can someone explain how I can get more than one variable from the flow and add it as parameters to my finishlocation?

For example:

PageReference pageRef = new PageReference('/' + flowContactId + ? + Id2 + & + Id3 )....etc.

THANK YOU


Controller:

public class SurveyFlowController {
public Flow.Interview.Survey_Flow_Test myflow {get;set;}
    
// Set the page reference accessor methods
public PageReference finishlocation {
get {
PageReference pageRef = new PageReference('/' + flowContactId );
pageRef.setRedirect(true);
return pageRef;
}
set { finishlocation = value; }
}
 
// Set the accessor methods for the flow output variable

public String flowContactId {
get {
String strTemp = '';
 

if(myflow != null) {
strTemp = string.valueOf(myflow.getVariableValue('varContactID'));
}
return strTemp;
}
set { flowContactId = value; }

}
}


Visualforce Button:
<apex:page Controller="SurveyFlowController" > <flow:interview name="Survey_Flow_Test" interview="{!myflow}" finishlocation="{!finishlocation}" /> </apex:page>
I've got an email template with various merge fields, one of which is the Event Time, however, it refuses to push the event time through into the email. Other non-event merge fields work fine (Contact name, User name, account name etc). It appears that the issue is because Events don't have a standard parent-child relationship with other objects and because you can't send an email directly from an Event but have to do it from an Account/Opportunity.

All I want to be able to do is book an event, and then have an email template that includes the date & time of the event to send to the customer.

Is there a workaround that can be used for this?
Hi All,

I am trying to create a button that converts a case to an opportunity, but have ran into a bit of a brickwall

When I click the button I get the following error

 A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:,soapenv:Client',faultstring:"03/08/2014' is not a valid value for the type xsd:date',}


The status of the case changes but the opportunity is not created, here is the code I have but not sure if it works totally as can't get past the date issue.

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var caseObj = new sforce.SObject("Case");
   caseObj.Id = '{!Case.Id}';
   caseObj.Status = 'Converted to Opportunity';
var result = sforce.connection.update([caseObj]);
var status = "{!Case.Status}}";
var newRecords = [];
{
   var o = new sforce.SObject("Opportunity");
   o.AccountId = '{!Case.AccountId}';
   o.Type = '{!Case.Type}';
   o.Name = '{!Case.CaseNumber},{!Case.Subject}';
   o.LeadSource = '{!'Converted from Case'}';
   o.Description = '{! Case.Description }';
   o.OwnerId = '{!Account.OwnerId}';
   o.StageName = '{!'Perception Analysis'}';
   o.CloseDate = '{! TODAY() +30}';
newRecords.push(o);
}
var result = sforce.connection.create(newRecords);

if (result[0].success == 'false') {
    alert(result[0].errors.message);
} else {
    parent.ID = '{!Case.ParentId}';
    window.parent.location = ('/00a/e?parent_id=retURL=/{!Case.Id}');}


I know the issue is from the o.CloseDate = '{! TODAY() +30}'; but just can't workout what it should be.

Thanks