You need to sign in to do that
Don't have an account?
Keerthigee
How to access the Campaign field from lead object to visualforce
Hi All,
I want to access campaign field from lead object to visualforce using custom controller. For this,is the right way to write trigger? Suppose If I write trigger then how to call trigger from visualforce?
Kindly support and suggest.
Thank You.
I want to access campaign field from lead object to visualforce using custom controller. For this,is the right way to write trigger? Suppose If I write trigger then how to call trigger from visualforce?
Kindly support and suggest.
Thank You.
create a handler in the constructor..
write this in constructor...
campmem = new CampaignMember();
All Answers
Thank you for your immediate suggestion, which is useful.
Thanks.
Can you explain how to write soql query to acess campaign field from lead object using extensions.
Awaiting for your response.
Thanks.
Here Campaign and Lead are not directly related...
we need to use the junction object CampaignMembers to get the field displayed....
Even when you save it check that you save as the code given below...
VF:
<apex:inputField id="if_lead_firstname" value="{!mylead.firstname}" label="First Name"/>
<apex:inputField id="if_lead_campaign" value="{!campmem.campaignID}" label="Campaign"/>
public Lead mylead { get; set; }
public CampaignMember campmem {get; set;}
public PageReference save() {
insert mylead;
campmem.leadid = mylead.id;
insert campmem;
mylead.clear();
return null;
}
Thanks for your response.
For junction object,We can't create a master-detail relationship with lead object.
Then,how to create this relationship?
Kindly support and suggest.
you need not create any master detail relationship...it already exixts...
1 Campaign ----- n Leads --- n leads can arise from 1 campaign...
n Campaigns ---- 1 Lead --- n campaigns may give rise to 1 lead...
here exixts a many to many relationship...which is achieved through a junction object called " Campaign Members "...
Use the above given code to get the field
Thanks for your response.
I got this point yesterday
With the help of your points,I displayed campaign label but not textfield.
what I want to do next.
Kindly support and suggest.
Thanks for your response.
Vf:
<apex:page standardcontroller="Lead" tabstyle="lead" extensions="campaignacess">
<b>my name is "{!$User.FirstName}"</b>
<apex:form >
<apex:pageBlock title="Lead Edit" tabstyle="contact">
<apex:pageblockbuttons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!Cancel}" value="cancel"/>
</apex:pageblockbuttons>
<apex:pageBlockSection title="Lead Information" columns="2">
<apex:inputfield value="{!lead.firstname}"/>
<apex:inputfield value="{!lead.lastname}"/>
<apex:inputfield value="{!lead.company}"/>
<apex:inputfield value="{!lead.leadsource}"/>
<apex:inputfield value="{!lead.title}"/>
<apex:inputfield value="{!lead.status}"/>
<apex:inputfield value="{!lead.industry}"/>
<apex:inputfield value="{!lead.Approval_status__c}"/>
</apex:pageBlockSection>
<apex:pageblocksection title="Address Information">
<apex:inputfield value="{!lead.street}"/>
<apex:inputfield value="{!lead.city}"/>
<apex:inputfield value="{!lead.state}"/>
<apex:inputfield value="{!lead.postalcode}"/>
<apex:inputfield value="{!lead.country}"/>
<apex:inputfield value="{!campmem.campaignID}"/>
</apex:pageblocksection>
<apex:pageBlocksection title="Additional Information">
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller:
-------------
public class campaignacess {
public campaignacess(ApexPages.StandardController controller) {
}
public Lead mylead { get; set; }
public CampaignMember campmem {get; set;}
public PageReference save() {
insert mylead;
campmem.leadid = mylead.id;
insert campmem;
mylead.clear();
return null;
}
}
Kindly support and suggest.
create a handler in the constructor..
write this in constructor...
campmem = new CampaignMember();
I got it what exactly i want.
Thanks for helping me with wonderful suggestion.
Can you help me on one more thing.i.e Writing articles
Kindly support and suggest.
Thanks for your response.
I want to write articles related to reports,triggers,workflows.
Kindly support and suggest.
Thanks for your Response.
If I enter some data in campaign field in VF and then save it.
Before saving,I got an error as
Kindly support and suggest.
plz refer to the save method which i have posted earlier...
thanks
I tried it,but not saving data.
Thanks.
mylead = new Lead();
I added this constructor already,but not saving the data.
Thanks.
its working good...
able to save the data...
Thank you for your response.
I am getting error till..
Kindly support and suggest.
you missed out to give entries to required fields
I had given that also.
still,not working.
Thanks.
<apex:page standardcontroller="Lead" tabstyle="lead" extensions="campaignacess5">
<b>my name is "{!$User.FirstName}"</b>
<apex:form >
<apex:pageBlock title="Lead Edit" tabstyle="contact">
<apex:pageblockbuttons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!Cancel}" value="cancel"/>
</apex:pageblockbuttons>
<apex:pageBlockSection title="Lead Information" columns="2">
<apex:inputfield value="{!lead.firstname}"/>
<apex:inputfield value="{!lead.lastname}"/>
<apex:inputfield value="{!lead.company}"/>
<apex:inputfield value="{!lead.leadsource}"/>
<apex:inputfield value="{!lead.title}"/>
<apex:inputfield value="{!lead.status}"/>
<apex:inputfield value="{!lead.industry}"/>
</apex:pageBlockSection>
<apex:pageblocksection title="Address Information">
<apex:inputfield value="{!lead.street}"/>
<apex:inputfield value="{!lead.city}"/>
<apex:inputfield value="{!lead.state}"/>
<apex:inputfield value="{!lead.postalcode}"/>
<apex:inputfield value="{!lead.country}"/>
<apex:inputfield value="{!campmem.campaignID}"/>
</apex:pageblocksection>
<apex:pageBlocksection title="Additional Information">
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller
public with sharing class campaignacess5 {
public campaignacess5(ApexPages.StandardController controller) {
campmem = new CampaignMember();
}
public CampaignMember campmem { get; set; }
}
Check it out and say what changes that occur in related lists of the detail page of the respective record
Campaigns have not been updated into related list campaign history.
Thanks.
Better to go with Custom Controller instead of standard controller...
Hi,
Thanks. Problem with Campaign field solved... Need help for owner field on the same page...
Regards,
Razzzaq.
Create a handler of User sObject and make use of user id...
hi vempally,
Is this how you were referring to...
If yes, I want that 'id' to binded directly...
Code as follows :-
<apex:page StandardController="Lead" extensions="leadext">
<apex:form >
<apex:pageBlock mode="Edit" title="Lead Edit" tabstyle="Lead">
<apex:pageblockButtons >
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton Value="Cancel" action="{!Cancel}"/>
</apex:pageblockButtons>
<apex:pageBlockSection columns="2" title="Lead Information">
<!---- Here it goes ------->
<apex:pageBlockSectionItem >
<apex:outputLabel value="Lead owner"></apex:outputLabel>
<apex:outputpanel >
<apex:outputfield value="{!userame.name}"/>
</apex:outputpanel>
</apex:pageBlockSectionItem>
<!------- -------->
<apex:inputField value="{!mylead.Phone}" />
<apex:pageBlockSectionItem >
<apex:outputLabel value="First Name"></apex:outputLabel>
<apex:outputPanel >
<apex:inputfield value="{!mylead.Salutation}"/>
<apex:inputfield value="{!mylead.FirstName}"/></apex:outputPanel></apex:pageBlockSectionItem>
<apex:inputField value="{!mylead.MobilePhone}" />
<apex:inputfield value="{!mylead.LastName}"/>
<apex:inputfield value="{!mylead.Fax}"/>
<apex:inputfield value="{!mylead.Company}"/>
<apex:inputfield value="{!mylead.Email}"/>
<apex:inputfield value="{!mylead.title}"/>
<apex:inputfield value="{!mylead.website}"/>
<apex:inputfield value="{!mylead.leadsource}"/>
<apex:inputfield value="{!mylead.Status}"/>
<apex:inputfield value="{!campmem.Campaignid}"/>
<apex:inputfield value="{!mylead.rating}"/>
<apex:inputfield value="{!mylead.industry}"/>
<apex:inputfield value="{!mylead.NumberOfEmployees}"/>
<apex:inputfield value="{!mylead.AnnualRevenue}"/>
<apex:inputfield value="{!mylead.state}"/>
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" title="Address Information">
<apex:inputfield value="{!mylead.street}"/>
<apex:inputfield value="{!mylead.city}"/>
<apex:inputField value="{!mylead.postalcode}"/>
<apex:inputfield value="{!lead.country}"/>
</apex:pageBlockSection>
<apex:pageblocksection columns="2" title="Additional Information">
<apex:inputfield value="{!mylead.ProductInterest__c}"/>
<apex:inputfield value="{!mylead.CurrentGenerators__c}"/>
<apex:inputfield value="{!mylead.SICCode__c}"/>
<apex:inputfield value="{!mylead.Primary__c}"/>
<apex:inputfield value="{!mylead.NumberofLocations__c}"/>
</apex:pageblocksection>
<apex:pageblocksection title="Description Information">
<apex:inputfield value="{!mylead.Description}"/>
</apex:pageblocksection>
<apex:pageblocksection title="Optional">
<apex:pageblockSectionItem >
<apex:outputPanel >
<apex:inputCheckbox value="{!mylead.HasOptedOutOfEmail}"/>
</apex:outputPanel></apex:pageblockSectionItem></apex:pageblocksection>
</apex:pageBlock>
</apex:form>
</apex:page>
==============================================================================
public class leadext {
public leadext(ApexPages.StandardController controller) {
campmem = new CampaignMember();
mylead = new lead();
ls = new user();
}
public Lead mylead { get; set; }
public CampaignMember campmem {get; set;}
public user ls{get;set;}
Pagereference leadpage;
user userame;
public user getuserame(){
ls = [ Select Name from User where Id = :'00590000003Mfae'];
return ls;
}
public PageReference save() {
insert mylead;
campmem.leadid = mylead.id;
insert campmem;
mylead.clear();
campmem.clear();
return null;
}
}