• Juliver Anoos
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
trigger AS_checkprimaryproduct on OpportunityLineItem (after insert) {

 
    Set<Id> oppId = new Set<Id>();
    List<OpportunityLineItem> queryAllSavedOPL = new List<OpportunityLineItem>();
    List<OpportunityLineItem> primaryProList = new List<OpportunityLineItem>();

    //get OpportunityId to where the product is created
    for(OpportunityLineItem newOLI : trigger.new)
    {
        oppId.add(newOLI.OpportunityId);
    }

    //fiLter Products FROM the Opportunity to get one record (with the oLdest CreatedDate)
    queryAllSavedOPL = [SELECT Id, Name, CreatedDate, AS_Primary_Item__c, OpportunityId 
                        FROM OpportunityLineItem
                        WHERE OpportunityId in:oppId
                        ORDER BY CreatedDate ASC LIMIT 1];

    System.debug('Opp Line Item'+queryAllSavedOPL);

    //set the queried Product to primary by setting AS_Primary_Item__c to true
    for(OpportunityLineItem primaryItem : queryAllSavedOPL)
    {
        primaryItem.AS_Primary_Item__c = true;
        primaryProList.add(primaryItem);
    }
    update primaryProList; 
    System.debug('Primary OppLineItem Product: '+ primaryProList);

}

this trigger will check the primary product that has the oldest createddate. it worked but someone toLd me this needs to be optimized..

I have a component to save guest to guest list. This component is now a public site. if guest exists in contact or lead it will fetch that contact id, same in Lead, and if does not exist, guest info will be saved to Lead. I added a confirmation pop up to inform that guest exists in the list when attempting to save and ask if im going to update the new mobile and email. 
My problem is i cant update the new email and phone after Clicking the 'Ok' Pop Up Confirmation Confirmation. any help pLs
After clicking okay, the phone and email of the contact/lead wont update..
This is what i made so far:
Modal Component: assuming i already have my attributes.

 

Guest_Info.cmp

<!-- Start of Guest Info Reg Form -->
    <aura:renderIf isTrue="{!v.isReg}">
        <div class="demo-only" style="height: 640px;">
            <section role="dialog" aura:id="Modalbox" tabindex="-1" aria-labelledby="modal-heading-01" aria-hidden = "true"  aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open hideY">
                <div class="slds-modal__container recordEditForm" >
                    <span id="closeText" onclick="{!c.handleCancel}">X</span>
                    <header class="slds-modal__header recordEditForm">
                        <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">{!'Event: '+v.objGuestInfoClass.getEvent.Name}</h2>
                    </header>
                    <div class="slds-modal__content slds-form-element__label slds-p-around_medium recordEditForm" id="modal-content-id-1">
                        <div aria-labelledby="newguestform">
        					
    							<div class="slds-align_absolute-center GUEST INFO">
							        <lightning:card  title="GUEST INFO">
							            <div class="slds-p-horizontal--small" style="width:100%;">
							                <lightning:input aura:id="newGuest" label="First Name" value="{!v.fname}"/>
							                <lightning:input aura:id="newGuest" label="Last Name" value="{!v.lname}"/>
							                <lightning:input aura:id="newGuest" label="Mobile Phone" value="{!v.mphone}"/>
							                <lightning:input aura:id="newGuest" label="Email" value="{!v.guestEmail}"/>
							                <br/>
							                <lightning:button label="Save" variant="brand" onclick="{!c.checkAndSave}"/>&nbsp;
											<lightning:button label="Cancel" variant="brand" onclick="{!c.closemodal}"/>
							            </div>
							        </lightning:card>
    							</div>
    						
    					</div> 
                    </div>
                    <!-- <footer class="slds-modal__footer recordEditForm"> 
							
                    </footer>  -->
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open hideY" aura:id="Modalbackdrop"></div>
        </div>
    </aura:renderIf>
