• bigga
  • NEWBIE
  • 20 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 20
    Replies
I have a button on opportunities to send an email to the primary contact role for that opportunity. I'm trying to add the Opportunity Description to that email.

This works:
<messaging:emailTemplate subject="Your recent order" recipientType="Contact" replyTo="myemail@mydomain.com" relatedToType="Opportunity">
<messaging:plainTextEmailBody >
Hi {!Recipient.Firstname} -

Last year around this time you ordered XXX from us at Our Company. Is it time to do that again?

Please let me know if I can help you with anything. Thanks!

</messaging:plainTextEmailBody>
</messaging:emailTemplate>

But I have to manually replace XXX with the opportunity description. Adding {!Opportunity.Description} to the template gives me this error:

Error: Unknown property 'core.email.template.EmailTemplateComponentController.Opportunity'

How can I include this Descriiption in an email? 
  • February 10, 2014
  • Like
  • 0

I've munged together an applescript to create an opportunity in Salesforce, assigning a contact and contact role.

-- beginning of applescript


tell application "SalesforceScripting"
activate
set session to login with saved credentials

-- request a partial account name, then present a list of accounts for the opportunity to relate to

set startsWith to text returned of (display dialog "Search Accounts" default answer "Enter Partial Account Name")
set res to query session soql "select id, name from account where name like '%" & startsWith & "%'"

set L to (get every SObject of res)
set MyAcctList to {}
repeat with row in L
set end of MyAcctList to row value of "Name"
end repeat
try
if (count of items of MyAcctList) is greater than or equal to 1 then
set AccountName to (choose from listMyAcctListwith prompt "Which Account?" OK button name "This one!" cancel button name "Cancel" without multiple selections allowed) as list
else if (count of items of MyAcctList) is equal to 0 then
beep
display dialog "No Such Account Exists" buttons {"OK"} default button 1
return
end if
on error errMsg number errnum
display dialogerrnum
end try

--get the associated Account ID from the Account Name

set res2 to query session soql "select id, name from account where name = '" & AccountName & "'"
set L to (get every SObject of res2)
repeat with row in L
set AcctId to rowvalueof "Id" -- the Salesforce.com Acct Id
end repeat

--get the associated Contact Name from the Account Id you just selected

set res3 to query session soql "select id, name from contact where AccountId = '" & AcctId & "'"
set Contacts to (get every SObject of res3)
set ContList to {}
repeat with row in Contacts
set end of ContList to row value of "Name"
end repeat

-- present a list of related contacts for the account, for the particular opportunity

try
if (count of items of ContList) is greater than or equal to 1 then
set ContactName to (choose from listContListwith prompt "Which Contact?" OK button name "This one!"cancel button name "Cancel" without multiple selections allowed) as text
else if (count of items of ContList) is equal to 0 then
beep
display dialog "No Contacts Found" buttons {"OK"} default button 1
return
end if
on error errMsg number errnum
display dialogerrnum
end try

--get the associated Contact ID from the Contact Name

set res4 to query session soql "select id, name from contact where name = '" & ContactName & "'"
set L to (get every SObject of res4)
repeat with row in L
set ContactId to rowvalueof "Id" -- the Salesforce.com Acct Id
end repeat

--then build the Opportunity in Salesforce.com

delay 3

set opp to makeSObject
set type of opp to "Opportunity"
opp setField named "Name" to CustName & " " & OrderNum -- required
opp setField named "AccountId" to AcctId as text -- required
opp setField named "StageName" to "Prospecting" -- required
oppsetFieldnamed "CloseDate" toCloseDate-- as date -- required

set res5 to sessioncreatesobjectsopp
Id of first item of res5
set NewOppID to Id of first item of res5 as text

display dialogNewOppID

--and Assign a Contact & ContactRole

set opprole to makeSObject
set type of opprole to "OpportunityContactRole"
opprole setField named "OpportunityId" to NewOppID
opprole setField named "ContactId" to ContactId
opprole setField named "Role" to "Decision Maker"
set res6 to sessioncreatesobjectsopprole

end tell

-- end of applescript

However if the contact's name as an apostrophe (O'Leary) then the script fails. I also still have the issue when creating a contact with a 4-character name (Marc) the entry in SF becomes "0"

  • September 30, 2011
  • Like
  • 0

This script has issues:

 

