• KevinSnell
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies

Hey all,

Hoping someone can help me with this simple issue.

I have the following jQuery which calculates the total for each row as the user inputs the data.  I need to show the total to the user before they committ the data to the database.  

<script>
       var j$ = jQuery.noConflict();

       j$(document).ready(function(){
           
           j$("[id$='qty'], [id$='cst']").blur(function(){
               var unitCost = j$("[id$='cst']").val();
               var quantity = j$("[id$='qty']").val();
               var totCost = +unitCost + +quantity;
               j$("[id$='tol']").val(totCost);
           });
       });
  </script>

Unfortunatlely it only works on the first row.  As far as I can tell the issue is around the jQuery not handling the row id's correct so it doesn't understand what it should be calculating.  For example the first row has the id: j_id0:j_id5:j_id6:wtable:0:cst and the next row id is: j_id0:j_id5:j_id6:wtable:1:cst.  So the number is increasing each time a row is being added.

So I need some help to add the number to the variables in the jQuery.

If anyone can help it would be really appreciated.

Thanks

Kev

Hi all,

 

So I've been searching for an answer but not come up with an answer so hoping the experts here can help.


Currently with Communities Self Registration the contact record related to the user which is created on registration is current linked to one account set in the CommunitiesSelfRegController (see below):

 

/**
 * An apex page controller that supports self registration of users in communities that allow self registration
 */
public with sharing class CommunitiesSelfRegController {

    public String firstName {get; set;}
    public String lastName {get; set;}
    public String email {get; set;}
    public String password {get; set {password = value == null ? value : value.trim(); } }
    public String confirmPassword {get; set { confirmPassword = value == null ? value : value.trim(); } }
    public String communityNickname {get; set { communityNickname = value == null ? value : value.trim(); } }
    
    public CommunitiesSelfRegController() {}
    
    private boolean isValidPassword() {
        return password == confirmPassword;
    }

    public PageReference registerUser() {
    
           // it's okay if password is null - we'll send the user a random password in that case
        if (!isValidPassword()) {
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, Label.site.passwords_dont_match);
            ApexPages.addMessage(msg);
            return null;
        }    

        String profileId = null; // To be filled in by customer.
        String roleEnum = null; // To be filled in by customer.
        String accountId = ''; // To be filled in by customer.
        
        String userName = email;

        User u = new User();
        u.Username = userName;
        u.Email = email;
        u.FirstName = firstName;
        u.LastName = lastName;
        u.CommunityNickname = communityNickname;
    u.ProfileId = profileId;
        
        String userId = Site.createPortalUser(u, accountId, password);
      
        if (userId != null) { 
            if (password != null && password.length() > 1) {
                return Site.login(userName, password, null);
            }
            else {
                PageReference page = System.Page.CommunitiesSelfRegConfirm;
                page.setRedirect(true);
                return page;
            }
        }
        return null;
    }
}

 

My question is:  Has anybody modified the controller so an account is created for each contact when the user registers?

 

Thanks

Kev

Hi All,

 

I'm new to coding and am struggling. I have the following code but am onlying getting 37% code coverage :

 

trigger trg_LeadToCampaign on Lead (after update, after insert) {
    
    //Create a new set to hold all the Leads with CampaignId - Set will contain information in <LeadId - CampaignId> format
    Set<String> existingCampaignMembers = new Set<String>();

    //Query CampaignMember object and fetch all the members related to current context Leads
    for(CampaignMember cM : [Select LeadId, CampaignId from CampaignMember where LeadId IN: Trigger.newMap.keySet()]) {
        
        //Add in set
        existingCampaignMembers.add(cM.LeadId + '-' + cM.campaignId);
    }
    
    
    //Create a list to hold all the CampaignMember records to be inserted
    List<CampaignMember> cMembers = new List<CampaignMember>();

    //Loop through Trigger.New records and check if member need to be created
    for(Lead l : Trigger.New) {
        
        //Check if campaign is not null
        if (l.HubSpot_Campaign__c != null ) {
            
            //Create string to check the existing leads
            String uniquenessCriteria = l.Id + '-' + l.HubSpot_Campaign__c;
            
            //Check in set if this lead is already associated with any campaign record 
            //and only create the CampaignMember if Lead and Campaign is not found in set
            if(!existingCampaignMembers.contains(uniquenessCriteria)){
                
                //Create a new Campign member record
                CampaignMember cm = new CampaignMember();
                cm = new CampaignMember();
                cm.LeadId = l.Id;
                cm.CampaignId = l.HubSpot_Campaign__c;
                cm.Status = 'Responded';

                //Add this record in the list of Campaign Members to be inserted
                cMembers.add(cm);
            }
        }
        
   //Insert records in database
    if(cMembers.size() > 0)
        database.insert( cMembers, false);
      }  
    }

 

@isTest
private class test_trgr_leadtocampaign {

