• Ryan Gardner
  • NEWBIE
  • 64 Points
  • Member since 2013

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 7
    Replies
I have an emergency. I need to update over 50k records on our address object. I have a trigger that was working in sandbox but for some reason is now giving a too many soql query error in prod when i try to do a data load using data loader. Can anyone tell me what ive done wrong i thought i had it bulkfied already...
trigger mainShipToAddessTrigger on ShipTo_Address__c (before insert, before update) { 

   List<ShipTo_Address__c> slist = new List<ShipTo_Address__c>();
   List<Contact> contactsToUpdate = new List<Contact>(); 
   for ( ShipTo_Address__c s : trigger.new ) {  
       if ( s.Primary_Billing_Address__c == true) { 
           Contact c = New Contact(Id = s.Contact__c); 
           system.debug('***** UPDATING:'+c.Id+' '+s.Address__c+' '+s.City__c); 
	//	   Address1_2 = String.Valueof(s.Address__c) + String.ValueOf(' ') + String.Valueof(s.Address2__c);
           c.MailingStreet = String.Valueof(s.Address__c) + String.ValueOf(' ') + String.Valueof(s.Address2__c); 
           c.MailingCity = s.City__c; 
           c.MailingState = s.State__c; 
           c.MailingCountry = s.Country__c; 
           c.MailingPostalCode = s.ZIP__c; 
    		contactsToUpdate.add(c);
    //       update c;              

       } 
       if ( s.Default_Shipping_Address__c == true) { 
           Contact c = New Contact(Id = s.Contact__c); 
           system.debug('***** UPDATING:'+c.Id+' '+s.Address__c+' '+s.City__c); 

           c.OtherStreet = String.Valueof(s.Address__c) + String.ValueOf(' ') + String.Valueof(s.Address2__c); 
           c.OtherCity = s.City__c; 
           c.OtherState = s.State__c; 
           c.OtherCountry = s.Country__c; 
           c.OtherPostalCode = s.ZIP__c; 
     		contactsToUpdate.add(c);
     //      update c;  

       } 
		update contactsToUpdate;
   } 

}

 
We are trying to implement a mass edit type VF page that displays a few fields in a list and allows the user to edit one of those fields. We have a requirement that the list be sortable by column. I’ve taken examples from SFDC and pieced together an implementation using an extension class to do the sorting and the standardsetcontroller. The problem we are having is once a user makes edits to the data on the page and presses the Save button, their changes are not saved; When I examine the records the user supposedly edited I see no changes. Moreover, the debug logs do not indicate any updates were done.  What do I need to do to get my VF page to Save (update) the records the user has edited? 

Here is our VF Page:

<apex:page standardController="Ticket1__Ticket__c" extensions="SortingController,selectedSizeController" showHeader="false" recordsetvar="tickets">
    <apex:form >
   
        <apex:pageMessage summary="Selected Collection Size: {!selectedSize}"
            severity="info"
            id="mupms"
        />
        <apex:pageMessage summary="Record Set Size: {!recordsSize}"
            severity="info"
            id="mupmr"
        />
   
        <apex:pageBlock title="Ticket Mass-Update" mode="edit" id="mub1">
            <apex:pageMessages />
           
            <apex:pageBlockSection id="mus1">
                <apex:inputField value="{!Ticket1__Ticket__c.Status__c}" id="status">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputField>
            </apex:pageBlockSection>
           
            <apex:pageBlockButtons location="bottom" id="mubut">
                <apex:commandButton value="Save" action="{!save}" id="butsav"/>
                <apex:commandButton value="Cancel" action="{!cancel}" id="butcan"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
       
        <apex:pageBlock title="Campaign Tickets" id="muselectedlist">
            <apex:pageBlockTable value="{!tickets}" var="tix" id="mutab">
           
                <apex:column >
                    <apex:outputText value="{!tix.Id}" />
                </apex:column>
               
                <apex:column >
                    <apex:outputText value="{!tix.Name}" />
                </apex:column>               
                            
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!sort}" value="Ticket1__tix_LastName__c{!IF(sorterUtil.column=='Ticket1__tix_LastName__c',IF(sorterUtil.sortDirection='ASC','?','?'),'')}">
                            <apex:param value="Ticket1__tix_LastName__c" name="column" assignTo="{!sorterUtil.column}" ></apex:param>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputText value="{!tix.Ticket1__tix_LastName__c}" />
                </apex:column>
               
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!sort}" value="Ticket1__tix_FirstName__c{!IF(sorterUtil.column=='Ticket1__tix_FirstName__c',IF(sorterUtil.sortDirection='ASC','?','?'),'')}">
                            <apex:param value="Ticket1__tix_FirstName__c" name="column" assignTo="{!sorterUtil.column}" ></apex:param>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputText value="{!tix.Ticket1__tix_FirstName__c}" />
                </apex:column>
               
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!sort}" value="Attendee_Role__c{!IF(sorterUtil.column=='Attendee_Role__c',IF(sorterUtil.sortDirection='ASC','?','?'),'')}">
                            <apex:param value="Attendee_Role__c" name="column" assignTo="{!sorterUtil.column}" ></apex:param>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputText value="{!tix.Attendee_Role__c}" />
                </apex:column>
               
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!sort}" value="Status__c{!IF(sorterUtil.column=='Status__c',IF(sorterUtil.sortDirection='ASC','?','?'),'')}">
                            <apex:param value="Status__c" name="column" assignTo="{!sorterUtil.column}" ></apex:param>
                        </apex:commandLink>
                    </apex:facet>
                        <apex:inputField value="{!tix.Status__c}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Here is our controller:

