+ Start a Discussion
Ap30Ap30 
Hello All,
In standard view we should see only one record at a time. On clicking next button, it should show another single record. Record shown first should not be there. I couldn't implement as i'm new to pagination concept.Please help.

<apex:page standardController="obj__c" extensions="contollername">
 <apex:form >
    <apex:pageBlock title="Student's Data">
  
           <apex:pageBlockTable value="{!listitem}"  var="sd">
            
          <apex:column value="{!sd.First_Name__c}"/>
          <apex:column value="{!sd.Last_Name__c}"/>
          <apex:column value="{!sd.Company__c}"/>
             
                        
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
    <apex:commandButton action="{!previous}" value="Prev"/>
      <apex:commandButton action="{!next}" value="Next"/>
    </apex:pageBlockButtons>
           
       </apex:pageBlock>
   </apex:form>
</apex:page> 

======================
public class contollername
{
    public transient List<obj__c> listitem{get; set;}
    public Integer size {get; set;}

    public contollername(ApexPages.StandardController stdController) {

         size=1;
         setLists();
    }

    public void setLists()
    {
       listitem= [Select First_Name__c,Last_Name__c,Company__c From obj__c limit:size];
    }

   public void next()
   {
      
      setLists();
   }
   
   public void previous()
   {
      
      setLists();
   }
}
Best Answer chosen by Ap30
PriyaPriya (Salesforce Developers) 
Hi,
 

Check below example that matches your requirement :- 

https://developer.salesforce.com/forums/?id=906F0000000BZxWIAW

Please mark as Best Answer so that it can help others in the future.

Regards,

Priya Ranjan


 
Rafi RafiRafi Rafi 
Hi,
I have a requirement I don't know how to get it, Q)ABC containers require the ability to automatically associate a contact created in their salesforce instance with the respective account based on the email domain specified in the primary email address of the contact. The association should happen in real-time as soon as a contact record is created within the system. 1)Develop the necessary piece of apex code to implement a solution 2)necessary test code(with 90% of code coverage)
Thanks in advance,
Rafi
Best Answer chosen by Rafi Rafi
ANUTEJANUTEJ (Salesforce Developers) 
Hi Rafi,

Please try the below snippet.
 
trigger auto_Account_assignment on Contact(before insert) {
    Set<String> emailDomains = new Set<String>();

    for (Contact l : Trigger.New) {
        if (l.Email == null) {
            continue;
        }   

        emailDomains.add(l.Email.split('@').get(1));
    }

    emailDomains.remove(null);
           
    if (!emailDomains.isEmpty()) {
        Map<String, Account> emailDomainToAccountMap = new Map<String, Account>();

        for (Account a : [ 
            select Name,
                Id
            from Account
            where Name in :emailDomains
        ]) {
            emailDomainToAccountMap.put(a.Name, a);
        }   

        for (Contact l : Trigger.New) {
            if (l.Email == null) {
                continue;
            }

            String domain = l.Email.split('@').get(1);

            if (!emailDomainToAccountMap.containsKey(domain)) {
                continue;
            }

            l.AccountId= emailDomainToAccountMap.get(domain).Id;
        }
    }
}
 
@isTest
private class AccountTestClass {
 static testMethod void validateAId() {
Account a= new Account();
a.name='test';
//I am adding only the name but please add all the required fields so that above account record is properly inserted
insert a;
Contact tempc = new contact();
tempc.LastName='TestContact';
tempc.email='primary@test.com';
insert tempc;
Id AI= a.id;
Contact check=[select id,accountid from contact where id in :AI];
system.assert(check.AccountId,AI);
 }
}

Please be noted that the above is a sample snippet and you need to make changes accordingly.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Jennifer Blankenship 12Jennifer Blankenship 12 
knowledge is not in any of my trailhead playgrounds. how do i get it to do trails?
Best Answer chosen by Jennifer Blankenship 12
Kamal ThakurKamal Thakur
Hi Jennifer,

Goto your profile in your trailhead playground. 
Check the "Knowledge User" checkbox and click save. 

Please like this answer and mark it as best if helpful. 

Regards,
Kamal
Manisha ValavalaManisha Valavala 
Hi ,

I am not able to browse third party url in lightning component as it shows below error 

"The domain is not set in 'CSP trusted sites whitelist'

But I have added the third party url in CSP , please assist
Best Answer chosen by Manisha Valavala
SwethaSwetha (Salesforce Developers) 
HI Manisha,
Ensure that you have  added the URL to CSP Errors whitelist using a wildcard like this: https://*.forcecontentuser.com

Also there is a known issue with the lightning:map usage which is worth checking: https://trailblazer.salesforce.com/issues_view?id=a1p3A000001FSlqQAG

If this information helps, please mark the answer as best. Thank you
DiamundoDiamundo 
Hi there.

In my lightning app I have a few components:
  • one component has a ui:inputSelect and registers an event. the ui:inputSelect has a change attribute that fires a function, wherein the selected text (an ID) is put in an event and fired.
  • one component that handles the event, is an aura:iteration list of a component that, on handling the event, should retrieve a list of items where a master-child lookup is the sent ID of the master object. This then displays all those child objects.
  • the other component that handles the event, has three inputText fields, that are supposed to display the other fields of the master object
