• Craig P
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies

Does anyone have a basic primer/how to for setting up an Authenticated Website user? SFDC support has not been able to help after multiple cases that have been opened.

I have a custom button on the Contact object which uses a Visualforce page to send an email and create a Task.  It is working fine.

 

Requirement:

I need to add a confirmation (e.g., "are you sure you want to send an email?") to the button, but I cannot use JavaScript on the button itself because I am invoking a Visualforce page.

 

Also, I cannot add JavaScript to the Visualforce page, because I am using the action attribute on the <apex:page> element

 

Is there a way to automatically invoke a JavaScript function from the <apex:page> element?  Is there any way to have a JavaScript confirm on a custom button that is using a Visualforce page?

 

Thanks in advance!

I'm struggling a little to find the necessary documentation to get started using the Authenticated Website profile & user licenses type.  How do I create new users?  Is the only way to do that is to create the user using Apex?  We don't need (or want) self-registeration in our use case -- we really want the bare minimum "user get username and password & is able to login..."

 

Ideally this is probably just a simple recipe and I'd be ready to go -- but I'm struggling figuring that out, even though I think it should be easy over all.

 

Michael

  • On the Lead object, I created a custom field called “Product_1__c”, which is a Lookup field to the Product object
  • I have successfully created a trigger that moves the Product from the Lead to the Opportunity during the Convert process

 

Problem:  In my Apex test class, how do I programmatically add the custom field “Product_1__c” to the Lead, and then invoke the Convert process?

 

Apex Unit Test code:

@isTest

private class testTrgLeadConvert {
    static testMethod void myUnitTest() {       

test.startTest();               

 

// Create the Lead object...

Lead lead = new Lead();       

lead.LastName = 'Test LastName';       

lead.Company = 'Test Company';       

insert lead;               

 

// make an update....

lead.Status = 'Qualified Lead';       

lead.Number_of_Reps__c = 10;       

lead.Industry = 'Banking';       

update lead;               

 

// test to ensure update worked...

Lead updatedLead = [SELECT Id, LastName, Company, Status, Industry FROM Lead Where Id = :lead.Id];       

System.assertEquals('Banking', updatedLead.Industry);               

 

// convert the Lead...

Database.Leadconvert leadConvert = new Database.Leadconvert();       

leadConvert.setLeadId(updatedLead.Id);       

leadConvert.setConvertedStatus('Qualified Lead');       

leadConvert.setDoNotCreateOpportunity(false);       

leadConvert.setSendNotificationEmail(false);               

Database.Leadconvertresult lcr = Database.convertLead(leadConvert);       

System.debug('leadConvert' + lcr.isSuccess());

 

Opportunity o = [SELECT Id, OwnerId FROM Opportunity WHERE Id=:lcr.getOpportunityId()];    

System.debug('opportunity ID:  ' + o.Id);        test.stopTest();   

}

}

 

Trigger:

trigger trgLeadConvert on Lead (after insert, after update) {
// products & opportunities   

set<Id> products = new Set<Id>();   

set<id> opportunities = new set<id>();             

 

// product to pricebook entries   

map<id,pricebookentry> pricebookentries = new map<id,pricebookentry>();             

 

// line items to add   

list<opportunitylineitem> lineitems = new list<opportunitylineitem>();             

 

// standard pricebook   

pricebook2 standardpricebook = [select id from pricebook2 where isstandard = true];
   

// get all of the Lead object's product and opportunity id values    

for(lead l : trigger.new) {       

products.add(l.Product_1__c);       

products.add(l.Product_2__c);       

products.add(l.Product_3__c);       

products.add(l.Product_4__c);       

opportunities.add(l.convertedopportunityid);   

}
   

// map product id to pricebook entry...  join the Lead's Product w/ the Pricebook Entry   

for(pricebookentry pbe:[select id, unitprice, product2id                            

  from pricebookentry                            

  where pricebook2.isstandard = true                              

     and product2id in :products]) {       

pricebookentries.put(pbe.product2id, pbe);   

}
   

// set pricebook entry value for opportunities   

for(opportunity[] opps:[select id from opportunity where id in :opportunities]) {       

for(opportunity opp:opps) {           

opp.pricebook2id = standardpricebook.id;       

}       

update opps;   

}
   

// create line items   

for(lead l:trigger.new) {       

if(l.convertedopportunityid == null || l.Product_1__c == null) continue;       

lineitems.add(new opportunitylineitem(quantity=1,totalprice=pricebookentries.get(l.Product_1__c).unitprice,opportunityid=l.convertedopportunityid,pricebookentryid=pricebookentries.get(l.Product_1__c).id));               if(l.Product_2__c == null) continue;       

lineitems.add(new opportunitylineitem(quantity=1,totalprice=pricebookentries.get(l.Product_2__c).unitprice,opportunityid=l.convertedopportunityid,pricebookentryid=pricebookentries.get(l.Product_2__c).id));
       if(l.Product_3__c == null) continue;       

lineitems.add(new opportunitylineitem(quantity=1,totalprice=pricebookentries.get(l.Product_3__c).unitprice,opportunityid=l.convertedopportunityid,pricebookentryid=pricebookentries.get(l.Product_3__c).id));
       if(l.Product_4__c == null) continue;       

lineitems.add(new opportunitylineitem(quantity=1,totalprice=pricebookentries.get(l.Product_4__c).unitprice,opportunityid=l.convertedopportunityid,pricebookentryid=pricebookentries.get(l.Product_4__c).id));}     

// commit line items to the database   

insert lineitems;    

 

}

 

 

 

 

I added a custom lookup field (Product__c) to the Lead object and need to map it to the Opportunity standard field.  I have the code to add the Pricebook Entry to the Opportunity Line Item, but I cannot get the Product2Id from my custom lookup field (Lead.Product__c)

 

How do I get the Product ID (or Pri

 

 

trigger trgLeadConvert on Lead (after update)

{   

    for(Lead l : Trigger.new) 

    {       

           if(l.IsConverted && l.convertedOpportunityId != null)       

          {           

                     Opportunity oppty = [Select o.Id, o.Description from Opportunity o Where o.Id = :l.ConvertedOpportunityId];                           

                     // add an opportunity line item...           

                     OpportunityLineItem oli = new OpportunityLineItem();           

                     oli.OpportunityId = oppty.Id;           

                     oli.Quantity = 1;           

                     oli.TotalPrice = 100.00;           

                     

                     // THIS IS I NEED HELP!!!!

                     //oli.PricebookEntryId = l.Product__c.PricebookEntry.Product2Id;           

                     //oli.PricebookEntryId = l.Product__c.Id;           

 

                     insert oli;
       }   

}

}