• A.Zaykov
  • NEWBIE
  • 25 Points
  • Member since 2016

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

Hi All,

Let's say you have a trigger which populates a lookup field on the opportunity with a team member with a specific role.

How do you handle the owner Default Opportunity Team:

https://help.salesforce.com/articleView?id=customize_teamselling.htm&type=5

Regards,

Angel

Hi,

When using <lightning:recordEditForm>, validation rules do not kick in.

Is this a general issue?

Thanks.
Angel
Hi guys,

My business requirement is to create a quick action which clones opportunity with products in Lightning.

I have created a flow which stores the opportunity products and attach them to the new opportunity.

I was wondering how to pass the Id of the new opportunity to the flow variable "VarT_NewOpportunityId".

Here's the code:
 
<aura:component implements="force:lightningQuickAction,lightning:availableForFlowActions,force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global">
 
     <aura:attribute name="opportunityRecord" type="Object"/>
    <aura:attribute name="clonedOpportunityId" type="String"/>
        <lightning:flow aura:id="flowData"/> 
    <force:recordData aura:id="oppRecord"
                      recordId="{!v.recordId}"
                      layoutType="FULL"
                      targetFields="{!v.opportunityRecord}"/>
   <!--    <aura:handler name="init" value="{!this}" action="{!c.newOpportunity}" /> -->

    <button class="slds-button slds-button_neutral" onclick="{!c.newOpportunity}">Next</button>

</aura:component>
 
({
	newOpportunity : function(component, event, helper) {
		var createOpportunity = $A.get("e.force:createRecord");
		createOpportunity.setParams({
  			"entityApiName": "Opportunity",
    		"defaultFieldValues": {
                'Name' : component.get('v.opportunityRecord.Name'),
                'AccountId' : component.get('v.opportunityRecord.AccountId'),
                'StageName' : component.get('v.opportunityRecord.StageName'),
                'ForecastCategoryName' : component.get('v.opportunityRecord.ForecastCategoryName'),
                'Probability' : component.get('v.opportunityRecord.Probability')
    }
});

	createOpportunity.fire();
     
            var flow = component.find("flowData");
            var inputVariables = [
               {
                  name : "VarT_OldOpportunityId",
                  type : "String",
                  value: component.get("v.opportunityRecord.Id")
               },
                
                {
                    name: "VarT_NewOpportunityId",
                    type : "String",
                    value : "Id of the new opportunity"
                }
               
            ];    
            flow.startFlow("CloneOpportunityProducts", inputVariables);
   
         }
	
})

Any ideas would be much appreciated.

Regards,
Angel
Hi,

I am trying to substitute a quick action (submitting a case for account to be removed) with a lightning component.

I need to prepopulate the Case.ContactId with the id of the internal contact attached to the user.

Here's the component:
 
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="caseCreate">
 <!--including lightning styles-->
    <ltng:require styles="{/assets/styles/salesforce-lightning-design-system.css'}"/>
     <ltng:require styles="{/assets/styles/salesforce-lightning-design-system.min.css'}"/>
    <aura:attribute name="contact" type="Contact" 
               default="{ 'sobjectType': 'Contact' }"/>