<!-- End of Guest Info Reg Form -->
Guest_InfoController.js
checkAndSave : function(component, event, helper) {
		var guestFname = component.get("v.fname");
		var guestLname = component.get("v.lname");
		var guestMphone = component.get("v.mphone");
        var guestEmail = component.get("v.guestEmail");
		var guestEventId = component.get("v.guestEventId");
		console.log('Firstname'+ guestFname);
		console.log('Lastname'+ guestLname);
		console.log('MobilePhone'+ guestMphone);
		console.log('GuestEmail'+ guestEmail );
		var action = component.get("c.searchContactsAndLeads");
			action.setParams ({fname:guestFname,
							   lname:guestLname,
							   mphone:guestMphone,
							   guestEmail:guestEmail,
                               eventId:guestEventId });
			action.setCallback(this, function(a) {
           	var state = a.getState();
            if (state === "SUCCESS") {
                var name = a.getReturnValue();
                console.log(name);
                if(confirm('Guest Saved: '+guestFname+' '+guestLname)){
                helper.refresh(component, event);
                } else {
                  helper.refresh(component, event); 
                  }  
            } else { 
            	if(confirm('Already listed in the Guest List: '+guestFname+' '+guestLname+'\nWould you like to update New mobile and Email?\n \nMobile: '+guestMphone+'\nEmail: '+guestEmail)){
                var gFname = component.get("v.fname");
                var gLname = component.get("v.lname");
                var gMphone = component.get("v.mphone");
                var gEmail = component.get("v.guestEmail");
                var gEventId = component.get("v.guestEventId");
                helper.updateNewPhoneEmail(component, event, gFname, gLname, gMphone, gEmail, gEventId); 
                 } else { 
                helper.refresh(component, event); 
                }
            }
        });
			$A.enqueueAction(action);
	},

Guest_InfoHelper.js
updateNewPhoneEmail : function(component, event, gFname, gLname, gMphone, gEmail, gEventId){
                
                var action2 = component.get("c.addNewPhoneEmail");
                    action2.setParams ({fname:gFname,
                                        lname:gLname,
                                        mphone:gMphone,
                                        guestEmail:gEmail,
                                        eventId:gEventId }); 
                            action2.setCallback(this, function(b) {
                            var state2 = b.getState();
                                if (state2 === "SUCCESS") {
                                    var name2 = b.getReturnValue();
                                    console.log('get state2'+name2);
                                    confirm('updated: '+gFname+' '+gLname)
                                    component.set("v.objGuestInfoClass", name2);
                                }     
                        });
                $A.enqueueAction(action2);

                var cmpTarget = component.find('Modalbox');
                var cmpBack = component.find('Modalbackdrop');
                var myTable = document.getElementById("myTable");
                var fixHeader = document.getElementById("fixHeader");
                $A.util.removeClass(cmpBack,'slds-backdrop_open');
                $A.util.removeClass(cmpTarget, 'slds-fade-in-open');
                $A.util.removeClass(myTable, 'hideY');
                $A.util.removeClass(fixHeader, 'hideY');
                component.set("v.isReg",false); 

        }

Guest_info_apexcla.cls
@Auraenabled
    public static List<Guest_List__c> addNewPhoneEmail (String fname, String lname, String mphone, String guestEmail, String eventId) {
    	Guest_info_apexcla getEventRec = new Guest_info_apexcla();
		getEventRec.eventId  = eventId;

		System.debug('Check strings'+fname+' '+lname+' '+mphone+' '+guestEmail+' '+eventId);

		List<Contact> existingContact = [SELECT Id, Name, MobilePhone, Email FROM Contact WHERE FirstName =: fname AND LastName =: lname LIMIT 1];
		List<Lead> existingLead = [SELECT Id, Name, MobilePhone, Email FROM Lead WHERE FirstName =: fname AND LastName =: lname LIMIT 1];
		System.debug('Check existingContact'+existingContact);
		System.debug('Check existingLead'+existingLead);

		Contact cont = existingContact[0];
		Lead leadToupdate = existingLead[0];
		if(!existingContact.isEmpty()){
			cont.MobilePhone = mphone;
			cont.Email = guestEmail;
		} else if(!existingLead.isEmpty()){
			leadToupdate.MobilePhone = mphone;
			leadToupdate.Email = guestEmail;
		}

		update leadToupdate;
		update cont;
		
		return [select Id, Name, Contact__r.Id, Contact__r.FirstName, Contact__r.LastName, Contact__r.Name, Contact__r.MobilePhone, Contact__r.Email,
								Lead__r.Id, Lead__r.FirstName, Lead__r.LastName, Lead__r.Name, Lead__r.MobilePhone, Lead__r.Email
								from Guest_List__c 
								where GuestEvent__c =: getEventRec.eventId ORDER BY Lead__r.Name, Contact__r.Name ASC];
	
    }

 