public class SortingController {
//[Select Id, Name, Tickets1__tix_LastName__c, Tickets1__tix_FirstName__c, Attendee_Role__c, Status__c From Tickets1__Ticket__c];

private final ApexPages.StandardSetController cntr;
String qid;

private String defaultSortColumn = 'Tickets1__tix_LastName__c'; /** Set the default sort Column. /
private String sortDirection = 'ASC';
public SortingControllerUtil sorterUtil {get; set;} /* Declare Sorter Utility class Object. /

public SortingController(ApexPages.StandardSetController controller) {

qid = ApexPages.currentPage().getParameters().get('id');
system.debug('Id of object in context is=' + qid);

cntr = (ApexPages.StandardSetController)controller;

sorterUtil = new SortingControllerUtil(defaultSortColumn, sortDirection); /* Create Sorter_UTIL Object. /
}
public List<Tickets1__Ticket__c> getTickets() {
/* Add the column and sort direction value at the end of query.*/
String stringQuery =
  'Select Id, Name, Tickets1__tix_LastName__c, Tickets1__tix_FirstName__c, Attendee_Role__c, Status__c From Tickets1__Ticket__c ' +
  'Where Tickets1__tix_Campaign__c= :qid ' +
  'Order By ' + sorterUtil.getColumn() + ' ' + sorterUtil.getSortDirection() +' NULLS LAST';
return database.query(stringQuery);
}

public PageReference sort() { /* Define sorting method. **/
/** Do nothing here. **/
return null;
}

}
Salesforce provides a list of pre-defined Login Flow Variables:
LoginFlow_UserId
LoginFlow_UserAgent, etc.

As defined in the documentation here: https://help.salesforce.com/HTViewSolution?id=000221887

And here: https://developer.salesforce.com/page/Login-Flows

My understanding is if you create these variables the information is automatically populated by Salesforce as long as you follow the exact naming convention.

I believe I have done that:

User-added image

I include that on an output screen, but nothing shows up
(Output Screen Setup)
User-added image

(Output Result)
User-added image

Which leads me to believe this variable is blank and something else must be done to set this variable? Or that this is a bug? Or the documentation is incomplete? Does anyone have any success using these pre-defined variables?
I have a class backing a visualforce page for a custom forecasting module. Depending on which user is updating the forecast data, I want to update a different set of fields. In my visualforce I display a list of opportunities, and I want to display all the fields I query for regardless of which user is viewing the forecast, i.e. I can't just not query some fields depending on which user I'm dealing with. It looks something like this:
 
//define user roles
Boolean userIsSalesRep = false;
Boolean userIsManager = false;

if(boo=foo){
    userIsSalesRep = true;
}else{
    userIsManager = true;
}
So I have 2 Booleans that show me who I'm dealing with, then I have a method to update the opportunities. When I do the update, I don't want to update certain fields depending on which user is calling the update.
public List<Opportunity> opportunities {get; set;}
......
......