The problem: either the event seems to not be fired, or the handlers seem to not be activated.

I put console.debug's, alerts and component.set("v.testmessage", "fired") 's in the handlers but they never execute.
I then put one of the handlers as the init-handler and then it did execute the handler (with an undefined ID since the event hadn't yet been fired, which is reasonable).

I have triple-checked the event name, event type and handler action, everything matches. I have no compilation problems, I have no errors when I am using my app. 
I also have no response whatsoever from my event. Any ideas?

**Registering component**
<aura:component controller="PrefixMasterHeaderSelectorController">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:registerEvent name="updateMaster" type="c:PrefixMasterEvent" />
    <aura:attribute name="masters" type="PrefixMaster__c[]"/>
      
    <label class="slds-master-element__label" for="masterSelector">Select a master to work with:</label>
    <div class="slds-master-element__control">
        <div class="slds-select_container">
            
            <ui:inputSelect aura:id="masterID" class="slds-select" change="{!c.masterHasChanged}">
                <aura:iteration items="{!v.masters}" var="master">
                    <ui:inputSelectOption text="{!master.Id}" label="{!master.Name}" />
                    <!-- + ' (Last modified: ' + master.LastModifiedDate + ' by ' + master.LastModifiedBy.Name + ')'}"/> -->
                </aura:iteration>	
                <ui:inputSelectOption text="newMaster" label="Create a new master" />
            </ui:inputSelect>
            
        </div>
    </div>

    <c:PrefixMasterHeaderMaster />
</aura:component>

**Registering controller**
({
    doInit : function(component, event, helper) {
        // Create the action
        var action = component.get("c.getMasters");
    
        // Add callback behavior for when response is received
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.masters", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
    
        // Send action off to be executed
        $A.enqueueAction(action);
    },
    
    masterHasChanged : function(component, event, helper) {
        var masterID = component.find("masterID").get("v.value");
        var masterEvent = component.getEvent("updateMaster");
        masterEvent.setParams({"master" : masterID})
        masterEvent.fire();
        
		console.debug('UPDATE MASTER = ' + masterID);
        alert('Hiya! masterEvent ' + masterEvent.getParam("master"));
    }
		
})

**List-child component**
<aura:component controller="PrefixListChildsController">
	<aura:handler name="updateForm" event="c:PrefixFormEvent" action="{!c.loadChilds}" />
    <aura:attribute name="childs" type="PrefixChild__c[]"/>
    
	<!--   	<aura:handler name="saveChild" event="c:PrefixChildEvent" action="{!c.handleAddItem}"/> -->
    <!--	to reload the masters after adding a new child -->
    
    <div>
        <header class="slds-p-top--small">
            <h3 class="slds-text-heading--small">Childs</h3>
        </header>
        
        <div id="list" class="row">
            <aura:iteration items="{!v.childs}" var="child">
                <aura:if isTrue="{!child.Order__c % 2 == 1}">
                        <div class="slds-p-around--small" style="background-color: lightblue; border-radius: 10px">
                            <c:PrefixChild child="{!child}"/>
                        </div>
                    <aura:set attribute="else" >
                        <div class="slds-p-around--small" style="background-color: none; border-radius: 10px">
                            <c:PrefixChild child="{!child}"/>
                        </div>
                    </aura:set>
                </aura:if>
            </aura:iteration>
            {!v.testEventmessage}
            <c:PrefixNewChild />
        </div>
    </div>

</aura:component>

**List-child controller.js**
({
	loadChilds : function(component, event, helper) {
 	    var action = component.get("c.getChilds");
		var masterID = event.getParam("master");    
    	action.setParams({ "masterID" : masterID });
        
        console.debug('master id = ' + masterID);
        alert('load childs ' + masterID);
        component.set("v.testEventmessage", masterID);

        // Add callback behavior for when response is received
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.childs", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
        
        // Send action off to be executed
        $A.enqueueAction(action);
    }
})


 
Best Answer chosen by Diamundo
DiamundoDiamundo
Solved it...

After I found out that the firing component was able to handle the (component) event, but a component somewhere else (not a parent or child component, but, say, an uncle-component) was not, I changed the type of the event to application. Still didn't work, so I looked up the documentation and saw that an application-type event is registered slightly different.

**APPLICATION-TYPE EVENT:**
<aura:event type="APPLICATION" >
    <aura:attribute name="item" type="sObject__c" />
</aura:event>
**REGISTERING COMPONENT**
<aura:registerEvent name="PrefixMasterEvent" type="c:PrefixMasterEvent" />

**FIRING CONTROLLER**
var applicationEvent = $A.get("e.c:PrefixMasterEvent");
    applicationEvent.setParams({"item" : itemID})
    applicationEvent.fire();