Hi , i need help. i need a test class for this method from the class name, ASPP_PaymentSource_Controller.cls
@AuraEnabled
    public static Map<String, String> savePS(ASPayment_Source__c ps, String gatewayId){
        System.debug('PS Handed: ' + ps);
        if(ps != null){
            Map<String, String> info = new Map<String, String>();

            Id cardRT = RecordTypeHelper.getRecordTypeIDByName('ASPayment_Source__c', 'Credit_Card');
            Id bankRT = RecordTypeHelper.getRecordTypeIDByName('ASPayment_Source__c', 'Bank');

            if(ps.RecordTypeId == cardRT || ps.RecordTypeId == bankRT){
                try{
                    upsert ps;
                    
                    info.put('message', 'Payment Source successfully created/udpdated.');
                    info.put('id', ps.Id);
                    info.put('isSucess', 'true');

                    return info;
                }catch(Exception e){
                    info.put('message', e.getMessage());
                    info.put('isSucess', 'false');

                    return info;
                }
            }// end if
            
            // Validate if Payment Source have contact or account
            if(ps.PPContact__c == null && ps.Account__c == null){
                info.put('message', 'Payment Source requires either Account or Contact.');
                info.put('isSucess', 'false');

                return info;
            }

            Map<String, String> result = new Map<String, String>();
            
            if(ps.Id != null){
                ASPayment_Source__c oldPS = [Select Id, Name, RecordTypeId, Account__c, 
                                                 PPContact__c, Active__c, Gateway_Payment_Type__c, 
                                                 Card_Name__c, Card_Expiry_Month__c, 
                                                 Card_Expiry_Year__c, token_Card_CCV__c, 
                                                 token_Card_Number__c, Credit_Card_Type__c, 
                                                 Account_BSB__c, Account_Name__c, 
                                                 token_Account_Number__c 
                                             FROM ASPayment_Source__c 
                                             WHERE Id =: ps.Id];
                
                if(oldPS != null){
                    if((ps.Gateway_Payment_Type__c == 'Bank' && (ps.Account_Name__c == oldPS.Account_Name__c && ps.Account_BSB__c == oldPS.Account_BSB__c && ps.token_Account_Number__c == oldPS.token_Account_Number__c)) || 
                        (ps.Gateway_Payment_Type__c == 'Credit Card' && (ps.Card_Name__c == oldPS.Card_Name__c && ps.token_Card_Number__c == oldPS.token_Card_Number__c && ps.Credit_Card_Type__c == oldPS.Credit_Card_Type__c && ps.Card_Expiry_Month__c == oldPS.Card_Expiry_Month__c && ps.Card_Expiry_Year__c == oldPS.Card_Expiry_Year__c && PS.token_Card_CCV__c == oldPS.token_Card_CCV__c))) 
                    {
                        try{
                            update ps;
                            result.put('PaymentSourceID',String.valueOf(ps.Id));
                            result.put('status','200');
                            result.put('message','Payment Source Updated');
                        }catch(Exception e){
                            result.put('status','500');
                            result.put('message',e.getMessage());
                        }
                    } else result = ProcessPayment.setPS(ps, gatewayId);
                } //end of if(oldPS != null)
            }else{
                if(ps.Gateway_Payment_Type__c == 'Credit Card'){
                    ps.Account_Name__c = null;
                    ps.token_Account_Number__c = null;
                    ps.Account_BSB__c = null;
                }else {
                    ps.Card_Name__c = null;
                    ps.token_Card_Number__c  = null;
                    ps.Credit_Card_Type__c = null;
                    ps.Card_Expiry_Month__c = null;
                    ps.Card_Expiry_Year__c = null;
                    ps.Card_CCV__c = null;
                }
                
                result = ProcessPayment.setPS(ps, gatewayId); 
            } 
            
            info.put('message', result.get('message'));
            if(result.get('status') !=  '500'){
                info.put('id', result.get('PaymentSourceID'));
                info.put('isSucess', 'true');
            }else info.put('isSucess', 'false');
            
            return info;    
        }else return null;
    }
thanks in advance..
 
trigger AS_checkprimaryproduct on OpportunityLineItem (after insert) {

 
    Set<Id> oppId = new Set<Id>();
    List<OpportunityLineItem> queryAllSavedOPL = new List<OpportunityLineItem>();
    List<OpportunityLineItem> primaryProList = new List<OpportunityLineItem>();

    //get OpportunityId to where the product is created
    for(OpportunityLineItem newOLI : trigger.new)
    {
        oppId.add(newOLI.OpportunityId);
    }

    //fiLter Products FROM the Opportunity to get one record (with the oLdest CreatedDate)
    queryAllSavedOPL = [SELECT Id, Name, CreatedDate, AS_Primary_Item__c, OpportunityId 
                        FROM OpportunityLineItem
                        WHERE OpportunityId in:oppId
                        ORDER BY CreatedDate ASC LIMIT 1];

    System.debug('Opp Line Item'+queryAllSavedOPL);

    //set the queried Product to primary by setting AS_Primary_Item__c to true
    for(OpportunityLineItem primaryItem : queryAllSavedOPL)
    {
        primaryItem.AS_Primary_Item__c = true;
        primaryProList.add(primaryItem);
    }
    update primaryProList; 
    System.debug('Primary OppLineItem Product: '+ primaryProList);

}