<aura:handler name="init" value="{!this}" action="{!c.loadContact}" /> 
<!-- Preparation of case object with fields-->
    <aura:attribute name="caseObj" type="Case"  default="{'sobjectType':'Case',
                                                         'Type':'Remove/Merge Account',
                                                            'Subtype':'',
                                                          'Subject':'',
                                                         'Priority':'Medium',
                                                         'Status':'New/Not Started',
                                                       'Description':''}"/> 
   <div class="slds">
       <div class="slds-form-element">
          <label class="slds-form-element__label" for="Type">Type</label>
          <div class="slds-form-element__control">
              <ui:inputText aura:id="type" class="slds-input" value="{!v.caseObj.Type}" placeholder="Remove/Merge Account" />
          </div>
        </div>
       <div class="slds-form-element">
          <label class="slds-form-element__label" for="Subtype">Subtype</label>
          <div class="slds-form-element__control">
            <ui:inputText aura:id="subtype" class="slds-input" value="{!v.casedObj.Subtype__c}" placeholder="--None--" />
          </div>
        </div>
       <div class="slds-form-element">
          <label class="slds-form-element__label" for="Subject">Subject</label>
          <div class="slds-form-element__control">
            <ui:inputText aura:id="subject" class="slds-input" value="{!v.casedObj.Subject}" placeholder="--None--" />
          </div>
        </div>
       <div class="slds-form-element">
          <label class="slds-form-element__label" for="Email">Priority</label>
          <div class="slds-form-element__control">
            <ui:inputText aura:id="priority" class="slds-input" value="{!v.caseObj.Priority}" placeholder="Medium" />
          </div>
        </div>
       <div class="slds-form-element">
          <label class="slds-form-element__label" for="Status">Status</label>
          <div class="slds-form-element__control">
              <ui:inputText aura:id="status" class="slds-input" value="{!v.caseObj.Status}" placeholder="New/Not Started" />
          </div>
        </div>
       <div class="slds-form-element">
          <label class="slds-form-element__label" for="Description">Description</label>
          <div class="slds-form-element__control">
              <ui:inputText aura:id="description" class="slds-input" value="{!v.caseObj.Description}" placeholder="" />
          </div>
        </div>
       <div class="slds-form-element">
          <label class="slds-form-element__label" for="ContactName">Contact Name</label>
          <div class="slds-form-element__control">
             <ui:inputText aura:id="description" class="slds-input" value="{!v.caseObj.ContactId}" placeholder="{!v.contact.Id}" />
          </div>
        </div>
       <div class="slds-form-element">        
          <div class="slds-form-element__control">
            <ui:button label="Save" press="{!c.save}"/>
          </div>
        </div>
 </div>
</aura:component>
The ContactId is internal contact attached to the user.

JS Controller:
 
({  
    
    loadContact : function(component, event, helper) {
    	var action = component.get("c.getContact");
    	action.setCallback(this, function(response) {
    		var state = response.getState();
    			if(state === "SUCCESS") {
    				component.set("v.contact", response.getReturnValue());
    				console.log(response.getReturnValue());
				}
           
		});
		$A.enqueueAction(action);
	},
    
     save : function(component, event, helper) {    
     var action = component.get("c.createCaseRecord");
            action.setParams({"caseObj":component.get("v.caseObj")});
            action.setCallback(this,function(result){
            component.set("v.isShow",true);
            var caseId = result.getReturnValue();
            var toastEvent = $A.get("e.force:showToast");
						toastEvent.setParams({
    					title: "Success!",
   						message: "You have successfully submitted the case",
   						type: "Success"
						});	
			toastEvent.fire();
        });
         $A.enqueueAction(action);
 	}
})
Apex class:
public class caseCreate {
@auraenabled
    public static Id createCaseRecord(Case caseObj){
        upsert caseObj;
        return caseObj.id;
    }
    
    @AuraEnabled
    public static Contact getContact(){
        return [SELECT id, Name FROM Contact WHERE Email=: UserInfo.getUserEmail() LIMIT 1];
    }
}
Any help/advice would be much appreciated.

Thanks!


 
Hello,

The business requirement is to have a lookup relation ship between a Contract and Opportunity. A field on the opportunity must get the SUM of a custom field on the Contracts which belong to the opportunity.

On mass update, I get an error "first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record"

After I lock the Account record, I get "First error: Record Currently Unavailable: The record you are attempting to edit, or one of its related records, is currently being modified by another user. Please try again."
 