tell application "SalesforceScripting"
	activate
	
	set CustName to "Smithtown"
	set OrderNum to "123456"
	set session to login with saved credentials
	
	set opp to make SObject
	set type of opp to "Opportunity"
	
	(* THESE are REQUIRED Opportunity Fields - the Opportunity is not created if these 4 objects don't have values *)
	
	opp setField named "Name" to "blahblah2" -- text returned of (display dialog "Name This" default answer "") -- as text -- will be filled by a variable
	opp setField named "StageName" to "Prospecting"
	opp setField named "CloseDate" to "2011-07-10"
	
	(* THESE are Custom Opportunity Fields - anything written via applescript, and the "Create SObjects" instruction fails - no opportunity created *)
	
	--	opp setField named "Opp_Name_20__c" to "123456 BLAH BLAH" -- Eventually will filled with these variables: OrderNum & " " & CustName
	--	opp setField named "PDS__PO_Number__c" to "123456"  -- variable OrderNum
	--	opp setField named "PDS__Document_Number__c" to "123456" -- variable OrderNum
	--	opp setField named "PDS__Invoice_Number__c" to "123456" -- variable OrderNum
	
	set res5 to session create sobjects opp
	Id of first item of res5
	set NewOppID to Id of first item of res5 as text
	
end tell

 

Inserting anything into the custom opportunity fields causes the script to fail. I can understand having "required" fields, like name, but I should be able to fill custom fields with my own data.

 

  • July 11, 2011
  • Like
  • 0

Though lots of many nights and trial and error with various syntax, I've munged together a set of scripts that help me integrate with Salesforce via Applescript. Many thanks to Simon and all the folks that have put these mac tools together for us to use and and abuse.

 

I thought I'd had everything licked, but then came upon a discovery - the script that I'd used to take data from Address Book and create accounts and contacts was inserting a "0" where the last name should go in the Contact record.

 

Here's the code:

 

tell application "SalesforceScripting"
	activate
	set session to login with saved credentials
	
	set ContactFirstName to "Joe"
	set ContactLastName to "Blow"
	
	set cont to make SObject
	set type of cont to "Contact"
	cont setField named "FirstName" to ContactFirstName
	cont setField named "LastName" to ContactLastName
	--	cont setField named "AccountId" to NewAccountID
	--	cont setField named "PDS__Primary_Contact__c" with to
	--	cont setField named "Email" to EmailAddy
	
	set res2 to session create sobjects cont
	set NewContactID to Id of first item of res2
	
	open location "https://na9.salesforce.com/" & NewContactID
	
end tell

 

Here's the results of that script from the AS Log:

 

tell application "SalesforceScripting"
	activate
	login with saved credentials
		--> UserSession id "us_31068"
	make new SObject
		--> SObject id "row_31070"
	set type of SObject id "row_31070" to "Contact"
	setField SObject id "row_31070" named "FirstName" to "Joe"
	setField SObject id "row_31070" named "LastName" to "Blow"
	create UserSession id "us_31068" sobjects SObject id "row_31070"
		--> {SaveResult id "sr_31071" of UserSession id "us_31068"}
	get Id of SaveResult id "sr_31071" of UserSession id "us_31068"
		--> "003E0000005uds7IAA"
	open location "https://na9.salesforce.com/003E0000005uds7IAA"
end tell

 

If I hard code the ContactLastName, like:

 

cont setField named "LastName" to "Blow"

 the log returns an identical result, and the record is written properly to Salesforce.com. But if "LastName" is written with a variable, I get a big fat ZERO.

 

Any clues?

 

 

 

  • July 11, 2011
  • Like
  • 0

I was thrilled to find this:

 

tell application "SalesforceScripting"
	set mySession to login username "myemail@mydomain.com" password "passwordtokenhere"
	
	--  Create a new Account in Salesforce
	
	set acc to make SObject
	set type of acc to "Account"
	acc setField named "Name" to "3 New Test Account"
	acc setField named "PDS__QB_Billing_Address__c" to "3 New Test Account
John Doe
123 Main Street
Arlington, TX 75007"
	acc setField named "Phone" to "(888) 555-6666"
	set res to mySession create sobjects acc
	Id of first item of res
	
end tell

 


And It works like a champ. I've spent the last couple of hours scouring the net and the script library trying to find out how to use something similar, or to add to it, so that I can create an Opportunity and Contact by adding some instructions to this.

 

I'm stuck. I guess I don't know enough about Apex and the SF system yet to read what needs to be in the script.

 

Any insight as to how to add Accounts/Contacts/Opportunities at the same time would be greatly appreciated.

  • June 28, 2011
  • Like
  • 0
I have a button on opportunities to send an email to the primary contact role for that opportunity. I'm trying to add the Opportunity Description to that email.

This works:
<messaging:emailTemplate subject="Your recent order" recipientType="Contact" replyTo="myemail@mydomain.com" relatedToType="Opportunity">
<messaging:plainTextEmailBody >
Hi {!Recipient.Firstname} -

Last year around this time you ordered XXX from us at Our Company. Is it time to do that again?

Please let me know if I can help you with anything. Thanks!

</messaging:plainTextEmailBody>
</messaging:emailTemplate>

But I have to manually replace XXX with the opportunity description. Adding {!Opportunity.Description} to the template gives me this error:

Error: Unknown property 'core.email.template.EmailTemplateComponentController.Opportunity'

How can I include this Descriiption in an email? 
  • February 10, 2014
  • Like
  • 0

This script has issues:

 

tell application "SalesforceScripting"
	activate
	
	set CustName to "Smithtown"
	set OrderNum to "123456"
	set session to login with saved credentials
	
	set opp to make SObject
	set type of opp to "Opportunity"
	
	(* THESE are REQUIRED Opportunity Fields - the Opportunity is not created if these 4 objects don't have values *)
	
	opp setField named "Name" to "blahblah2" -- text returned of (display dialog "Name This" default answer "") -- as text -- will be filled by a variable
	opp setField named "StageName" to "Prospecting"
	opp setField named "CloseDate" to "2011-07-10"
	
	(* THESE are Custom Opportunity Fields - anything written via applescript, and the "Create SObjects" instruction fails - no opportunity created *)
	
	--	opp setField named "Opp_Name_20__c" to "123456 BLAH BLAH" -- Eventually will filled with these variables: OrderNum & " " & CustName
	--	opp setField named "PDS__PO_Number__c" to "123456"  -- variable OrderNum
	--	opp setField named "PDS__Document_Number__c" to "123456" -- variable OrderNum
	--	opp setField named "PDS__Invoice_Number__c" to "123456" -- variable OrderNum
	
	set res5 to session create sobjects opp
	Id of first item of res5
	set NewOppID to Id of first item of res5 as text
	
end tell

 

Inserting anything into the custom opportunity fields causes the script to fail. I can understand having "required" fields, like name, but I should be able to fill custom fields with my own data.

 

  • July 11, 2011
  • Like
  • 0

Though lots of many nights and trial and error with various syntax, I've munged together a set of scripts that help me integrate with Salesforce via Applescript. Many thanks to Simon and all the folks that have put these mac tools together for us to use and and abuse.

 

I thought I'd had everything licked, but then came upon a discovery - the script that I'd used to take data from Address Book and create accounts and contacts was inserting a "0" where the last name should go in the Contact record.

 

Here's the code:

 

tell application "SalesforceScripting"
	activate
	set session to login with saved credentials
	
	set ContactFirstName to "Joe"
	set ContactLastName to "Blow"
	
	set cont to make SObject
	set type of cont to "Contact"
	cont setField named "FirstName" to ContactFirstName
	cont setField named "LastName" to ContactLastName
	--	cont setField named "AccountId" to NewAccountID
	--	cont setField named "PDS__Primary_Contact__c" with to
	--	cont setField named "Email" to EmailAddy
	
	set res2 to session create sobjects cont
	set NewContactID to Id of first item of res2
	
	open location "https://na9.salesforce.com/" & NewContactID
	
end tell

 

Here's the results of that script from the AS Log:

 

tell application "SalesforceScripting"
	activate
	login with saved credentials
		--> UserSession id "us_31068"
	make new SObject
		--> SObject id "row_31070"
	set type of SObject id "row_31070" to "Contact"
	setField SObject id "row_31070" named "FirstName" to "Joe"
	setField SObject id "row_31070" named "LastName" to "Blow"
	create UserSession id "us_31068" sobjects SObject id "row_31070"
		--> {SaveResult id "sr_31071" of UserSession id "us_31068"}
	get Id of SaveResult id "sr_31071" of UserSession id "us_31068"
		--> "003E0000005uds7IAA"
	open location "https://na9.salesforce.com/003E0000005uds7IAA"
end tell

 

If I hard code the ContactLastName, like:

 

cont setField named "LastName" to "Blow"

 the log returns an identical result, and the record is written properly to Salesforce.com. But if "LastName" is written with a variable, I get a big fat ZERO.

 

Any clues?

 

 

 

  • July 11, 2011
  • Like
  • 0

I was thrilled to find this:

 

tell application "SalesforceScripting"
	set mySession to login username "myemail@mydomain.com" password "passwordtokenhere"
	
	--  Create a new Account in Salesforce
	
	set acc to make SObject
	set type of acc to "Account"
	acc setField named "Name" to "3 New Test Account"
	acc setField named "PDS__QB_Billing_Address__c" to "3 New Test Account
John Doe
123 Main Street
Arlington, TX 75007"
	acc setField named "Phone" to "(888) 555-6666"
	set res to mySession create sobjects acc
	Id of first item of res
	
end tell

 


And It works like a champ. I've spent the last couple of hours scouring the net and the script library trying to find out how to use something similar, or to add to it, so that I can create an Opportunity and Contact by adding some instructions to this.

 

I'm stuck. I guess I don't know enough about Apex and the SF system yet to read what needs to be in the script.

 

Any insight as to how to add Accounts/Contacts/Opportunities at the same time would be greatly appreciated.

  • June 28, 2011
  • Like
  • 0