    public static testMethod void testleadtocampaign()
    {
        
    System.debug('VistageDebug: entering TriggerTests_LeadtoCampaign');
    
    //Create Campaign
    Campaign testCampaign = new Campaign(Name='Test', IsActive=True);
    insert testCampaign;
    
    //Create Lead AND Add to Campaign
    Lead testLead = new Lead(FirstName='Bart', LastName='Simpson', Company='The Simpsons',
      Status=VistageConstants.LEAD_INITIAL_STATUS, Country='US', PostalCode='92130',
      Email='scooby@doo.com', List_Assignment__c = 'Reserve',
      RecordTypeId=VistageConstants.LEAD_RECORDTYPE_UK_Member_Candidate);
    insert testLead;

    //Create Campaign Member
    CampaignMember newcm = new CampaignMember (LeadId=testLead.Id, CampaignId=testCampaign.Id);
    insert newcm;
    
    
    //Create Lead
    Lead newLead = new Lead(FirstName='Scooby', LastName='Doo', Company='Mystery, Inc',
    Status=VistageConstants.LEAD_INITIAL_STATUS, Country='US', PostalCode='92130',
    Email='scooby@doo.com', List_Assignment__c = 'Reserve',
    RecordTypeId=VistageConstants.LEAD_RECORDTYPE_UK_Member_Candidate);
    insert newLead;
 
    //Add Campaign Id to Hubspot Campaign Field to fire trigger
    Lead updateMe = [SELECT Id FROM Lead WHERE Id = :newLead.Id];
    updateMe.HubSpot_Campaign__c = testCampaign.Id;
    update updateMe;

    //Check Lead is in Campaign
    CampaignMember afterupdate = [SELECT Lead.id, CampaignId, HasResponded  FROM CampaignMember WHERE lead.id= :newlead.id AND campaignid = :testcampaign.id];
    System.assert(afterupdate.lead.id == newlead.id);
}
}

 

I'm struggling with the following pieces of code:

 //Add in set
        existingCampaignMembers.add(cM.LeadId + '-' + cM.campaignId);
    }
    

And

//Create string to check the existing leads
            String uniquenessCriteria = l.Id + '-' + l.HubSpot_Campaign__c;

 

If anyone code help it would be really appreciated as I need to get this code deployed asap.

 

Thanks


Kev

 

Hi All,

 

I'm new to coding and am struggling. I have the following code but am onlying getting 37% code coverage :

 

trigger trg_LeadToCampaign on Lead (after update, after insert) {
    
    //Create a new set to hold all the Leads with CampaignId - Set will contain information in <LeadId - CampaignId> format
    Set<String> existingCampaignMembers = new Set<String>();

    //Query CampaignMember object and fetch all the members related to current context Leads
    for(CampaignMember cM : [Select LeadId, CampaignId from CampaignMember where LeadId IN: Trigger.newMap.keySet()]) {
        
        //Add in set
        existingCampaignMembers.add(cM.LeadId + '-' + cM.campaignId);
    }
    
    
    //Create a list to hold all the CampaignMember records to be inserted
    List<CampaignMember> cMembers = new List<CampaignMember>();

    //Loop through Trigger.New records and check if member need to be created
    for(Lead l : Trigger.New) {
        
        //Check if campaign is not null
        if (l.HubSpot_Campaign__c != null ) {
            
            //Create string to check the existing leads
            String uniquenessCriteria = l.Id + '-' + l.HubSpot_Campaign__c;
            
            //Check in set if this lead is already associated with any campaign record 
            //and only create the CampaignMember if Lead and Campaign is not found in set
            if(!existingCampaignMembers.contains(uniquenessCriteria)){
                
                //Create a new Campign member record
                CampaignMember cm = new CampaignMember();
                cm = new CampaignMember();
                cm.LeadId = l.Id;
                cm.CampaignId = l.HubSpot_Campaign__c;
                cm.Status = 'Responded';

                //Add this record in the list of Campaign Members to be inserted
                cMembers.add(cm);
            }
        }
        
   //Insert records in database
    if(cMembers.size() > 0)
        database.insert( cMembers, false);
      }  
    }

 

@isTest
private class test_trgr_leadtocampaign {

    public static testMethod void testleadtocampaign()
    {
        
    System.debug('VistageDebug: entering TriggerTests_LeadtoCampaign');
    
    //Create Campaign
    Campaign testCampaign = new Campaign(Name='Test', IsActive=True);
    insert testCampaign;
    
    //Create Lead AND Add to Campaign
    Lead testLead = new Lead(FirstName='Bart', LastName='Simpson', Company='The Simpsons',
      Status=VistageConstants.LEAD_INITIAL_STATUS, Country='US', PostalCode='92130',
      Email='scooby@doo.com', List_Assignment__c = 'Reserve',
      RecordTypeId=VistageConstants.LEAD_RECORDTYPE_UK_Member_Candidate);
    insert testLead;

    //Create Campaign Member
    CampaignMember newcm = new CampaignMember (LeadId=testLead.Id, CampaignId=testCampaign.Id);
    insert newcm;
    
    
    //Create Lead
    Lead newLead = new Lead(FirstName='Scooby', LastName='Doo', Company='Mystery, Inc',
    Status=VistageConstants.LEAD_INITIAL_STATUS, Country='US', PostalCode='92130',
    Email='scooby@doo.com', List_Assignment__c = 'Reserve',
    RecordTypeId=VistageConstants.LEAD_RECORDTYPE_UK_Member_Candidate);
    insert newLead;
 
    //Add Campaign Id to Hubspot Campaign Field to fire trigger
    Lead updateMe = [SELECT Id FROM Lead WHERE Id = :newLead.Id];
    updateMe.HubSpot_Campaign__c = testCampaign.Id;
    update updateMe;

    //Check Lead is in Campaign
    CampaignMember afterupdate = [SELECT Lead.id, CampaignId, HasResponded  FROM CampaignMember WHERE lead.id= :newlead.id AND campaignid = :testcampaign.id];
    System.assert(afterupdate.lead.id == newlead.id);
}
}

 

I'm struggling with the following pieces of code:

 //Add in set
        existingCampaignMembers.add(cM.LeadId + '-' + cM.campaignId);
    }
    

And

//Create string to check the existing leads
            String uniquenessCriteria = l.Id + '-' + l.HubSpot_Campaign__c;

 

If anyone code help it would be really appreciated as I need to get this code deployed asap.

 

Thanks


Kev