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
ANITHA BEEMU 2ANITHA BEEMU 2 

HI All,need help for the following,for standard object opportunity,i need to add multiple addresses(locations)

HI all,
i have custom object called locations which is master detail relationship with opportunities,now i want a button (existing location)on the related list of locations in the opportunitypage.i tired 

1-) Create a custom related list button in Opportunity as shown below:




2-) Add the url below to your button:

/apex/AssociateOpportunity?id={!Account.Id}

3-) Add the button to the Opportunity's related list in Account's page layout:





4-) Create a custom lookup field for Opportunity in Account (this is a trick to get the lookup field of Opportunity working in the Visualforce). This button won't be visible and will not be added to any layouts and won't include any related list.




5-) Create a controller class (I named it AssociateOpportunityExtController): 
 
01public with sharing class AssociateOpportunityExtController {
02 
03    public Account account  { get; set; }
04     
05    public AssociateOpportunityExtController() {
06         
07        String accountId = ApexPages.currentPage().getParameters().get('id');
08        account = [SELECT Id, Name, Opportunity__c FROM Account WHERE Id =: accountId];
09         
10    }
11     
12    public PageReference associate () {
13         
14        Opportunity opp = new Opportunity ( Id = account.Opportunity__c, AccountId = account.Id);
15         
16        try {
17            Database.update(opp);
18        } catch (Exception error) {
19            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error while associating.' + error.getMessage()));
20        }
21         
22        PageReference page = new PageReference('/' + account.Id);
23         
24        return page.setRedirect(true);
25    }
26     
27    public PageReference cancel () {
28        PageReference page = new PageReference('/' + account.Id);
29        return page.setRedirect(true);       
30    }
31     
32}
6-) Create a Visualforce (I named it AssociateOpportunity):
 
01<apex:page controller="AssociateOpportunityExtController">
02    <apex:form>
03        <apex:pageblock title="Associate Opportunity to Custom Object">
04            <apex:pageMessages />
05            <apex:pageblockbuttons location="top">
06                <apex:commandbutton value="Associate" action="{!associate}" />
07                <apex:commandbutton value="Cancel" action="{!cancel}"/>
08            </apex:pageblockbuttons>
09            <apex:pageBlockSection>
10                <apex:pageBlockSectionItem>
11                    <apex:outputLabel>Account Name</apex:outputLabel>
12                    <apex:outputText>{!account.Name}</apex:outputText>  
13                </apex:pageBlockSectionItem>
14              <apex:pageBlockSectionItem>
15                    <apex:outputLabel>Opportunity</apex:outputLabel>
16                    <apex:inputField value="{!account.Opportunity__c}"/>
17                </apex:pageBlockSectionItem>               
18            </apex:pageBlockSection>
19        </apex:pageblock>
20    </apex:form>
21</apex:page>

(i changed objectnames as in above its for different object) after following this getting error "Namespace length cannot exceed 15 chars "..
can any one help pls.
ANITHA BEEMU 2ANITHA BEEMU 2
Hi all,now i tried to clear the error,now problrm is not able save the existing location into opportunity,can any one help