this trigger will check the primary product that has the oldest createddate. it worked but someone toLd me this needs to be optimized..
Hi , i need help. i need a test class for this method from the class name, ASPP_PaymentSource_Controller.cls
@AuraEnabled
    public static Map<String, String> savePS(ASPayment_Source__c ps, String gatewayId){
        System.debug('PS Handed: ' + ps);
        if(ps != null){
            Map<String, String> info = new Map<String, String>();

            Id cardRT = RecordTypeHelper.getRecordTypeIDByName('ASPayment_Source__c', 'Credit_Card');
            Id bankRT = RecordTypeHelper.getRecordTypeIDByName('ASPayment_Source__c', 'Bank');

            if(ps.RecordTypeId == cardRT || ps.RecordTypeId == bankRT){
                try{
                    upsert ps;
                    
                    info.put('message', 'Payment Source successfully created/udpdated.');
                    info.put('id', ps.Id);
                    info.put('isSucess', 'true');

                    return info;
                }catch(Exception e){
                    info.put('message', e.getMessage());
                    info.put('isSucess', 'false');

                    return info;
                }
            }// end if
            
            // Validate if Payment Source have contact or account
            if(ps.PPContact__c == null && ps.Account__c == null){
                info.put('message', 'Payment Source requires either Account or Contact.');
                info.put('isSucess', 'false');

                return info;
            }

            Map<String, String> result = new Map<String, String>();
            
            if(ps.Id != null){
                ASPayment_Source__c oldPS = [Select Id, Name, RecordTypeId, Account__c, 
                                                 PPContact__c, Active__c, Gateway_Payment_Type__c, 
                                                 Card_Name__c, Card_Expiry_Month__c, 
                                                 Card_Expiry_Year__c, token_Card_CCV__c, 
                                                 token_Card_Number__c, Credit_Card_Type__c, 
                                                 Account_BSB__c, Account_Name__c, 
                                                 token_Account_Number__c 
                                             FROM ASPayment_Source__c 
                                             WHERE Id =: ps.Id];
                
                if(oldPS != null){
                    if((ps.Gateway_Payment_Type__c == 'Bank' && (ps.Account_Name__c == oldPS.Account_Name__c && ps.Account_BSB__c == oldPS.Account_BSB__c && ps.token_Account_Number__c == oldPS.token_Account_Number__c)) || 
                        (ps.Gateway_Payment_Type__c == 'Credit Card' && (ps.Card_Name__c == oldPS.Card_Name__c && ps.token_Card_Number__c == oldPS.token_Card_Number__c && ps.Credit_Card_Type__c == oldPS.Credit_Card_Type__c && ps.Card_Expiry_Month__c == oldPS.Card_Expiry_Month__c && ps.Card_Expiry_Year__c == oldPS.Card_Expiry_Year__c && PS.token_Card_CCV__c == oldPS.token_Card_CCV__c))) 
                    {
                        try{
                            update ps;
                            result.put('PaymentSourceID',String.valueOf(ps.Id));
                            result.put('status','200');
                            result.put('message','Payment Source Updated');
                        }catch(Exception e){
                            result.put('status','500');
                            result.put('message',e.getMessage());
                        }
                    } else result = ProcessPayment.setPS(ps, gatewayId);
                } //end of if(oldPS != null)
            }else{
                if(ps.Gateway_Payment_Type__c == 'Credit Card'){
                    ps.Account_Name__c = null;
                    ps.token_Account_Number__c = null;
                    ps.Account_BSB__c = null;
                }else {
                    ps.Card_Name__c = null;
                    ps.token_Card_Number__c  = null;
                    ps.Credit_Card_Type__c = null;
                    ps.Card_Expiry_Month__c = null;
                    ps.Card_Expiry_Year__c = null;
                    ps.Card_CCV__c = null;
                }
                
                result = ProcessPayment.setPS(ps, gatewayId); 
            } 
            
            info.put('message', result.get('message'));
            if(result.get('status') !=  '500'){
                info.put('id', result.get('PaymentSourceID'));
                info.put('isSucess', 'true');
            }else info.put('isSucess', 'false');
            
            return info;    
        }else return null;
    }
thanks in advance..
 
How can take entire metadata backup of my production org apart from using Force.com IDE or Third party priced tools.
Solutions and suggestion are welcome, thanks in advance.