function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Paul SherryPaul Sherry 

Cross object field update - Custom to standard object

Hi everyone, this is my first post here but I've been reading quite a bit and have learned alot from these boards but have recently run into a road block that I cant seem to figure out.  Im hoping that someone might be able to point me in the right direction.

I need some help with Apex coding that would allow for a cross object field update from our org's custom object "Dispos" (appt results) to update corresponding fields in the opportunity object. I have created a custom object called "dispos" that allows our sales staff to enter appointment result information from the salesforce1 app. Our salesmen are subcontractors/1099 employess and we have force.com app licenses for them which allow them to be named users as well as having limited visibility into our org but they do not have access to the opportunity object (intentionally).

When a salesman runs an appointment that has been assigned to him, we require that he creates a new dispo record and fill in the blanks of the appointment results. Because of the limitations of the force.com app license they do not have visibility into the opportunity object that is the "master" location of new leads, appointment results and sold job information. What we are hoping to achieve through Apex is that when a new dispo is created and the proper opportunity record is referenced, that the details input by the salesmen are transferred into the corresponding fields of the opportunity.

I have tried to achieve this through a standard work flow rule and field update but I cant quite get this operation to work from custom objects to the opportunity. Ive contacted salesforce about this particular business process and have been told that it will only be possible through custom apex coding.  I am fairly flexible on how we achieve the desired result but my main goal to keep our office staff from having to reenter data that is already in the system in order to keep the opportunity records accurate and up to date.
Best Answer chosen by Paul Sherry
Jason Curtis NBSFDGJason Curtis NBSFDG
Exactly, if you have a field on Opportunity that is a lookup field to the Dispo object (hence a 1-to-1 relationship), then you can create a formula field on Opportunity that links to a field on Dispo and displays it. I use this often when a related objects name field is an auto-id and I want to show some other related field on the detail record.

All Answers

nitin sharmanitin sharma
Are u saying that you want to copy some information from dispo object to the opporunityt object?Id that it the case then you will have to writer a trigger to accomplish that.

Is there any relationship between the two objects?
Jason Curtis NBSFDGJason Curtis NBSFDG
To elaborate on Nitin's answer, you can't declartively update a parent record from a child record (unless it is a roll up field), that is assuming there are multiple Dispo records related to an Opportunity.
Paul SherryPaul Sherry
Thanks for responding! Ill try to clarify for you both.  

Nitin, Yes, when a new dispo record is created from the field by a salesman, I would like for that information to also be copied into the coresponding opportunity that was assigned to them.  I have also had the idea that before that process/trigger "runs" that I would like for a full license user like a salesmanager to review the dispo and then take an action that would prompt the field update.  For example if a salesman mistyped the opportunity number when submitting a dispo, the sales manager could confirm the correct dispo to opportunity relationship and then make create the relationship to prompt the field update.  This extra step should be easy by creating a list view for dispos that are "un reviewed" and we would still be eliminating all of the redundant data entry when the trigger runs.

Jason, Thank you for your response, I should have been more clear about the dispo process.  There should only ever be one dispo for any one opportunity.  I had planned on creating the field update process on a "when its created and edited" format so that if a salesman were to have more contact with a customer they have already created the dispo for then they would simply go back to the original dispo and update the information, which would in turn, update the opportunity field.
nitin sharmanitin sharma
Hi Sherry,


I have some sample trigger for you .Since I am short of time ,therefore,I have written in 2 minutes.I could not run in any environment so there are bounnd to be some mistakes .

I have assumed that opporunity already exists and new disp record is created by the salesman and linked it to to an exisitng oppornuity.So there is an exiting opp in the system.I have taken some sample fields ,In place of those fields you have to put your own dispo and opportunity field.


We need another trigger for updation.


create t on dispo(After insert)
{

Map<id,dispo__c> disp=new Map<id,dispo__c>;


for(Dispo__c cope:trigger.new)
{


disp.put(cope.id,cope)


}
if(disp.szie()>0)
{

list<opportunity>ole=new list<opportunity>();
list<opporunity> opp=new list<opportunity>([select id name from opportunity where id in:disp.keyset()]);
for(opportunity o:opp)
{
disp__c l=disp.get(o.id);
o.amount=l.amount;
o.date=l.date;
ole.add(o);

}

Insert ole;

}
}
}
Jason Curtis NBSFDGJason Curtis NBSFDG

