• Rafael Sanchez 4
  • NEWBIE
  • 0 Points
  • Member since 2015

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

After reading tons of links, posts and many documents, I decided to ask for help here, hopping some guru can help me with this issue:
 

<!-- Visualforce Remote object component for Products -->
<apex:remoteObjects >
<apex:remoteObjectModel name="PriceBookEntry" jsShorthand="Prod" fields="id, Name, Pricebook2Id, UnitPrice, IsActive">
</apex:remoteObjectModel>
</apex:remoteObjects>

I have done this javascript fuction to display records from PriceBookEntry Object using remoteObject in Javascript:

function fetchPB(){var wh = new SObjectModel.Prod();
    wh.retrieve({
      where:{
            Pricebook2Id : {eq:'01so0000002r3TBAAY'}, 
            IsActive : {eq:true},
            UnitPrice : {gt: 0}
      },
      limit: 5
      },function(err, records){
        if(err) alert(err.message);
        else {
          records.forEach(function(record) {             
            var divCol = $('<div class="row">');
            var p = record.get("Pricebook2Id");
            alert('row => ' + record.toString());
            var detail = $('<p>'+record.get("Name")+'<br/></p>');           
            var link1 = $('<p><br/><input type="check" name="optCheck"></p> ');
            link1.click(function(){              
              $('#inputProduct2').val(record.get("UnitPrice"));
            });
            detail.append(link1);
            h3.append(detail); 
            divCol.append(product);
            divCol.appendTo('#prodRow');
          });
        }
      });      
}

When I execute this function I can see in the developer console of my browser the post action and the data is coming from the server

User-added image
Even I see the data is coming I can't get the object's values, if I display a javascript alert with the object information I can't see values only this:

User-added image

I'm prety sure this answer will be not only a big help for me but for the entire SF comunity.

Thanks in Advance.

After reading tons of links, posts and many documents, I decided to ask for help here, hopping some guru can help me with this issue:
 

<!-- Visualforce Remote object component for Products -->
<apex:remoteObjects >
<apex:remoteObjectModel name="PriceBookEntry" jsShorthand="Prod" fields="id, Name, Pricebook2Id, UnitPrice, IsActive">
</apex:remoteObjectModel>
</apex:remoteObjects>

I have done this javascript fuction to display records from PriceBookEntry Object using remoteObject in Javascript:

function fetchPB(){var wh = new SObjectModel.Prod();
    wh.retrieve({
      where:{
            Pricebook2Id : {eq:'01so0000002r3TBAAY'}, 
            IsActive : {eq:true},
            UnitPrice : {gt: 0}
      },
      limit: 5
      },function(err, records){
        if(err) alert(err.message);
        else {
          records.forEach(function(record) {             
            var divCol = $('<div class="row">');
            var p = record.get("Pricebook2Id");
            alert('row => ' + record.toString());
            var detail = $('<p>'+record.get("Name")+'<br/></p>');           
            var link1 = $('<p><br/><input type="check" name="optCheck"></p> ');
            link1.click(function(){              
              $('#inputProduct2').val(record.get("UnitPrice"));
            });
            detail.append(link1);
            h3.append(detail); 
            divCol.append(product);
            divCol.appendTo('#prodRow');
          });
        }
      });      
}

When I execute this function I can see in the developer console of my browser the post action and the data is coming from the server

User-added image
Even I see the data is coming I can't get the object's values, if I display a javascript alert with the object information I can't see values only this:

User-added image

I'm prety sure this answer will be not only a big help for me but for the entire SF comunity.

Thanks in Advance.

Hi All,

I'm quite new into development and I was looking for answer. We need to have a particular picklist field(Lead_Status__c) in Contact be updated to "Qualified" after the lead was converted with an Opportunity (during conversion of the lead, optionally adding new Opportunity). 

We tried to use workflow and process builder but it end up as "false" in the debug log, so the option is via apex. I manage to do some search in sites and found this code:
 