public void save(){

    // I want to do something like this-->
    if(userIsSalesRep){
        for(Opportunity o: opportunities){
            o.remove('fieldXX');
        }
    }

    update(opportunities);
}
Does anybody have a good idea on how to do this. I have some clunky ideas on what I could do, but I really don't want to make it clunky.


 
I have an emergency. I need to update over 50k records on our address object. I have a trigger that was working in sandbox but for some reason is now giving a too many soql query error in prod when i try to do a data load using data loader. Can anyone tell me what ive done wrong i thought i had it bulkfied already...
trigger mainShipToAddessTrigger on ShipTo_Address__c (before insert, before update) { 

   List<ShipTo_Address__c> slist = new List<ShipTo_Address__c>();
   List<Contact> contactsToUpdate = new List<Contact>(); 
   for ( ShipTo_Address__c s : trigger.new ) {  
       if ( s.Primary_Billing_Address__c == true) { 
           Contact c = New Contact(Id = s.Contact__c); 
           system.debug('***** UPDATING:'+c.Id+' '+s.Address__c+' '+s.City__c); 
	//	   Address1_2 = String.Valueof(s.Address__c) + String.ValueOf(' ') + String.Valueof(s.Address2__c);
           c.MailingStreet = String.Valueof(s.Address__c) + String.ValueOf(' ') + String.Valueof(s.Address2__c); 
           c.MailingCity = s.City__c; 
           c.MailingState = s.State__c; 
           c.MailingCountry = s.Country__c; 
           c.MailingPostalCode = s.ZIP__c; 
    		contactsToUpdate.add(c);
    //       update c;              

       } 
       if ( s.Default_Shipping_Address__c == true) { 
           Contact c = New Contact(Id = s.Contact__c); 
           system.debug('***** UPDATING:'+c.Id+' '+s.Address__c+' '+s.City__c); 

           c.OtherStreet = String.Valueof(s.Address__c) + String.ValueOf(' ') + String.Valueof(s.Address2__c); 
           c.OtherCity = s.City__c; 
           c.OtherState = s.State__c; 
           c.OtherCountry = s.Country__c; 
           c.OtherPostalCode = s.ZIP__c; 
     		contactsToUpdate.add(c);
     //      update c;  

       } 
		update contactsToUpdate;
   } 

}

 
help please. how can i prevent duplication of records based on two fields?
    Objects                          Fields
Schedule__c               
Seat__                            Schedule__c(lookup)
Reservation__c            Seat__c(lookup), Schedule__c(lookup), passenger_name__c

i have this code:
trigger PreventSeatDuplication on Reservation__c (before insert, before update) {

    Map<String, Reservation__c> resMap = new Map<String, Reservation__c>();
   
    for (Reservation__c res : System.Trigger.new) {
  
        if ((res.Seat__c != null) && (System.Trigger.isInsert || (res.Seat__c != System.Trigger.oldMap.get(res.Id).Seat__c))) {
            if (resMap.containsKey(res.Seat__c)) {
                res.Seat__c.addError('Seat not available.');
            } else {
                resMap.put(res.Seat__c, res);
            }
       }
    }
  
    for (Reservation__c res : [SELECT Seat__c FROM Reservation__c WHERE Seat__c IN :resMap.KeySet()]) {
        Reservation__c newRes = resMap.get(res.Seat__c);
        newRes.Seat__c.addError('Seat not available.');
    }
}

but it only prevents the same seat # for the same name, for example, if there is already a record on Reservation__c(Passenger_Name__c='test1', Seat__c='1', Schedule__c='sched001') how can i prevent Reservation__c(Passenger_Name__c='test2', Seat__c='1', Schedule__c='sched001') from saving?
help!
  • March 10, 2014
  • Like
  • 0
We are trying to implement a mass edit type VF page that displays a few fields in a list and allows the user to edit one of those fields. We have a requirement that the list be sortable by column. I’ve taken examples from SFDC and pieced together an implementation using an extension class to do the sorting and the standardsetcontroller. The problem we are having is once a user makes edits to the data on the page and presses the Save button, their changes are not saved; When I examine the records the user supposedly edited I see no changes. Moreover, the debug logs do not indicate any updates were done.  What do I need to do to get my VF page to Save (update) the records the user has edited? 

Here is our VF Page:

<apex:page standardController="Ticket1__Ticket__c" extensions="SortingController,selectedSizeController" showHeader="false" recordsetvar="tickets">
    <apex:form >
   
        <apex:pageMessage summary="Selected Collection Size: {!selectedSize}"
            severity="info"
            id="mupms"
        />
        <apex:pageMessage summary="Record Set Size: {!recordsSize}"
            severity="info"
            id="mupmr"
        />
   
        <apex:pageBlock title="Ticket Mass-Update" mode="edit" id="mub1">
            <apex:pageMessages />
           
            <apex:pageBlockSection id="mus1">
                <apex:inputField value="{!Ticket1__Ticket__c.Status__c}" id="status">
                    <apex:actionSupport event="onchange" rerender="muselectedlist"/>
                </apex:inputField>
            </apex:pageBlockSection>
           
            <apex:pageBlockButtons location="bottom" id="mubut">
                <apex:commandButton value="Save" action="{!save}" id="butsav"/>
                <apex:commandButton value="Cancel" action="{!cancel}" id="butcan"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
       
        <apex:pageBlock title="Campaign Tickets" id="muselectedlist">
            <apex:pageBlockTable value="{!tickets}" var="tix" id="mutab">
           
                <apex:column >
                    <apex:outputText value="{!tix.Id}" />
                </apex:column>
               
                <apex:column >
                    <apex:outputText value="{!tix.Name}" />
                </apex:column>               
                            
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!sort}" value="Ticket1__tix_LastName__c{!IF(sorterUtil.column=='Ticket1__tix_LastName__c',IF(sorterUtil.sortDirection='ASC','?','?'),'')}">
                            <apex:param value="Ticket1__tix_LastName__c" name="column" assignTo="{!sorterUtil.column}" ></apex:param>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputText value="{!tix.Ticket1__tix_LastName__c}" />
                </apex:column>
               
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!sort}" value="Ticket1__tix_FirstName__c{!IF(sorterUtil.column=='Ticket1__tix_FirstName__c',IF(sorterUtil.sortDirection='ASC','?','?'),'')}">
                            <apex:param value="Ticket1__tix_FirstName__c" name="column" assignTo="{!sorterUtil.column}" ></apex:param>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputText value="{!tix.Ticket1__tix_FirstName__c}" />
                </apex:column>
               
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!sort}" value="Attendee_Role__c{!IF(sorterUtil.column=='Attendee_Role__c',IF(sorterUtil.sortDirection='ASC','?','?'),'')}">
                            <apex:param value="Attendee_Role__c" name="column" assignTo="{!sorterUtil.column}" ></apex:param>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputText value="{!tix.Attendee_Role__c}" />
                </apex:column>
               
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!sort}" value="Status__c{!IF(sorterUtil.column=='Status__c',IF(sorterUtil.sortDirection='ASC','?','?'),'')}">
                            <apex:param value="Status__c" name="column" assignTo="{!sorterUtil.column}" ></apex:param>
                        </apex:commandLink>
                    </apex:facet>
                        <apex:inputField value="{!tix.Status__c}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Here is our controller:

public class SortingController {
//[Select Id, Name, Tickets1__tix_LastName__c, Tickets1__tix_FirstName__c, Attendee_Role__c, Status__c From Tickets1__Ticket__c];

private final ApexPages.StandardSetController cntr;
String qid;

private String defaultSortColumn = 'Tickets1__tix_LastName__c'; /** Set the default sort Column. /
private String sortDirection = 'ASC';
public SortingControllerUtil sorterUtil {get; set;} /* Declare Sorter Utility class Object. /

public SortingController(ApexPages.StandardSetController controller) {

qid = ApexPages.currentPage().getParameters().get('id');
system.debug('Id of object in context is=' + qid);

cntr = (ApexPages.StandardSetController)controller;

sorterUtil = new SortingControllerUtil(defaultSortColumn, sortDirection); /* Create Sorter_UTIL Object. /
}
public List<Tickets1__Ticket__c> getTickets() {
/* Add the column and sort direction value at the end of query.*/
String stringQuery =
  'Select Id, Name, Tickets1__tix_LastName__c, Tickets1__tix_FirstName__c, Attendee_Role__c, Status__c From Tickets1__Ticket__c ' +
  'Where Tickets1__tix_Campaign__c= :qid ' +
  'Order By ' + sorterUtil.getColumn() + ' ' + sorterUtil.getSortDirection() +' NULLS LAST';
return database.query(stringQuery);
}

public PageReference sort() { /* Define sorting method. **/
/** Do nothing here. **/
return null;
}

}

I am very new to the SalesForce development and the overall environment.

I am trying to create the data model (custom objects) in my Developer Edition instance manually. Where can I find the Objects Name and the field names of all the objects related with Recruiting application. Do I need to use Training Org If I don't have to create this objects manually.

 

Please advise

  • September 14, 2013
  • Like
  • 0
I have tested this trigger multiple times in the Sandbox, and it produces the proper results. However, when I deploy the changes to production, it comes out with different results. Does anyone know how I could trace what is producing the different results in production? I checked workflows and validation rules but couldn't find anything.