You need to sign in to do that
Don't have an account?

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.
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.
All Answers
Is there any relationship between the two objects?
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.
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;
}
}
}
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
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
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!
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.
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!