Trigger Lead on Lead (after update) {

    if (Trigger.isAfter) {

        if (Trigger.isUpdate) { 

            Map<ID,ID> oppToContact = new Map<ID,ID>(); 

            for (Lead ld : Trigger.new) {
                if(ld.isConverted && trigger.oldMap.get(ld.id).isConverted) continue; //only process newly converted leads

                // Find all converted Leads with Opportunitiy and add ConvertedOpportunityId to setConvertedOppIds
                if (ld.ConvertedOpportunityId != null && ld.ConvertedContactId != null){                    
                    oppToContact.put(ld.ConvertedOpportunityId,ld.ConvertedContactID);  

                }

            }
I might need to find the additional code to add here to update the Lead Status in Contact if this particular record was converted from a lead and with added opportunity upon conversion, can anyone please help me on this code? Im quite new in this development and would really like to explore further. Please see image below of the supposed field to update when the Lead converted to Contact and was added opportunity during conversion. field name is Lead_Status__c (picklist field)


User-added image


Thank you for the answer

Israel

After reading tons of links, posts and many documents, I decided to ask for help here, hopping some guru can help me with this issue:
 

<!-- Visualforce Remote object component for Products -->
<apex:remoteObjects >
<apex:remoteObjectModel name="PriceBookEntry" jsShorthand="Prod" fields="id, Name, Pricebook2Id, UnitPrice, IsActive">
</apex:remoteObjectModel>
</apex:remoteObjects>

I have done this javascript fuction to display records from PriceBookEntry Object using remoteObject in Javascript:

function fetchPB(){var wh = new SObjectModel.Prod();
    wh.retrieve({
      where:{
            Pricebook2Id : {eq:'01so0000002r3TBAAY'}, 
            IsActive : {eq:true},
            UnitPrice : {gt: 0}
      },
      limit: 5
      },function(err, records){
        if(err) alert(err.message);
        else {
          records.forEach(function(record) {             
            var divCol = $('<div class="row">');
            var p = record.get("Pricebook2Id");
            alert('row => ' + record.toString());
            var detail = $('<p>'+record.get("Name")+'<br/></p>');           
            var link1 = $('<p><br/><input type="check" name="optCheck"></p> ');
            link1.click(function(){              
              $('#inputProduct2').val(record.get("UnitPrice"));
            });
            detail.append(link1);
            h3.append(detail); 
            divCol.append(product);
            divCol.appendTo('#prodRow');
          });
        }
      });      
}

When I execute this function I can see in the developer console of my browser the post action and the data is coming from the server

User-added image
Even I see the data is coming I can't get the object's values, if I display a javascript alert with the object information I can't see values only this:

User-added image

I'm prety sure this answer will be not only a big help for me but for the entire SF comunity.

Thanks in Advance.

I wrote a Trigger on Lead that creates an Opportunity Team Member when a Lead is converted and it has ConvertedOpportunityId.  The Opportunity Team Member should have UserId = Lead OwnerId and has a specific role (for example - "Account Manager").  

 

I tested converting a Lead that was owned by me and the Opportunity was created with an Opportunity Team Member = me and role was Account Manager, so I thought the Trigger worked fine.  Then I tested converting a Lead that was owned by another user.  The Opportunity was created with the same owner as the Lead Owner, but there was no Opportunity Team Member.  I added some debug statements to catch if the Opportunity Team Member was really created and it did (at least) in the debug log.  One of the debugs showed that the Opportunity Team Member was created from the Trigger and it had me (the person who converted the Lead) as the Member.  Another debug showed that I was the Opportunity Owner, but when I checked in the UI, the Opportunity Owner was actually the other user.  

 

Here is my Lead Trigger.

Trigger Lead on Lead (before insert, before update) {
	 	
	if (Trigger.isBefore) {
		
		if (Trigger.isUpdate) {	
					
			Set<Id> setLeadIds     = new Set<Id>();  
			Set<Id> setConvertedOppIds   = new Set<Id>();  
			
			for (Lead ld : Trigger.new) {

				// Find all converted Leads with Opportunitiy and add ConvertedOpportunityId to setConvertedOppIds
				if (ld.isConverted && ld.ConvertedOpportunityId != null 
					&& Trigger.oldMap.get(ld.Id).ConvertedOpportunityId != ld.ConvertedOpportunityId) 
					setConvertedOppIds.add(ld.ConvertedOpportunityId);			
			}		

			if (!setConvertedOppIds.isEmpty()) {
				List<OpportunityTeamMember> lstOppTeams = new List<OpportunityTeamMember>();
				// Get Opportunities that created from the Lead conversion
				List<Opportunity> lstConvertedOpps = [select Id, OwnerId from Opportunity where Id in :setConvertedOppIds];
				if (lstConvertedOpps.size() > 0) {					
					for (Opportunity opp : lstConvertedOpps) {
						OpportunityTeamMember otm = new OpportunityTeamMember(
								   TeamMemberRole = 'Account Manager', 
						           OpportunityId  = opp.Id,
						           UserId         = opp.OwnerId);
						lstOppTeams.add(otm);
					}
					// Insert Opportunity Team
					if (!lstOppTeams.isEmpty()) {
						for (Opportunity opp : lstConvertedOpps) {
							System.debug('===== before inserting OTMs, opp = ' + opp);
						}
						System.debug('===== inserting OTMs: ' + lstOppTeams);
						
						insert lstOppTeams;
						
						for (OpportunityTeamMember otm : [select id, UserId, TeamMemberRole from OpportunityTeamMember where OpportunityId in :setConvertedOppIds])
							System.debug('===== OTM after insert: ' + otm);
						
						lstConvertedOpps = [select Id, OwnerId from Opportunity where Id in :setConvertedOppIds];
						for (Opportunity opp : lstConvertedOpps) {
							System.debug('===== after inserting OTMs, opp = ' + opp);
						}
					}
				}
			}
		}		
	} 	
}

 

 

So, I wonder if we can really write a Trigger on Lead that creates an Opportunity Team Member that belongs to a different user?

Also, can we catch what happens during the Lead Conversion, like why there seems to be some opportunity owner changing during that time but we couldn't really see that?

 

Out of the curiousity, I wrote a Trigger on Opportunity just for debug to see if I could catch the opportunity change.  Strangely, I was unable to do that.  The debugs only showed that I was the opportunity owner right before Insert and also after insert.  Nothing showed that the other user was the opportunity owner until I checked in the UI.

 

Here is the opportunity Trigger.

Trigger Opportunity on Opportunity (after insert, after update, before insert, before update) {

	String str = '';
	str += (Trigger.isBefore) ? 'Before ' : 'After ';
	if (Trigger.isInsert) str += 'Insert: ';
	if (Trigger.isUpdate) str += 'Update: ';

	for (Opportunity opp : Trigger.new) {
		System.debug('===== ' + str + ' Opp Id=' + opp.id + '   OwnerId=' + opp.OwnerId);
	}

}