You need to sign in to do that
Don't have an account?
Jeremy Bannon
Apex Class Help
I have a custom covert button that uses the following Apex Class:
public class CustomConvertLead {
public CustomConvertLead(ApexPages.StandardController controller) {
}
public PageReference ConvertL(){
Id idd = ApexPages.CurrentPage().getParameters().get('id');
Boolean ok = false;
Id AccId, ConId;
Lead ll = [SELECT Id,Company__c, Contact__c, Company, Engagement_Target__c, FirstName, LastName, Amount__c,
Reason_Inquiry__c, Referral_Name__c, OwnerId, Description, Rating, Email,
AnnualRevenue, EBITDA__c, NumberOfEmployees, LeadSource, Lead_Source_Description__c
FROM Lead WHERE Id =:idd LIMIT 1];
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(idd);
lc.setDoNotCreateOpportunity(true);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
if (ll.Company__c != null && ll.Contact__c != null){
lc.setAccountId(ll.Company__c);
lc.setContactId(ll.Contact__c);
Database.LeadConvertResult result = Database.convertLead(lc);
}
else {
ok = true;
if (ll.Company__c != null)
lc.setAccountId(ll.Company__c);
if (ll.Contact__c != null)
lc.setContactId(ll.Contact__c);
if (ll.Company__c == null){
List<Account> cc = [SELECT Id FROM Account WHERE Name = :ll.Company];
if (cc.size() != 0)
lc.setAccountId(cc[0].Id);
}
if (ll.Contact__c == null){
List<Contact> cc =[SELECT Id, AccountId FROM Contact WHERE LastName = :ll.LastName OR (Email = :ll.Email AND Email != NULL)];
if (cc.size() != 0){
lc.setAccountId(cc[0].AccountId);
lc.setContactId(cc[0].Id);
}
}
Database.LeadConvertResult result = Database.convertLead(lc);
AccId = result.getAccountId();
ConId = result.getContactId();
}
Idea_Pitch__c i = new Idea_Pitch__c();
if (ll.FirstName != null)
i.Name = ll.FirstName + ' '+ ll.LastName + ' ' + ll.Company;
else
i.Name = ll.LastName + ' ' + ll.Company;
i.Converted_Time_Stamp__c = datetime.now();
i.Project_Type__c = ll.Reason_Inquiry__c;
i.Referred_by__c = ll.Referral_Name__c; //there are 2 refferred_by_contact on Idea
// what should OwnerId be mapped to
i.Rating__c = ll.Rating;
i.Description__c = ll.Description;
i.Annual_Revenue__c = ll.AnnualRevenue;
i.EBITDA__c = ll.EBITDA__c;
i.Capital_Formation_Amount__c = ll.Amount__c;
i.No_of_Employees__c = ll.NumberOfEmployees;
i.Status__c = '1. Idea Development';
i.Lead_Source__c = ll.LeadSource;
i.Lead_Source_Description__c = ll.Lead_Source_Description__c;
i.Engagement_Target__c = ll.Engagement_Target__c;
List<CampaignMember> cms = [SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE LeadID = :ll.Id LIMIT 1];
if (cms.size() != 0)
i.Campaign_Conference__c = cms[0].CampaignID;
if (ok == false){
i.Company__c = ll.Company__c;
i.Contact__c = ll.Contact__c;
}
else {
i.Company__c = AccId;
i.Contact__c = ConId;
}
INSERT i;
PageReference p = new PageReference('/'+i.Id);
return p;
}
}
I want to add a few more field updates. I have added the feilds in through the developer console. However you can not add the New Apex Class to an active org. I have the new code built in one of my sandboxes.
public class CustomConvertLead {
public CustomConvertLead(ApexPages.StandardController controller) {
}
public PageReference ConvertL(){
Id idd = ApexPages.CurrentPage().getParameters().get('id');
Boolean ok = false;
Id AccId, ConId;
Lead ll = [SELECT Id,Company__c, Contact__c, Company, Engagement_Target__c, FirstName, LastName, Amount__c,
Reason_Inquiry__c, Referral_Name__c, OwnerId, Description, Rating, Email,
AnnualRevenue, EBITDA__c, NumberOfEmployees, LeadSource, Lead_Source_Description__c
FROM Lead WHERE Id =:idd LIMIT 1];
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(idd);
lc.setDoNotCreateOpportunity(true);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
if (ll.Company__c != null && ll.Contact__c != null){
lc.setAccountId(ll.Company__c);
lc.setContactId(ll.Contact__c);
Database.LeadConvertResult result = Database.convertLead(lc);
}
else {
ok = true;
if (ll.Company__c != null)
lc.setAccountId(ll.Company__c);
if (ll.Contact__c != null)
lc.setContactId(ll.Contact__c);
if (ll.Company__c == null){
List<Account> cc = [SELECT Id FROM Account WHERE Name = :ll.Company];
if (cc.size() != 0)
lc.setAccountId(cc[0].Id);
}
if (ll.Contact__c == null){
List<Contact> cc =[SELECT Id, AccountId FROM Contact WHERE LastName = :ll.LastName OR (Email = :ll.Email AND Email != NULL)];
if (cc.size() != 0){
lc.setAccountId(cc[0].AccountId);
lc.setContactId(cc[0].Id);
}
}
Database.LeadConvertResult result = Database.convertLead(lc);
AccId = result.getAccountId();
ConId = result.getContactId();
}
Idea_Pitch__c i = new Idea_Pitch__c();
if (ll.FirstName != null)
i.Name = ll.FirstName + ' '+ ll.LastName + ' ' + ll.Company;
else
i.Name = ll.LastName + ' ' + ll.Company;
i.Converted_Time_Stamp__c = datetime.now();
i.Project_Type__c = ll.Reason_Inquiry__c;
i.Referred_by__c = ll.Referral_Name__c; //there are 2 refferred_by_contact on Idea
// what should OwnerId be mapped to
i.Rating__c = ll.Rating;
i.Description__c = ll.Description;
i.Annual_Revenue__c = ll.AnnualRevenue;
i.EBITDA__c = ll.EBITDA__c;
i.Capital_Formation_Amount__c = ll.Amount__c;
i.No_of_Employees__c = ll.NumberOfEmployees;
i.Status__c = '1. Idea Development';
i.Lead_Source__c = ll.LeadSource;
i.Lead_Source_New_IdeaO__c = ll.Lead_Source_New_LeadO__c;
i.Lead_Source_Description__c = ll.Lead_Source_Description__c;
i.Lead_Source_Description_New_IdeaO__c = ll.Lead_Source_Description_New_LeadO__c;
i.Engagement_Target__c = ll.Engagement_Target__c;
List<CampaignMember> cms = [SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE LeadID = :ll.Id LIMIT 1];
if (cms.size() != 0)
i.Campaign_Conference__c = cms[0].CampaignID;
if (ok == false){
i.Company__c = ll.Company__c;
i.Contact__c = ll.Contact__c;
}
else {
i.Company__c = AccId;
i.Contact__c = ConId;
}
INSERT i;
PageReference p = new PageReference('/'+i.Id);
return p;
}
}
My question is when I use change set to bring it over, will it just take the place of the orginal code or do I need to do something else?
public class CustomConvertLead {
public CustomConvertLead(ApexPages.StandardController controller) {
}
public PageReference ConvertL(){
Id idd = ApexPages.CurrentPage().getParameters().get('id');
Boolean ok = false;
Id AccId, ConId;
Lead ll = [SELECT Id,Company__c, Contact__c, Company, Engagement_Target__c, FirstName, LastName, Amount__c,
Reason_Inquiry__c, Referral_Name__c, OwnerId, Description, Rating, Email,
AnnualRevenue, EBITDA__c, NumberOfEmployees, LeadSource, Lead_Source_Description__c
FROM Lead WHERE Id =:idd LIMIT 1];
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(idd);
lc.setDoNotCreateOpportunity(true);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
if (ll.Company__c != null && ll.Contact__c != null){
lc.setAccountId(ll.Company__c);
lc.setContactId(ll.Contact__c);
Database.LeadConvertResult result = Database.convertLead(lc);
}
else {
ok = true;
if (ll.Company__c != null)
lc.setAccountId(ll.Company__c);
if (ll.Contact__c != null)
lc.setContactId(ll.Contact__c);
if (ll.Company__c == null){
List<Account> cc = [SELECT Id FROM Account WHERE Name = :ll.Company];
if (cc.size() != 0)
lc.setAccountId(cc[0].Id);
}
if (ll.Contact__c == null){
List<Contact> cc =[SELECT Id, AccountId FROM Contact WHERE LastName = :ll.LastName OR (Email = :ll.Email AND Email != NULL)];
if (cc.size() != 0){
lc.setAccountId(cc[0].AccountId);
lc.setContactId(cc[0].Id);
}
}
Database.LeadConvertResult result = Database.convertLead(lc);
AccId = result.getAccountId();
ConId = result.getContactId();
}
Idea_Pitch__c i = new Idea_Pitch__c();
if (ll.FirstName != null)
i.Name = ll.FirstName + ' '+ ll.LastName + ' ' + ll.Company;
else
i.Name = ll.LastName + ' ' + ll.Company;
i.Converted_Time_Stamp__c = datetime.now();
i.Project_Type__c = ll.Reason_Inquiry__c;
i.Referred_by__c = ll.Referral_Name__c; //there are 2 refferred_by_contact on Idea
// what should OwnerId be mapped to
i.Rating__c = ll.Rating;
i.Description__c = ll.Description;
i.Annual_Revenue__c = ll.AnnualRevenue;
i.EBITDA__c = ll.EBITDA__c;
i.Capital_Formation_Amount__c = ll.Amount__c;
i.No_of_Employees__c = ll.NumberOfEmployees;
i.Status__c = '1. Idea Development';
i.Lead_Source__c = ll.LeadSource;
i.Lead_Source_Description__c = ll.Lead_Source_Description__c;
i.Engagement_Target__c = ll.Engagement_Target__c;
List<CampaignMember> cms = [SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE LeadID = :ll.Id LIMIT 1];
if (cms.size() != 0)
i.Campaign_Conference__c = cms[0].CampaignID;
if (ok == false){
i.Company__c = ll.Company__c;
i.Contact__c = ll.Contact__c;
}
else {
i.Company__c = AccId;
i.Contact__c = ConId;
}
INSERT i;
PageReference p = new PageReference('/'+i.Id);
return p;
}
}
I want to add a few more field updates. I have added the feilds in through the developer console. However you can not add the New Apex Class to an active org. I have the new code built in one of my sandboxes.
public class CustomConvertLead {
public CustomConvertLead(ApexPages.StandardController controller) {
}
public PageReference ConvertL(){
Id idd = ApexPages.CurrentPage().getParameters().get('id');
Boolean ok = false;
Id AccId, ConId;
Lead ll = [SELECT Id,Company__c, Contact__c, Company, Engagement_Target__c, FirstName, LastName, Amount__c,
Reason_Inquiry__c, Referral_Name__c, OwnerId, Description, Rating, Email,
AnnualRevenue, EBITDA__c, NumberOfEmployees, LeadSource, Lead_Source_Description__c
FROM Lead WHERE Id =:idd LIMIT 1];
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(idd);
lc.setDoNotCreateOpportunity(true);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
if (ll.Company__c != null && ll.Contact__c != null){
lc.setAccountId(ll.Company__c);
lc.setContactId(ll.Contact__c);
Database.LeadConvertResult result = Database.convertLead(lc);
}
else {
ok = true;
if (ll.Company__c != null)
lc.setAccountId(ll.Company__c);
if (ll.Contact__c != null)
lc.setContactId(ll.Contact__c);
if (ll.Company__c == null){
List<Account> cc = [SELECT Id FROM Account WHERE Name = :ll.Company];
if (cc.size() != 0)
lc.setAccountId(cc[0].Id);
}
if (ll.Contact__c == null){
List<Contact> cc =[SELECT Id, AccountId FROM Contact WHERE LastName = :ll.LastName OR (Email = :ll.Email AND Email != NULL)];
if (cc.size() != 0){
lc.setAccountId(cc[0].AccountId);
lc.setContactId(cc[0].Id);
}
}
Database.LeadConvertResult result = Database.convertLead(lc);
AccId = result.getAccountId();
ConId = result.getContactId();
}
Idea_Pitch__c i = new Idea_Pitch__c();
if (ll.FirstName != null)
i.Name = ll.FirstName + ' '+ ll.LastName + ' ' + ll.Company;
else
i.Name = ll.LastName + ' ' + ll.Company;
i.Converted_Time_Stamp__c = datetime.now();
i.Project_Type__c = ll.Reason_Inquiry__c;
i.Referred_by__c = ll.Referral_Name__c; //there are 2 refferred_by_contact on Idea
// what should OwnerId be mapped to
i.Rating__c = ll.Rating;
i.Description__c = ll.Description;
i.Annual_Revenue__c = ll.AnnualRevenue;
i.EBITDA__c = ll.EBITDA__c;
i.Capital_Formation_Amount__c = ll.Amount__c;
i.No_of_Employees__c = ll.NumberOfEmployees;
i.Status__c = '1. Idea Development';
i.Lead_Source__c = ll.LeadSource;
i.Lead_Source_New_IdeaO__c = ll.Lead_Source_New_LeadO__c;
i.Lead_Source_Description__c = ll.Lead_Source_Description__c;
i.Lead_Source_Description_New_IdeaO__c = ll.Lead_Source_Description_New_LeadO__c;
i.Engagement_Target__c = ll.Engagement_Target__c;
List<CampaignMember> cms = [SELECT CampaignID, LeadID, Status FROM CampaignMember WHERE LeadID = :ll.Id LIMIT 1];
if (cms.size() != 0)
i.Campaign_Conference__c = cms[0].CampaignID;
if (ok == false){
i.Company__c = ll.Company__c;
i.Contact__c = ll.Contact__c;
}
else {
i.Company__c = AccId;
i.Contact__c = ConId;
}
INSERT i;
PageReference p = new PageReference('/'+i.Id);
return p;
}
}
My question is when I use change set to bring it over, will it just take the place of the orginal code or do I need to do something else?
I thing u have done some changes in your class in sandbox and trying to push that again. Even if u use the change set it will override the code of the existing class.
Thank you for the help.