public class contractRollUpCLASS {
    @future
    public static void calculate(Set<Id> recordIds) {
  
    List<Contract> contrList = [SELECT Id, AccountId, Renewal_Opportunity__c FROM Contract WHERE Id IN : recordIds];
    Set<Id> oppIds = new Set<Id>();
    Set<Id> accIds = new Set<Id>();
    
    for(Contract con : contrList) {
        oppIds.add(con.Renewal_Opportunity__c);
        accIds.add(con.AccountId);
        
    }
        
//lock the account
    List<Account> accList = [SELECT Id FROM Account WHERE Id IN : accIds FOR UPDATE];
    
    
    //Map will contain one Opportunity Id to one sum value.
    map<Id, Double> OpportunityMap = new Map<Id,Double>();
    
    List<Opportunity> oppsToUpdate = new List<Opportunity>();
    
    //aggregate result.
    for(AggregateResult q : [SELECT Renewal_Opportunity__c, SUM(Latest_PD_Renewal_Amount__c) sumLatest FROM Contract WHERE Renewal_Opportunity__c IN : oppIds AND Latest_PD_Renewal_Amount__c != null GROUP BY Renewal_Opportunity__c]) {
  
        OpportunityMap.put((Id)q.get('Renewal_Opportunity__c'),(Double)q.get('sumLatest'));
    }
    
    for(Opportunity opp : [SELECT Id, Annual_Maintenance_Value__c, AccountId FROM Opportunity WHERE Id IN : oppIds]) {
 
        Double sumLatestPD = OpportunityMap.get(opp.Id);
        opp.Annual_Maintenance_Value__c = sumLatestPD;
        oppsToUpdate.add(opp);     
    }    

        update oppsToUpdate;   

    }
}


Any ideas how I can bypass this issue?
Thanks,

Angel

Hello,

The business requirement is to have a lookup relation ship between a Contract and Opportunity. A field on the opportunity must get the SUM of a custom field on the Contracts which belong to the opportunity. I use the @future annotation to increase the CPU time, however, I get an error "Attempt to de-reference a null object".

Here's the code. I got the error on line 6 where I define the Set<ID>
public class contractRollUpCLASS {
    @future
    public static void calculate() {
  
    //limit the size of list by using Sets which do not contain duplicate elements.
    Set<ID> oppIds = new Set<ID>();

    
    //when adding new or updating existing contracts.
    if(trigger.isInsert || trigger.isUpdate) {
        
        for(Contract con : (List<Contract>)trigger.new) {
        
            if(con.Is_Obsolete__c == false)
            oppIds.add(con.Renewal_Opportunity__c);
        }
    }
    
    
    //when deleting contracts.
    if(trigger.isDelete){
        
        for(Contract con : (List<Contract>)trigger.old ) {
           if(con.Is_Obsolete__c == false)
            oppIds.add(con.Renewal_Opportunity__c);
        }
    } 
    System.debug('***************NUMBER OF IDS ************** : '+ String.ValueOf(oppIds.size()));
    
    //Map will contain one Opportunity Id to one sum value.
    map<Id, Double> OpportunityMap = new Map<Id,Double>();
    
    List<Opportunity> oppsToUpdate = new List<Opportunity>();
    
    //aggregate result.
    for(AggregateResult q : [SELECT Renewal_Opportunity__c, SUM(Latest_PD_Renewal_Amount__c) sumLatest FROM Contract WHERE Renewal_Opportunity__c IN : oppIds AND Latest_PD_Renewal_Amount__c != null GROUP BY Renewal_Opportunity__c]) {
        OpportunityMap.put((Id)q.get('Renewal_Opportunity__c'),(Double)q.get('sumLatest'));
    }
    
    for(Opportunity opp : [SELECT Id, Annual_Maintenance_Value__c FROM Opportunity WHERE Id IN : oppIds]) {

        Double sumLatestPD = OpportunityMap.get(opp.Id);
        opp.Annual_Maintenance_Value__c = sumLatestPD;
        oppsToUpdate.add(opp);     
    }    
    update oppsToUpdate;   
    
}
}