Paul, have you thought about setting up an automated approval process, that way a record could be submitted and passed on to the necessary manager.
Preliminary info here: https://help.salesforce.com/HTViewHelpDoc?id=what_are_approvals.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=what_are_approvals.htm&language=en_US)

Best,
 

Jason

Paul SherryPaul Sherry
Jason, that's a great idea to make sure that the record is approved by the correct manager and to confirm that the 'dispo' is related to the correct opportunity. Could the approval process also trigger the field update from dispo to opportunity? *PAUL SHERRY, *Production Manager [image: http://www.feazelinc.com/cgi/htmlos.cgi/servicepoint-new-customer.html] [image: https://www.facebook.com/FeazelInc] [image: http://www.linkedin.com/company/768342?trk=tyah] [image: http://www.youtube.com/feazelinc] C: 614-561-3877 | T: 866-LEAKSOS | feazelinc.com | Columbus | Cincinnati | Dayton
Jason Curtis NBSFDGJason Curtis NBSFDG

There are some challenges to cross-object field updates with approval/work flows. Probalby best to test it out, here is a reference: https://help.salesforce.com/HTViewHelpDoc?id=workflow_cross_object_field_updates.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=workflow_cross_object_field_updates.htm&language=en_US)

Also, if the cross-object updating doesn't work, you might be able to update a field on Dispo, and then have it reflected on the opportunity via a formula field.
 

Best,
 

Jason