(Note: instead of component.getEvent("eventName") you now use $A.get("e.c:EventName") !
I'm not sure what the 'e' stands for, but I'm pretty sure the 'c' part is the namespace, and be careful to put the name of the event FILE as 'EventName' in the $A.get() parameter.)

**HANDLING COMPONENT**
<aura:handler event="c:PrefixApplicationEvent" action="{!c.doAnotherFunction}" />
(Note: the main difference is: with an application event there is no need (or use) for an event 'name', and I'm not sure why it has to be specified at the registerEvent tag other than it's a required attribute of the tag.)

**HANDLING CONTROLLER**
({
    doAnotherFunction(component, event, helper) {
        var item = event.getParam("item");
        alert('The item is: ' + item);
    }
})




 
Shane QuiringShane Quiring 
Hi Experts,

I need some assitance with a date formula. I trying to calculate the number of months left between two dates, start and end date. I currently have the folloiwng formula:

(Custom_End_Date__c - today ())/30

Which will give me the number of days left and if I divide the number by 30 and I should get the numbner of months. Unfortunately I am short by one month. For example if I have a end date of 12/01/2015 minus today, 30 July, would give me 124 days. If I divide that by 30 I get 4 months, or more exactly 4.13 months. But from July to Dec is 5 months.

Any assistance would be greatly appreciated.

Thank-you
Best Answer chosen by Shane Quiring
CyberJusCyberJus
Dividing by 30 is going to give you slightly inaccurate results because not every month is 30 days. 

If you are only concerned about difference in the actual month - ie July 30th to Aug 1st = 1 month
Try this:
(MONTH(Custom_End_Date__c) + (12*(YEAR(Custom_End_Date__c)-YEAR(TODAY()))) - MONTH(TODAY())
Chris McCartyChris McCarty 
How does one add the Salesforce Trailhead Badges (link) on their Linkedin Profile? When I edit my Linkedin profile where do I do this?
Thanks!
Best Answer chosen by Chris McCarty
Sebastian.PerazaSebastian.Peraza
I just added a badge that i've already had in my LinkedIn profile.
You can go to your LinkedIn profile and under Add certificate -> Certification Name & Certification Authority (Salesforce Trailhead).
That's it.
Akshay ShrivastavaAkshay Shrivastava 
i have created a app ..in which iam using standard objects..i want to restrict user not to see the records created by admin  
Best Answer chosen by Akshay Shrivastava
Suraj Tripathi 47Suraj Tripathi 47

Hi Akshay,

You control record-level access in four ways.
Org-wide defaults specify the default level of access users have to each other’s records.
Role hierarchies ensure managers have access to the same records as their subordinates. Each role in the hierarchy represents a level of data access that a user or group of users needs.
Sharing rules are automatic exceptions to org-wide defaults for particular groups of users, to give them access to records they don’t own or can’t normally see.
Manual sharing lets record owners give read and edit permissions to users who might not have access to the record any other way.

Please refer this link

https://trailhead.salesforce.com/content/learn/modules/data_security/data_security_sharing_rules

 

Please mark it as Best Answer if it helps!

Thank You!

Abilash Kosigi 8Abilash Kosigi 8 
A question on a lighter note. I am new to Salesforce and to this forum. What is the criteria that is followed to award points in the forum. Are there any benefits for the peole who accrue more? :)
Best Answer chosen by thisisnotapril
pconpcon
The points are awarded for answering posts, being chosen as the correct answer and having your posts/answers liked.  As for the benefits, there's the fame that goes along with being known in the developer community and the satisfaction of knowing you've helped your fellow developers.  Also, if you continue to be an outstanding member in the community (doing additional things like giving talks in your local area or blogging about the platform) you could be nomitated for the MVP program [1].

[1] http://www.salesforce.com/mvp/
gbalakrigbalakri 

I am trying to execute the following code for recalling an approval process an ends up getting the following error

 

 

execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: INVALID_OPERATION, Illegal transition type:

 

 Approval.ProcessWorkItemRequest pwr = new Approval.ProcessWorkItemRequest();
       
List<ProcessInstance> procins = new List<ProcessInstance>([select Id from ProcessInstance where Status = 'Pending' and TargetObjectId = :objectId]);
// Retrieve the process work instance id associated to the process instance
            List<ProcessInstanceWorkitem>  workitem = new List<ProcessInstanceWorkitem>([select Id from ProcessInstanceWorkitem where ProcessInstanceId = :procins[0].id]);

            if ((workitem != null) && (workitem.size() > 0))
            {
                pwr.SetComments(statusToUpdate);

                pwr.setWorkItemId(workitem[0].id);
                pwr.setAction('Remove');
            
               
                // Execute process request
                Approval.ProcessResult pr = Approval.process(pwr);

}

Best Answer chosen by Admin (Salesforce Developers) 
jlojlo

 gbalakri - Try changing this line:

 

pwr.setAction('Remove');

 to this:

 

 

 

pwr.setAction('Removed');

 

 

See the docs: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content%2Fapex_ProcessWorkitemRequest.htm|SkinName=webhelp

Message Edited by jlo on 04-08-2009 12:07 PM