Any help would be much appreciated.
Angel
 
Hi all,

The idea is: When a user has been deactivated, assign all of his/her contacts to the owner of the account they belong to.
Using the "isActive" field in the IF condition does not work. If I use different field, the code works.
public class InactiveUser {
    
    public static void deactivateUser(List<User> triggerNew, Map<Id, User> oldMap) {
        
    Set<Id> usersId = new Set<Id>();
    
    for(User us : triggerNew) {
        
        if(oldMap.get(us.Id).isActive != us.isActive && us.isActive == false) {
            usersId.add(us.Id);
        }
    }    
    //create a list of all contacts which belong to the inactive users
    List<Contact> contactsList = new List<Contact>();
    contactsList = [SELECT Id, OwnerId, Account.OwnerId FROM Contact WHERE OwnerId IN: usersId];
    
    List<Contact> contactsToBeUpdated = new List<Contact>();
    
    //loop through the Contact list and change the ownerId to the Account.OwnerId
    
    for(Contact c : contactsList) {
        c.OwnerId = c.Account.OwnerId;
        contactsToBeUpdated.add(c);
    }
    
    if(contactsToBeUpdated.size() > 0) {
            
            try {         
                update contactsToBeUpdated;
            } catch (System.DmlException ex) {
                System.debug(ex);
            }
        }  
    }     
}

Thanks,
Angel
Hi guys,

I don't understand why I get "System.LimitException: Apex CPU time limit exceeded" on mass update.

Basically I want to count opportunity team members with specific role and store the counter in a custom field on opportunity level.
 
Trigger roleUpdateOnly on OpportunityTeamMember (after update) {
  
  
  Set<Id> setOpptyIdsUpdateOnly = new Set<Id>();
  
    
    for(OpportunityTeamMember optm: Trigger.new) {
        if(trigger.isUpdate){
        
         String oldRole = trigger.OldMap.get(optm.Id).TeamMemberRole;
             if(oldRole == 'specific role' || optm.TeamMemberRole == 'specific role') {
                setOpptyIdsUpdateOnly.add(optm.OpportunityId);
             }
           }
        }  
  
  List<Opportunity> listOpps= [Select id,Counter_specific_role__c ,
 (Select id from OpportunityTeamMembers WHERE TeamMemberRole = 'specific role')
 from Opportunity where Id in : setOpptyIdsUpdateOnly];

  for(Opportunity opp :listOpps) {
   
   opp.Counter_specific_role__c = opp.opportunityTeamMembers.size();
  }
  update listOpps; 
   
}


Thanks in advance.
 
Hi guys,

Is there a posibility to pass the value of:

<apex:outputText value="{!Sum}"/> to a custom field on the account object ?

Thanks
Hi guys,

I don't understand why I get "System.LimitException: Apex CPU time limit exceeded" on mass update.

Basically I want to count opportunity team members with specific role and store the counter in a custom field on opportunity level.
 
Trigger roleUpdateOnly on OpportunityTeamMember (after update) {
  
  
  Set<Id> setOpptyIdsUpdateOnly = new Set<Id>();
  
    
    for(OpportunityTeamMember optm: Trigger.new) {
        if(trigger.isUpdate){
        
         String oldRole = trigger.OldMap.get(optm.Id).TeamMemberRole;
             if(oldRole == 'specific role' || optm.TeamMemberRole == 'specific role') {
                setOpptyIdsUpdateOnly.add(optm.OpportunityId);
             }
           }
        }  
  
  List<Opportunity> listOpps= [Select id,Counter_specific_role__c ,
 (Select id from OpportunityTeamMembers WHERE TeamMemberRole = 'specific role')
 from Opportunity where Id in : setOpptyIdsUpdateOnly];

  for(Opportunity opp :listOpps) {
   
   opp.Counter_specific_role__c = opp.opportunityTeamMembers.size();
  }
  update listOpps; 
   
}


Thanks in advance.