Paul SherryPaul Sherry
I see, so rather than having editable fields in the opportunity, I would create read only formala fields with the formulas just referencing the applicable dispo fields? Assuming that there is only one dispo per opportunity that might work. *PAUL SHERRY, *Production Manager [image: http://www.feazelinc.com/cgi/htmlos.cgi/servicepoint-new-customer.html] [image: https://www.facebook.com/FeazelInc] [image: http://www.linkedin.com/company/768342?trk=tyah] [image: http://www.youtube.com/feazelinc] C: 614-561-3877 | T: 866-LEAKSOS | feazelinc.com | Columbus | Cincinnati | Dayton
Jason Curtis NBSFDGJason Curtis NBSFDG
Exactly, if you have a field on Opportunity that is a lookup field to the Dispo object (hence a 1-to-1 relationship), then you can create a formula field on Opportunity that links to a field on Dispo and displays it. I use this often when a related objects name field is an auto-id and I want to show some other related field on the detail record.
This was selected as the best answer
Paul SherryPaul Sherry
Well that definitely simplifies the process and should eliminate the need for any Apex coding if im following you correctly. Is there anything that I need to do to make sure that there is a 1 to 1 relationship? (not allow a second dispo) Thank you for your help on this! *PAUL SHERRY, *Production Manager [image: http://www.feazelinc.com/cgi/htmlos.cgi/servicepoint-new-customer.html] [image: https://www.facebook.com/FeazelInc] [image: http://www.linkedin.com/company/768342?trk=tyah] [image: http://www.youtube.com/feazelinc] C: 614-561-3877 | T: 866-LEAKSOS | feazelinc.com | Columbus | Cincinnati | Dayton
Jason Curtis NBSFDGJason Curtis NBSFDG
If you have a lookup field on Opportunity called “Disposition” and then link it to the Dispo object, then when the Opp record is edited and a Dispo selected for that Opp it will always be 1 Dispo record for that 1 Opportunity. (But multiple Opportunities could reference the same Dispo.) If you put an Opportunity lookup field on Dispo, then you will only have one Opp record per Dispo. (But, again, multiple Dispo records could reference the same Opportunity.) Plus this wouldn’t allow you to auto populate field back to Opp from a Dispo. I know you are just using platform licenses so you can’t have your service people use the Opp object, but ideally, if this wasn’t a restriction, then you would just have additional fields on Opp, and the fields they weren’t allowed to see would be hidden. J
Paul SherryPaul Sherry
Good morning Jason, I was thinking about how to simplify this process for the end user and wanted to run something past you. Could we create a new, blank dispo during the creation of the new opportunity record so that the relationship is already there? Then when a sales manager assigns an opportunity we could include the dispo# in the email notification that is sent out (I have an email notification set up to notify the salesman with all of the relevant customer information) so that when our salesman is finished with their appt, they just have to check their email, search for the correct dispo# and fill in the blanks. That would keep the salesman from having to create a new dispo, keep the office from having to verify that the dispo is related to the correct opportunity and we can still set up an approval process around it to make sure someone reviews the dispo. I think that in order for the salesman to have access to the dispo we might have to make the assigned salesman the owner of the dispo record but that should be fairly straight forward as well. Thanks for any advice! Paul *PAUL SHERRY, *Production Manager [image: http://www.feazelinc.com/cgi/htmlos.cgi/servicepoint-new-customer.html] [image: https://www.facebook.com/FeazelInc] [image: http://www.linkedin.com/company/768342?trk=tyah] [image: http://www.youtube.com/feazelinc] C: 614-561-3877 | T: 866-LEAKSOS | feazelinc.com | Columbus | Cincinnati | Dayton
Jason Curtis NBSFDGJason Curtis NBSFDG
Paul, glad you dug in and got it working. I'm a big fan of the platform, it can do some pretty amazing things.

One thought, reading through your note, if you don't already have it set up, via workflow you could have an email automatially sent out upon the creation (or on some other criteria) on a dispo with a link back to the dispo record. The Salesperson can click the link in the email and can even have it open up in the Salesforce1 mobile app.

And when you get a chance, if you can mark this question solved and mark which was the best answer.

Good luck!
Paul SherryPaul Sherry
Thats a great idea also!  I am definately going to add that link to the notification email.
Jason Curtis NBSFDGJason Curtis NBSFDG
One thing that through me when I first created an email template, you can have the template dynamically insert the various fields you want to populate the email, the name of the opp, dates, etc. But it took me a bit to find out the field to put into the template to create a clickable URL. Here is the text from one of my templates:

The following lead has been assigned to you on {!Lead.CreatedDate}.
It came in from {!Lead.LeadSource}.

{!Lead.FirstName} {!Lead.LastName} with {!Lead.Company}.

They are interested in: {!Lead.Product_Interest__c}

Notes: 
{!Lead.Lead_Notes__c}

Click here for the record: {!Lead.Link}
The {!Lead.Link} is the clickable link, you can insert it by selecting the object, then selecting the field type of "Detail Link", see image.
User-added image
Paul SherryPaul Sherry
Thanks for the heads up, I didnt realize there was a direct link for the record.  What I did to add the link in this case was to copy and paste the first half of the url into the email ( http://www.salesforce.com/....) and then added the dispo id directly following the "/" and that finishes up the link to make sure the salesmen are directed to the correct record.   I think I had to do it this way because I was referencing a related dispo record (my email notification is triggered on the opportunity record) rather than the opportunity record.
Paul SherryPaul Sherry
Is there anything specific that I need to do in order for the link to open in the salesforce1 app rather than opening a browser window?
Paul SherryPaul Sherry
I cant seem to get the link to open in the Salesforce1 app, it is going straight to a browser window on both my iPhone and iPad which both have the Salesforce1 app.... Any ideas?
Jason Curtis NBSFDGJason Curtis NBSFDG
Hi, Paul, when I click a link to a SF record on my mobile email it asks me where I want to open it and SF1 is an option, but I'm on Android.
I think it is doable to make the link open directly in SF1 though (now that I researched it), you might have found this already, but here are a couple of options to review:
http://salesforce.stackexchange.com/questions/22591/how-to-redirect-links-in-email-template-to-salesforce1-app
And this slide show shows how to create the Direct Email link, see page 24& 25:
http://www.slideshare.net/developerforce/salesforce1-mobile-tips-tricks-for-admins-33866072

Basically, though, you have to use the URL: com.salesforce.salesforce1://entity/view?entityId=xxxxxxx
I haven't tired it yet, hope it works, let me know!


Jason Curtis NBSFDGJason Curtis NBSFDG
Salesforce1 Tips
Jason Curtis NBSFDGJason Curtis NBSFDG
Hmmm, this seems to be for linking from a web page to the app, but I haven't been able to get it to work from my phone email client.
Paul SherryPaul Sherry
I managed to get the droids working to go straight to the app or atleast the smart phone enabled version but my iPhone isnt letting me do it quite as easily.  If I get it working ill certainly let you know.  Our salesmen with iPhones will have to resort to opening the app from the home screen, I think even they can manage that :)