• Richie D
  • SMARTIE
  • 915 Points
  • Member since 2008

  • Chatter
    Feed
  • 33
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 26
    Questions
  • 184
    Replies

So I've got a trigger that changes the contact owner to the account owner anytime a new contact is created.  I am trying to test it but am getting only 80%. I can't figure out how to get it to tell that the change actually happened.  I tried adding a system assert message but can't figure out the verbage that it is looking for.  If you could take a look and help me out that would be great.  The two lines that aren't being covered in my trigger are:

mapAccountToOwner.put(a.Id, a.OwnerId);

and

c.OwnerID = mapAccountToOwner.get(c.AccountId);

and here's the test class I have so far:

@IsTest
private class AccountContactOwner
{
    private static TestMethod void testTrigger(){
        
        //Step 1 : Data Insertion
        Account a=new Account(Name='Test Account');
           insert a;
           Contact c = new Contact(FirstName='John',LastName='Doe');
        insert c;
        
        
        test.startTest();
        
        
        //Perform the dml action on which trigger gets fired , like insert, update ,delete , undelete, in your case you have to update account record that you created in above  
        //create test user
            Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
      User u1 = new User(Alias = 'standa', Email='saplingstandarduser@testorg.com',
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
      LocaleSidKey='en_US', ProfileId = p.Id,
      TimeZoneSidKey='America/Los_Angeles', UserName='saplingstandarduser@testorg.com');


      System.runAs(u1) {
      // The following code runs as user 'u'  
       // create test contact
        Contact c1 = new Contact(FirstName='Jane',LastName='Doe');
        insert c1;
        
        //assert your results using system.assert and system.asserEquals
        
        system.assert(c.OwnerID = a.OwnerID);
        
        
        
        test.stopTest();
    }
}
}

Hi,

 

I'm trying to set a "default" value to a lookup field called Carrier on Opportunity Product.

My Opportunity Product also have a text field called Default Carrier.

Every product have a default carrier, so i  want to set a default value for my lookup field.( the salesman can choose an other Carrier if they want).

 

I know that we can't use the workflow to populate the lookup field so i tried the trigger below:

 

trigger SetCarrier on Account (before insert) {
    for(OpportunityLineItem op : Trigger.new){
       op.Carrier__c = [Select Carrier__c.Id from Carrier__c Where Carrier__c.Name = :op.Default_carrier__c];
    }
}

 i got this error message:

 

Save error: Illegal assignment from LIST<Carrier__c> to Id

 

But in every case i'll not have a list =/.

 

 

I need some direction.  I currently have two lists - one called upgrades and the other called serial number / upgrades.  What I want my code to do is compare the values in the upgrades list with the values in the serial number / upgrades list.  If a value on the upgrades list is found on the serial number / upgrades list then don't do anything.   However, if a value on the upgrades list is NOT found on the serial number / upgrades list, then add that value to the serial number / upgrades list.  Both lists are variable in size, meaning that they could have 1 value or as many as 40 values.  How can I achieve this, with apex code preferably inside of a trigger? 

 

UPGRADES                                                          SN/UPGRADES

UG-001   <-----compare This     To all of these ---->   UG-004

                                                                                   UG-001 This value found, don't add it again.

UG-002 <-- This value            is not found here -->     ----       So add it to SN/UPGRADE list. 

UG-003 <-- This value            is not found here -->     ----        So add it to SN/UPGRADE list.

 

 

Any help would be appreciated.

 

 

Is it possible to create a formula for a field update to look at 2 different lookup fields and depending on which one is selected to populate a specfic text field?

 

Example: Product Owned (lookup) is blank but Asset (lookup) is not and pull in the product name text field based off of the selection.

 

IF(OR(
NOT(ISBLANK(Product_Owned__c)),Product_Owned__r.ProductName__c,
IF(
NOT(ISBLANK(Asset__c)),Asset__r.ProductName__c )))

 

Any info would be greatly appreciated.

I have a Set<String> called selectedDesignations.

I have a select list that when a user clicks 'move up' or 'move down', the item is re-positioned within the list.

 

By using debug statements, I can see that the list is getting re-ordered the way I need it to.

The problems is re-Rendering the list, it doesnt want to re-paint.

 

I have had this problem before, and I can't really tell how I solved it. Previously I had some ajax activity that would not fire off. I moved a few pageBlock items and panels around and then it worked. So, not really a realiable solution.

 

Any ideas why I cannot get the outputpanel id = "selected" and the select list id = "selected_designation_list" to re-Render properly?

 

Code:

 

<apex:pageBlockSection title="Designations" collapsible="false" id="des">

	<apex:actionRegion >
		<table>
		<tr>
		<td><apex:outputPanel id="available">
		<apex:selectList id="unselected_designation_list" required="false" value="{!highlightedDesignations}" multiselect="true" size="10">

		<apex:selectOptions value="{!unSelectedOptionsDesignations}" />
		</apex:selectList>
		</apex:outputPanel>
		</td>
		</tr>



		<tr>
		<td><apex:outputPanel id="buttons">
		<apex:commandButton value="Add" action="{!doSelect}" reRender="available,selected">
		<apex:param name="designationListName" value="designations" assignTo="{!listName}" />

		</apex:commandButton>
		<br />
		<apex:commandButton value="Remove" action="{!doUnSelect}" reRender="selected,available">
		<apex:param name="designationListName" value="designations" assignTo="{!listName}" />
		</apex:commandButton>
		</apex:outputPanel>
		</td>
		</tr>



		<tr>
		<td><apex:outputPanel id="selected">
		<apex:selectList id="selected_designation_list" required="false" value="{!unHighlightedDesignations}" multiselect="true" size="10">
		<apex:selectOptions value="{!selectedOptionsDesignations}" />
		</apex:selectList>
		</apex:outputPanel>
		</td>
               <td><apex:outputPanel id="move">
	<apex:commandButton immediate="false" status="processingStatus" action="{!reOrderDesignations}" value="Move Up" reRender="des,available,selected">
	<apex:param name="designationDirection" value="up" assignTo="{!DESIGNATION_MOVE_DIRECTION}" />
	</apex:commandButton>
	<br />
	<br />
	<apex:commandButton immediate="false" status="processingStatus" action="{!reOrderDesignations}" value="Move Down" reRender="des,available,selected">
	<apex:param name="designationDirection" value="down" assignTo="{!DESIGNATION_MOVE_DIRECTION}" />
											</apex:commandButton>
	</apex:outputPanel>
	</td>
</tr>
	</table>

	</apex:actionRegion>

	</apex:pageBlockSection>





public void reOrderDesignations(){
	//re order unHighlightedDesignations(list item 0) inside the list called selectedDesignations(set)
	
	
	String SELECTED = unHighlightedDesignations.get(0);
	
	if(unHighlightedDesignations.size() == 1){
		Integer myCount = 0;
		Integer myResult;
		for(String s: selectedDesignations){
			
			if(s.equals(SELECTED)){
				myResult = myCount;	
				
				break;
			}else{
				myCount++;
			}

		}
		
		
		
		String temp;
		Integer x=0;
		//convert set to list
		List<String> items = new List<String>(selectedDesignations);
		
		if(myResult!= 0){
			if(this.DESIGNATION_MOVE_DIRECTION.equalsIgnoreCase('up')){
				x = myResult-1;
				temp = items.get(x);
				
				items[myResult] = temp;
				items[myResult-1] = SELECTED;
				
						
			}else if(this.DESIGNATION_MOVE_DIRECTION.equalsIgnoreCase('down')){
				x = myResult+1;
				temp = items.get(x);
				items[myResult] = temp;
				items[myResult+1] = SELECTED;
			}
			
		Integer size = items.size();
		this.selectedDesignations.clear();
		//////////////////////////////////////////////////
		for(Integer y = 0; y < size;y++ ){
			this.selectedDesignations.add(items[y]);
			System.debug('Item2: '+items[y]);
		}
	
			
		}
		
		
	}
	
	
}

 

hi

 

Im new to APEX and VF.

 

I'm trying to create a bread crumbs system for my pages. The idea is to add pages to map and than loop through the map and build the bread crumbs.

 

The problem Im facing is the order of the items interated over the loop is not the same of items added in the map.

 

Do you guys know how to loop and maintain the original item order?

 

this is my code

 

 breadCrumbs = new Map<String,String>{'Home'=>'/apex/Home','Build Car'=>'/apex/Build_car'};

 for (String fieldName : breadCrumbs.keySet()){
     sBreadCrumbs = sBreadCrumbs + '<a href="' + breadCrumbs.get(fieldName) + '">' + fieldName + '</a>'; 
 }

 

Any ideas how to maintain the order in the loop?

 

 

 

 

hi

 

here's blocktable in my page:

----------------------------------------------------------------------------------------------------------------------------------------------------

      <apex:pageBlockTable id="CampaignHierarchyList" value="{!campaign}" var="ch" rendered="{!NOT(ISNULL(campaign))}" >
            <apex:column HeaderValue="Campaign Name" style="width:40%">
                <apex:outputLink title="" value="/{!ch.Camp.Id}">
                <apex:outputText value="{!ch.Camp.name}"/>
                </apex:outputLink>
            </apex:column>

            <apex:column HeaderValue="Federal Contacts" style="width:15%">
                <apex:outputField value="{!ch.fedCount}" />
            </apex:column>

            <apex:column HeaderValue="Federal Responses" style="width:15%">
                <apex:outputField value="{!ch.fedResponse}"/>
            </apex:column>
            
            <apex:column HeaderValue="Non-Federal Contacts" style="width:15%">
                <apex:outputField value="{!ch.NonfedCount}"/>
            </apex:column>

            <apex:column HeaderValue="Non-Federal Responses" style="width:15%">
                <apex:outputField value="{!ch.NonfedResponse}"/>
            </apex:column>
        </apex:pageBlockTable>

 

 

and my class for my pageblock:

-------------------------------------------------------------------------------------------------------------------------------------------------

public list<cCampaign> lCampaign;

 

public List<cCampaign> getcampaign(){        
    Campaign[] campParent = [Select Id, Name, NumberOfContacts, HierarchyNumberOfContacts, NumberOfResponses, HierarchyNumberOfResponses
                             from Campaign where id = :c.Id];        

        ChCmembers =  [Select Contact.Id from CampaignMember where Campaignid = :campParent[0].id];               
        for (CampaignMember cm : ChCmembers){
            ConHIds.add(cm.Contact.Id);
        }
        
        //get federal contacts ids
        for (Contact Con : [Select ID From Contact where Id in: ConHIds and Account.Federal_Account__c  = true]){
            FederalConIds.add(Con.Id);
        }
        
        //get non federal contacts ids
        for (Contact Con : [Select ID From Contact where Id in: ConHIds and Account.Federal_Account__c  = false]){
            NonFederalConIds.add(Con.Id);
        }


        Campaign[] campChild = [Select Id,Owner.UserRoleId from Campaign where Parent_Campaign_Name__c like: campParent[0].name];
        for (integer i = 0; i < campChild.size();i++){
            setUserRoleId.add(campChild[i].Owner.UserRoleId);                       
        }
        
        cCampaign x = new cCampaign(campParent[0]);
        x.sFederalConIds=FederalConIds;
        x.sNonFederalConIds=NonFederalConIds;
        lCampaign.add(x);                     
        
        CmParent.add(campParent[0].Id);
        CmParentName.add(campParent[0].Name);
       
        return lCampaign;    
}

    

public class cCampaign{
        public Campaign Camp{get;set;}
        public set<Id> sFederalConIds {get;set;}
        public set<Id> sNonFederalConIds {get;set;}
        public integer fedCount {get;set;}        
        public integer fedResponse {get;set;}        
        public integer NonfedCount {get;set;}        
        public integer NonfedResponse {get;set;}        

        public cCampaign(Campaign c){
            Camp = c;
            fedCount = [Select count() From Contact where Id in: sFederalConIds and Account.Federal_Account__c  = true];
            fedResponse = [Select count() from CampaignMember where Contact.Id in: sFederalConIds  and HasResponded = true and Campaignid=:c.id];
            NonfedCount = [Select count() From Contact where Id in: sNonFederalConIds and Account.Federal_Account__c  = false];
            NonfedResponse = [Select count() from CampaignMember where Contact.Id in: sNonFederalConIds  and HasResponded = true and Campaignid=:c.id];
        }
    
}

  • February 17, 2012
  • Like
  • 0

Hi There,

I have an interesting prolem.

1. I create a new Accounts' view and for condition I set:

    DateTimeFieldX equals 31/01/2012 15:45

    I save the view and it returns me a record with the DateTimeFieldX equaling: 2012-01-31T15:45:03.000Z.

    From that I can see that it is ignoring the :03 milliseconds part.

 

2. I open the Force.com Explorer and I type in the following query:

    SELECT  Name FROM Account where DateTimeFieldX = 2012-01-31T15:45:00Z and I get nothing which is understandable

     because I have 00 for milliseconds.

 

The question is how to the where clause condition in 2 above to ignore the milliesconds value and to return me whatever 1 above returns.

To put this into perspective I am building a where clause in .Net which is similar to SF's and I let users enter date and time up-to the millisecond.

 

For those of you who are looking for a solution on how to cnovert DateTime to a DateTime field suitable for SOQL query in .Net here it is:
 public string Convert(DateTime obj, Field field = null)
 {
     return System.Xml.XmlConvert.ToString(obj, System.Xml.XmlDateTimeSerializationMode.Utc);
  }

 

Thanks,

Kos

 

Hi,

 

 

How to identify first element in list?

 

For e.g.

 

             

for(Schedule_Task__c st:lstScheduleTask)

         {

         

             if(lstScheduleTask==0) // Is there any way to find out this is first element.

             {

                // 

             }

             else

             {

                //

 

}

}

 

Thanks and Regards,

Devendra S

Hi,

 

I am having a strange behaviour where i am rerending a pageblocksection  with apex:repeat in it.

There is a lot of code which gets displayed on the page before the rerendered block.

 

Here is the VF code

<apex:pageblocksection id="tableApp" >
    
<table >

<apex:repeat var="slot" value="{!LstString}">
    <tr>
        <td><apex:outputText value="{!slot}"/></td>
    </tr>   
</apex:repeat>
 </table>
</apex:pageblocksection>  

 LstString is just a string list with values 'Hello1' and 'Hello', these do get displayed after all the code. Below is just someportion of the code

window.parent.ViewstateInspectorComponent.reload([{"displayName": "View State","name": "View State","viewstateSize": 6.94,"percentOfParent": 100.0,"percentOfTotalViewstate": 100.0,"leaf": false,"isGroupable": false,"identityCode": "6e523dd735efff132c1e67c5262c35e","children": [{"displayName": "Component Tree","name": "Component Tree","viewstateSize": 0.86,"percentOfParent": 12.0,"percentOfTotalViewstate": 12.0,"leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "17edd43e203dfc18ed7fe6e7be261c5e"},{"displayName": "State","name": "State","viewstateSize": 6.31,"percentOfParent": 91.0,"percentOfTotalViewstate": 91.0,"leaf": false,"isGroupable": false,"identityCode": "af39ef0b8654ec315b38a3ef99899c9b","children": [{"displayName": "Expressions","name": "Expressions","viewstateSize": 0.78,"percentOfParent": 12.0,"percentOfTotalViewstate": 11.0,"leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "1323ef8c11294a914f516bc978c31c0c"},{"displayName": "Controllers","name": "Controllers","viewstateSize": 1.38,"percentOfParent": 22.0,"percentOfTotalViewstate": 20.0,"leaf": false,"isGroupable": false,"identityCode": "942eb2063c41d08a0ca6aa51b630f33a","children": [{"displayName": "AppointmentController","name": "AppointmentController","type": "Page appointment Controller","viewstateSize": 1.38,"percentOfParent": 100.0,"percentOfTotalViewstate": 20.0,"leaf": false,"iconCls": "task","isGroupable": false,"identityCode": "cb8e372ef47deb542dbcebdaee026829","children": [{"displayName": "Appointment","name": "Appointment","type": "Appointment__c","viewstateSize": 0.19,"percentOfParent": 14.0,"percentOfTotalViewstate": 3.0,"leaf": false,"iconCls": "task","isGroupable": false,"identityCode": "51de7edfe97fcac51452a095ab7244ad","children": [{"displayName": "Start_Date__c","name": "Start_Date__c","type": "String","viewstateSize": 0.09,"percentOfParent": 47.0,"percentOfTotalViewstate": 1.0,"value": "2011-09-21 00:00:00","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "9f2e82e5ee05b1612b4b0e104b950d4e"},{"displayName": "Appointment_Type__c","name": "Appointment_Type__c","type": "String","viewstateSize": 0.09,"percentOfParent": 47.0,"percentOfTotalViewstate": 1.0,"value": "Call","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "c2a482f6a7d9d08c4e338be5698d53ee"}]},{"displayName": "liTimeSlots [49]","name": "liTimeSlots","type": "LIST<CTimeSlot>","viewstateSize": 0.78,"percentOfParent": 57.0,"percentOfTotalViewstate": 11.0,"leaf": false,"isGroupable": true,"identityCode": "4cf2c84fcc6526b648d786e5180b5958","children": [{"displayName": "0","name": "0","type": "CTimeSlot","viewstateSize": 0.42,"percentOfParent": 54.0,"percentOfTotalViewstate": 6.0,"leaf": false,"iconCls": "task","isGroupable": false,"identityCode": "ecccf8b9fdd988110f245cdf7067b688","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "00:00:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "fe9f7f6e17d0e09e87406e8c0621e0b7"}]},{"displayName": "1","name": "1","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "434a8ceb403bf52a35d322bfda862e12","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "00:30:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "cf22d004c7e93a056aa8bfeef3c3d43e"}]},{"displayName": "2","name": "2","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "f04f2b7ceb7384a827ab61fbb16ce1e1","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "01:00:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "b2ead991fa0073694cb96c81e70d9c66"}]},{"displayName": "3","name": "3","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "d96887ed3f3e01b2af3ad8f361ff127","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "01:30:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "c95d7a06e01707c1c67926dc265d4d68"}]},{"displayName": "4","name": "4","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "303f199faa0a1412b0e3e3e9954832a","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "02:00:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "b523c7859ebb7048a82df3447c0b12a6"}]},{"displayName": "5","name": "5","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "a3f05f83896e248caa050d001b222805","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "02:30:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "b9a6561c069c868c004105262f40836b"}]},{"displayName": "6","name": "6","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "69035039797c57bacf3d6d423a69f3d1","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "03:00:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "eab55fe7d97a051b82d78ee560dd52a3"}]},{"displayName": "7","name": "7","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "9c2f261a3b5349edd6e037f232c4c727","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "03:30:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "d3dfa08fe4f3e18facf33636d53d7831"}]},{"displayName": "8","name": "8","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "6a7cfb1d612512041ffd0f04717eddac","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "04:00:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "7a04e9d2ae70ef5c2bf881fd6bed0331"}]},{"displayName": "9","name": "9","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "3a37ba26fac5a158fe8ac81fb22b2f7d","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "04:30:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "79be268a2b6a200b1dff17b9a32d8c"}]},{"displayName": "10","name": "10","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "fde751be537d352a9ba9f5b94a8b8fa9","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "05:00:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "93f1ac3f145420e128765e941e722a41"}]},{"displayName": "11","name": "11","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "1840cc8e032fb7658f3aba9dbaee22a0","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "05:30:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "5bbbdc2060d533d98c368a34b62baaf0"}]},{"displayName": "12","name": "12","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "b78688f33675536eb5b442c04069e920","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "06:00:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "75153027f0121aa66fd4ed94ac93a892"}]},{"displayName": "13","name": "13","type": "CTimeSlot","viewstateSize": 0.42,"percentOfParent": 54.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "245ca246e80cf21f9b5e40b9341fffd7","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "06:30:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "af51dc4b91db493758245f0ac9fbef9e"}]},{"displayName": "14","name": "14","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "9984ce868e0f11e0aba0e88c600dc613","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "07:00:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "ea5a84d019379fa4f9f88c465e9b4cb8"}]},{"displayName": "15","name": "15","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "cfc0a2f1cab0fca5003b24947cea83a9","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "07:30:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "7c4b0ff21b98653fbb7b133aa74cf1d9"}]},{"displayName": "16","name": "16","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": "ea81f1b209799f8bb720d1d4ce92ea6c","children": [{"displayName": "tStart","name": "tStart","type": "Time","viewstateSize": 0.06,"percentOfParent": 14.0,"percentOfTotalViewstate": 0.9,"value": "08:00:00.000Z","leaf": true,"iconCls": "task","isGroupable": false,"identityCode": "506f3082e8fe83e8cb532e23e56606c3"}]},{"displayName": "17","name": "17","type": "CTimeSlot","viewstateSize": 0.44,"percentOfParent": 56.0,"percentOfTotalViewstate": 6.0,"leaf": false,"isGroupable": false,"identityCode": 

 Any idea why this is happening

  • September 22, 2011
  • Like
  • 0

This is probably a simple problem, but can't figure it out myself.  (amateur).

 

I have  a Site with pages, and a custom controller so that a (public) guest user can fill out a form and it then redirects them to a new page with output fields so they can see what they entered.  The problem I am having is that this custom object has "record types" and all submissions are going into the default record type, and I'm not sure how to change that.  I have a different Page for each (record type) submission form, and would like to be able to "set" the record type based on the page they are on.

 

Along the same lines, "during" adding a new record, I'd like to set a custom field "Status_c" to a value - that I can change later in my administrator ui, that the guest user would not be able to see or input or change.  I believe these are related tasks?

 

If anybody could help, or at least point in the right direction, I'd very much appreciate it!!!!

 

 

Here's part of a page and controller:

 

 

<apex:page controller="PIFBonusController" tabStyle="Account" sidebar="false" showHeader="false">
<meta name="robots" content="noindex">
<apex:form >
<apex:pageBlock title="Bonus PIF">
<p/>First Name:<br/><apex:inputField required="true" value="{!newpif.First_Name__c}"/>
<p/>Last Name:<br/><apex:inputField required="true" value="{!newpif.Last_Name__c}"/>

 

<apex:page controller="PIFBonusController" tabStyle="Account" sidebar="false" showHeader="false">

   <apex:form >

   <apex:pageBlock title="Bonus PIF">

       <p/>First Name:<br/><apex:inputField required="true" value="{!newpif.First_Name__c}"/>

       <p/>Last Name:<br/><apex:inputField required="true" value="{!newpif.Last_Name__c}"/>

 

 

   <apex:commandButton value="Submit PIF" action="{!Save}"/>

 

   </apex:pageBlock>

   </apex:form> 

</apex:page>

 

 

 

public with sharing class PIFBonusController {
 
  // the contact record you are adding values to
  public PIF__c newpif {
    get {
      if (newpif == null)
        newpif = new PIF__c();
      return newpif;
    }
    set;
  }
 
  public PIFBonusController() {
    // blank constructor
  }
 
  // save button is clicked
  public PageReference save() {
 
    try {
      insert newpif; // inserts the new record into the database
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new PIF.'));
      return null;
    }
 
    // if successfully inserted new pif, then displays the thank you page.
    return Page.PIF_Bonus_Thankyou;
  }
 
}

Hi there,

 

I have a new data entry VF page (and Apex Class).  When accessing the page in Internet Explorer, I had been receiving a Security Warning (The current Web page is trying to open a site in your Trusted sites list.  Do you want to allow this?).  I added https://c.<servername>.visualforce.com to my Trusted sites, which gets rid of the Security Warning, but now I get a Security Information alert (This page contains both secure and nonsecure items.  Do you want to display the nonsecure items?).

 

Is there another setting in IE that will suppress this Security Information alert, or do we need to modify the Apex Class/VF page?  Most of my users primarily use IE, so while I know Firefox handles this differently, I can't easily transition them all to Firefox and I don't want them to see this message every time they use the page in IE.

 

Any ideas?  Your replies are greatly appreciated!

 

Kristin

Message Edited by flewells on 11-09-2009 08:40 AM

 Hi,

 

I have created a trigger and tested on the sandbox and it works fine. I implemented it on the production last night and recieved the following errors this morning.

 

 

Apex script unhandled trigger exception by user/organization: 00520000000lct9/00D200000000Aq6 UpdateToAccSetupForm: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0220000005vt34AAA; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, This category is under construction. An email notofication will be sent when available.: [] Trigger.UpdateToAccSetupForm: line 21, column 2

 

 

 

 I have no idea why I am getting these errors, I recieved around 4 of them, can somebody please shine a light on this for me because I thought I had mastered the trigger.

 

Thanks in advance.

 

Here is my code:

 

 

trigger UpdateToAccSetupForm on Account (after update) { //Map to store SAP number - Map key is AccountID Map<String, String> SetupFormMap = new Map<String, String>(); //Loop for each update for (Account acc : System.Trigger.new){ //If SAP Number is not Null if (acc.IF_SAP__c != null){ //Put SAP ID into map. SetupFormMap.put(acc.ID, acc.IF_SAP__c); } else{ } } //Create a list to put all records in that need updating. List<AccountSetupForm__c> recordsforupdates = new list<AccountSetupForm__c>(); //For each key that is in the map and has an AccountSetupForm for (AccountSetupForm__c aacc :[Select Id, AccountName__c, SAP_Number__c from AccountSetupForm__c where AccountName__c IN : SetupFormMap.keySet()] ){ //If the Map contains the AccountSetupForm Foreign Key if (SetupFormMap.containsKey(aacc.AccountName__c)){ //Take SAP Number from map and add to AccountSetupForm aacc.SAP_Number__c = SetupFormMap.get(aacc.AccountName__c); //Add updated AccountSetupForm record to list. recordsforupdates.add(aacc); } } //Update all AccountSetupForm records update recordsforupdates; }

 

 

 

 

Installed a Twitter Search Widget app that does a search on twitter then displays the results directly inside the Salesforce.com page.  For IE 7.0 users, this is triggering the "Do You Want To Display the Nonsecure Items?" popup.

 

We do not want to disable the popup as it has its uses for other websites but do not want it to be triggered by this Twitter Search Widget?   Is there code we can add to the visualforce page or component that can prevent this?

 

-Thanks

  • September 24, 2009
  • Like
  • 0

Good day,

 

I need to invoke ajax call when user tick on checkbox, below is the code

 

 

<apex:inputCheckbox value="{!myvalue}" rendered="{!hasField}" onclick="{! 'javascript:if(document.getElementById('myField') == null){alert('Message call');} else { handleClicked();} '}}" />

When i put in this and save, it prompt me error on missing '}'  ....i try putting '\' in front of all single quote and it able to save , but it doesn't function when i tick on it 

 

 

'javascript:if(document.getElementById(\'myField\') == null){alert(\'Message call\');} else { handleClicked();} '

 

any clue how i can fix it ? Thanks in advance

 

 

 

 

 

 

  • August 17, 2009
  • Like
  • 0

Hey Hi, I am working on a Site and I need to use a standard Sav functionality, however I do not wish the page to move to the standard View page of the record.

 

 <apex:commandButton action="{!save}" value="Publish"  onComplete="window.parent.location.href='/apex/home';"/>              

 

I used onComplete but it is not redirecting to the page.

 

Please help

 

Warm Regards.

Siddhesh

 

Hi,

 

Can we display the result of a query as a single row?

 

E.g : select colorfield from obj where name ='abc'

 

where coclorfield is a formula field stores some color value based on a field in obj.

 

I did like this

 

<apex:repeat value="{!colors}" var="c"> <TR> <TD bgcolor="{!c.colorfield__c}" width="0" height="1">t</TD> </TR> </apex:repeat>

 but the results are comin in multi rows..

I want it in a single row

 

 

 

Hello,

 

I am trying to find a formula/function in Salesforce that is the equivalent to the EOMONTH function in excel.  The excel function is as follows:

 

Scenario 1 =EOMONTH(A1,0)  => this gives me the end date of the month that is in cell "A1"

 

Scenario 2 =EOMONTH(A1,1)  = > this give me the end date of the month after the month  that is in cell "A1"

 

So if A1 is Jan 15,2009 the function would give me Jan 31, 2009 in scenario 1 and Feb 28, 2009 in scenario 2.

 

Does anyone know how this can be accomplished in Salesforce?

 

Yes I know what you're thinking about....

 

Why do you want a picture in the sidebar??

 

 

 

The client just want it, i I've to make him happy  :smileymad:

 

Thanks in advance!!

Hi,

 

I have created a custom object "person" . now i want to craete records for that , but i am unable to find "new" for the same.

 

I have one solution  to see URL for new in SalesForce Explorer, but i wanted to know is there any other way to create the records for custom object ?

 

Thanks,

Deep. 

Hi All,

 

I have seen packages that have added a 'component' to the sidebar although it does not appear in the homepage components list or have the standard 'custom compnent styling' applied (title bar + html content below). How is this done? 

 

If there is documentation ot there I just need the links - can't seem to find any any where...

 

Thanks!

Rich.

 

 

Hi,

 

I have a problem with the following line in a beta package:-

 

List<CollaborationGroup> groups = [select id, name, description from collaborationGroup where name=:name];

giving the error:

 

System.QueryException: sObject type 'CollaborationGroup' is not supported

 

This works in the development org and other orgs where installed so am at a loss to explain, and therefore fix, this issue. If collaborationGroup wasn't available then I'd have thought the package wouldn't have installed??

 

Thanks for any help on this one.

 

Regards,

Rich.

Hi,

 

I'm trying to create a table of contents in a visualforce page rendered as a pdf. Has anybody done this? Is this even possible?

 

I'm looking for something that would end up looking like:-

 

1. Lorem Ipsum......................1

2. Lorem Ipsum......................2

3. Lorem Ipsum......................2

4. Lorem Ipsum......................3 

 

(heading).............................(page number)

 

I know I can do the first bit but I don't have any way of knowing which page the heading will fall on due to differing content lengths.

 

Thanks for any help.

Rich.

Hi,

 

I have a formula which does a case on the $recordType.Name on a parent object. I have another formula field that references this field on a child object. so far so good...

 

I now see that the value on the child is not the same as the parent (which is wrong).  Example below:-

 

Parent__c
field_parent__c = Case($RecordType.Name, 'abc', 1, 'def', 2, 0)

Child__c
field_child__c = parent__r.field_parent__c;

 If parent__c.Recordtype.Name = abc, field_parent__c=1 BUT field_child__c = 0;

 If parent__c.Recordtype.Name = def, field_parent__c=2 BUT field_child__c = 0;

 

Am I right in thinking that the $RecordType.Name field is run against the child record when calculating field_child__c and not just 'grabbing the value from field_parent__c'?

 

Is there a work around?

 

Thanks for any guidance/assistance.

 

Cheers,

Rich.

Hi,

 

We're trying to stop DMLExceptions from reaching the user in Visualforce pages which come from a controller. try{} catch{} blocks aren't stopping the message being shown. 

 

Example:

Account a = [select id from Account limit 1];
			try{
				insert a; //fails due to supplied id
			}catch(DMLException ex){}

 From this we get the message:

 

Account ID: cannot specify Id in an insert call - Standard SFDC Exception Message

 

Is there anyway to stop the message being shown? The idea is to build our own message which is more friendly to the user.

 

Looking at the docs shows examples where a custom message is being shown to the user within a try/catch block with no mention of duplicate messages.

 

Any ideas?

 

Thanks for any help.
Rich. 

 

Hi,

 

Anybody else having problems with images in summer '12?

Our sandbox has been updated and pdf generation now gives an error 'PDF generation failed. Check the page markup is valid.'

 

Test example below gives same issue. Any ideas?

 

<apex:page renderas="pdf">
  <h1>Congratulations</h1>
  This is your new Page
  <img src="http://www.developerforce.com/assets/images/discussions/banner.gif"></img>
</apex:page>

 A case has been logged -but just wondering if there is a quick fix.

 

Thanks!

Rich.

 

 

 

Dear all,

 

Can anybody explain to what the contact 'me' is added to in the code below?

Account a = [select id, name ,(select id, name from Contacts) from Account limit 1];
system.debug(a.contacts);
Contact me= new contact(lastname='smith', firstName='bob', accountId=a.Id);
a.contacts.add(me);
system.debug(a.contacts);

 Both system.debug statements will show the same records before and after adding me to the collection. Presuming that the collection 'Contacts' is somehow a read-only list; no error is found when running. So, has the add method call been ignored or just somehow adding to the 'wrong collection'...

 

This isn't a problem that needs fixing but may get you wondering like me ;)

 

Cheers,

Rich.

Hi Developers,

 

According the the documentation (and my memory) the following should work:-

 

PageReference ref = new PageReference('http://www.google.com');
Blob b = ref.GetContent();

 Why are we getting the following error upon execution of the getContent() method? 

 

System.VisualforceException: java.net.NoRouteToHostException: No route to host

 

This error (seems to )occur for all urls other than Salesforce! (http://www.salesforce.com, https://cs7.salesforce.com are ok).

 

Thanks for any help.

Rich.

 

Hi,

 

Today we have code that used to work which now doesn't.

 

For example test.startTest(); is now requiring the system namespace to be added to allow compilation and saving in UI and Eclipse. Code now becomes system.test.startTest();

This is the case for all test.* method calls.

 

Is this a temporary glich? A salesforce updgrade issue?? Any ideas? Using CS7...

 

Don't want to have to go and change all test methods to fix this if something else is going on.

 

Thanks,

Rich.

 

Hi All,

 

I have a requirement to upload rows from a CSV file with a delay in between each row to allow batch processing to take place. I am running one row at a time as the logic behind the application is complex and, to stop 'too many SQL statements' exceptions, a batch size of 1 is to be used.

 

My question is' How can I setup Talend to do this?

 

I have a tFileInputDelimited linked to a tSleep then linked to a tSalesforceOutput component. I have set the attribute "Rows to Commit" to be 1 and so I have 2 transactions in Salesforce; one for each record in my test data. I am trying use the tSleep to put a 20 second pause between each call to Salesforce. The result is that the 2 records are created in seperate transactions but updated with no delay. What other components/configuration do I need?

 

Any help would be appreciated.

 

Many thanks.

Rich.

Fellow developers,

 

I am experiencing a strange error - perhaps someone has come across this before and knows a solution?

 

I have a VF page that takes a number of parameters from the url and creates various custom objects. One of the last tasks it has to do is insert a Lead. If an Id parameter (containing a string not related to a SFDC id) is present in the querystring I get the error:-

 

EXCEPTION_THROWN|[199,17]|System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, invalid parameter value: []

Line 199 inserts the Lead.

 

so /mypage?firstname=bob&lastname=smith&id=abc123    = BROKEN

but /mypage?firstname=bob&lastname=smith                         = OK

 

I don't use the id. I don't have a standard controller. Its just a standard constructor (public myPage(){...} ) and action dosomething() in the VF page tag.

 

The reason is that it is there in an external flash application and the client swears it used to work with the id parameter and it will continue to be being passed in.

 

(I did try doing the following in the constructor "apexpages.CurrentPage.getParameters().remove('id');" with no success.)

 

Any ideas??

 

Thanks,

Rich.

 

 

 

 

Hi,

 

I know there have been some posts about this but none seem to suggest a working answer.

 

I'd like to be able to write a documents body directly to the browser and set the content type so that the contents are treated correctly by the browser.

 

So far I have for an image:-

apex: public string theBody {get; set;} public const(){ Document d = [select body from document limit 1]; theBody = d.EncodingUtil.base64encode(d.body); VF: ... <img src="data:image/jpeg:base64, {!theBody}"/>

...

 

 

Which works ok.

 

For a document e.g. application/msword this approach won't work.

 

I have tried writing out the body directly and body.toString() but none work (even with setting the contentType correctly). If the contentType is set then word just decides to open the data as text inside the document.

 

Has anybody managed this? Is it possible?

 

Thanks for any help.

 

R.

Hi,

 

Does anybody know if :-

1. It is possible to get the list of sites for a given organization and

2. Whether it is possible to get the details out of them.

 

I'd like to provide a button (or link) within SFDC to allow a user to go directly to a 'sites' siteURL.

 

I know there is the $Site global variable, this is only available within an actual 'sites' site but it has the data available to it.

 

Thanks for any help.

Rich. 

Hi,

 

We are trying to send out a VisualForce email template via the standard

 

Messaging.sendEmail(new Messaging.Email[] { email });

 

 

methods in apex. All the email attributes are set correctly but the Id of the object to 'merge' in the template isn't received by the custom controller. The custom controller expects the value to be passed from the template into a component where it is then accessed. It works correctly in the standard salesforce 'send email' function.

 

Has anybody got this to work? Is it even possible?

 

I have seen an idea posted about this but am unsure on the current status.

 

Any help appreciated.

 

Rich.

Hi,

 

I have a new sites site with a custom web address but when I go there I am shown the salesforce login screen. Why is this??

 

I have a cname setting on my dns which means that the domain is correctly redirecting. Therefore why is salesforce showing this screen? I know there is a custom web address setting in the sites admin. Is it something to do with this? I can go to the site successfully by the mysite.force.com url so the site is working ok with no errors.

 

Any help really appreciated as this is an urgent problem.

 

Thanks.

Rich.

Hi,

 

Anybody come across this error before?

 

"Tag Library supports namespace: http://salesforce.com/standard/components/apex, but no tag was defined for name: form"

 

This appears to have started when our development accounts have been updated to Summer '09. I can't now upload an already created managed package. I have got around this before by creating a new page with EXACTLY the same content as one that doesn't work; the new one works fine.

 

I get this when the existing page has an apex:form tag in it.

 

Thanks for any help.

Rich.

Hi,

 

I'm posting into a VisualForce Page a form which contains binary data. I am looking through the parameters returned and have seen these values:

RemoteFile:/home/sfdc/salesforce/sfdc/jsp/form/form1981773126.tmp RemoteFile.content-type:application/octet-stream RemoteFile.file:/home/sfdc/salesforce/sfdc/jsp/form/form1981773126.tmp RemoteFile.filename:7463.jpg

Does anybody know what the entries for RemoteFile and RemoteFile.file mean? (filename is the name of the file I posted.)

Has anybody tried to access these values before? I have tried to use the URL by copying and pasting into my browser but get the url no longer exists message.

 

Is there a way to directly access the request object then posted the data to the page?

 

Thanks for any help.

R.

Hi,

 

I have a problem to solve whereby I am receiving binarydata (a multipart form) from an HTTPPost request. This is from a third party component, but hosted within a visualforce page, to which I have little control.

 

My question is how to access the 'posted binary data' within apex? In Jsp it might be something like:-

DataInputStream in = new DataInputStream(request.getInputStream()); int formDataLength = request.getContentLength(); byte dataBytes[] = new byte[formDataLength]; int byteRead = 0; int totalBytesRead = 0;

etc...

 

 

Couldn't find any tutorials or other information about direct access to the request object and HTTPRequest seems to relate to creating my own request inside apex.

 

I have also tried to create a webservice but would need to create a SOAP request, which I can't do, so stuck there...

 

Any help appreciated.

 

Rich.

 

Hello fellow 'sites-ers'
 
I have an problem where I want to store the users session Id so I can pull back session variables within my apex code. (Goal is to create own authentication process.) Problem is this:
 
I hit the first page UserInfo.getSessionId() returns a sessionId. If I store this in my custom object and go off to my next page; using UserInfo.getSessionId() I get a different session Id.
 
(All UserInffo.getsessionId() method calls are in constructors - not sure if that is important or not...)
 
Why is this? Any ideas? Any soultions?
 
Thanks,
Rich.
 
Hello,

I have an application that relies heavily on webservices. I have imported the WSDL, created the app and am now looking to install on a staging account (via a package) from my development account. This is where I get stuck...

To package up the app I need to write testmethods to cover 75% of the code. As testmethods do not support 'webservice callouts' I cannot create enough coverage to package up the app and install on another account.

What can I do? Is there anyway around this? Anybody else come across this problem?

Any help gratefully received.

Cheers,
Rich.

ps. I am going to stub out all calls to the WS and return static data so I can get coverage but am looking for a proper solution so I can get this on the app Exchange.

Hi All,

 

I have seen packages that have added a 'component' to the sidebar although it does not appear in the homepage components list or have the standard 'custom compnent styling' applied (title bar + html content below). How is this done? 

 

If there is documentation ot there I just need the links - can't seem to find any any where...

 

Thanks!

Rich.

 

 

Hi,

 

I have a problem with the following line in a beta package:-

 

List<CollaborationGroup> groups = [select id, name, description from collaborationGroup where name=:name];

giving the error:

 

System.QueryException: sObject type 'CollaborationGroup' is not supported

 

This works in the development org and other orgs where installed so am at a loss to explain, and therefore fix, this issue. If collaborationGroup wasn't available then I'd have thought the package wouldn't have installed??

 

Thanks for any help on this one.

 

Regards,

Rich.

So I've got a trigger that changes the contact owner to the account owner anytime a new contact is created.  I am trying to test it but am getting only 80%. I can't figure out how to get it to tell that the change actually happened.  I tried adding a system assert message but can't figure out the verbage that it is looking for.  If you could take a look and help me out that would be great.  The two lines that aren't being covered in my trigger are:

mapAccountToOwner.put(a.Id, a.OwnerId);

and

c.OwnerID = mapAccountToOwner.get(c.AccountId);

and here's the test class I have so far:

@IsTest
private class AccountContactOwner
{
    private static TestMethod void testTrigger(){
        
        //Step 1 : Data Insertion
        Account a=new Account(Name='Test Account');
           insert a;
           Contact c = new Contact(FirstName='John',LastName='Doe');
        insert c;
        
        
        test.startTest();
        
        
        //Perform the dml action on which trigger gets fired , like insert, update ,delete , undelete, in your case you have to update account record that you created in above  
        //create test user
            Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
      User u1 = new User(Alias = 'standa', Email='saplingstandarduser@testorg.com',
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
      LocaleSidKey='en_US', ProfileId = p.Id,
      TimeZoneSidKey='America/Los_Angeles', UserName='saplingstandarduser@testorg.com');


      System.runAs(u1) {
      // The following code runs as user 'u'  
       // create test contact
        Contact c1 = new Contact(FirstName='Jane',LastName='Doe');
        insert c1;
        
        //assert your results using system.assert and system.asserEquals
        
        system.assert(c.OwnerID = a.OwnerID);
        
        
        
        test.stopTest();
    }
}
}

Hi,

 

I'm trying to set a "default" value to a lookup field called Carrier on Opportunity Product.

My Opportunity Product also have a text field called Default Carrier.

Every product have a default carrier, so i  want to set a default value for my lookup field.( the salesman can choose an other Carrier if they want).

 

I know that we can't use the workflow to populate the lookup field so i tried the trigger below:

 

trigger SetCarrier on Account (before insert) {
    for(OpportunityLineItem op : Trigger.new){
       op.Carrier__c = [Select Carrier__c.Id from Carrier__c Where Carrier__c.Name = :op.Default_carrier__c];
    }
}

 i got this error message:

 

Save error: Illegal assignment from LIST<Carrier__c> to Id

 

But in every case i'll not have a list =/.

 

 

Not sure if this is proper etiquette in the forums, but I have a continuation on a previous problem that I think should be a quick fix.  I replied to my past post, but it didnt get bumped to the top, so I'm making a new posting.  Any help in explaining would be great.

 

I am trying to do the same as here (http://boards.developerforce.com/t5/Apex-Code-Development/Stuck-writing-a-basic-trigger-to-update-ownership-of-a-record/m-p/493187), except to have any tasks (autocreated via workflow on a new case) also reassigned.  I am getting a "Save error: Invalid foreign key relationship: Task.WhatId" error on line 9.  Is this because of a similar problem that sfdcfox described in #2 above, whereas the value doesn't exist yet in a trigger?  If so, how do I get the value populated so that I can reference against it?  Or does the "WhatId" field work differently than a regular reference field?

 

Thanks so much!!  And also, for next time, should this be a new thread or is there a way to bump an existing thread to the top of the forum?  Do I need to uncheck the "Solution" that I had marked?

 

public with sharing class TaskClass {

	public static void updateTaskOwner (List<Task> tasks) {
	
    	  // map of opportunities
 			map<id,opportunity> opps = new map<id,opportunity>();
  			// obtain opportunity ids
  			for(Task t:tasks) {
    			opps.put(t.WhatId.opportunity__c,null);
  			}
  			// don't include null id
  			opps.remove(null);
  			// query all opps and place in map
  			opps.putAll([select id,impuser__c from opportunity where id in :opps.keyset()]);
  			// assign owner for each non-null value
  			for(Task t:tasks) {
    			if(opps.containskey(t.WhatId.opportunity__c) && opps.get(t.WhatId.opportunity__c).impuser__c != null) {
      				t.ownerid = opps.get(t.WhatId.opportunity__c).impuser__c;
    			}
  			}
	}
}

 

I have looked at most examples that fall into the Insufficient Privileges category and I have found none that is identical to my situation.

 

What I did is overide the standard contact page (View) with my custom visualforce page.  I can allow who see's this page and this is not my problem.

 

Is their a way that I can load the normal Contact View  to uses who do not have permission ?  Instead I always get the error.

 

Insufficient Privileges
You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.
  • September 10, 2012
  • Like
  • 0

I have a custom object with a trigger that was created before my time - I am just learning triggers.  I have pasted my code below.  My Users are getting the error when saving "Error:Apex trigger chassis_notification caused an unexpected exception, contact your administrator: chassis_notification: execution of BeforeUpdate caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing target address (target, to, cc, bcc): []: Trigger.chassis_notification: line 149, column 1"

 

 

trigger chassis_notification on Warranty__c (before update) 
{
  for(Warranty__c w : Trigger.new) 
  {
     // If this is a Chassis, send email to notify accounting
     if(w.Chassis_Unit__c == True && 
        w.Warranty_Status__c == 'Approved' && 
        w.ChassisNotificationSent__c != True &&
        w.Replace_with_vRecovery__c == False
        )
     {
        Account company = [select Id, Name from Account where Id = :w.Account_Name__c];
        Contact contact = [select Id, Name from Contact where Id = :w.Contact_Name__c];
        User caseOwner = [select Id, Email from User where Id = :w.OwnerId];
        Asset asset = [select Id, name from Asset where Id = :w.Asset_Tag__c];
        Case myCase = [select Id, CaseNumber from Case where Id = :w.Associated_Case__c];
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses;
        mail.setReplyTo('support@unitrends.com');
        mail.setSenderDisplayName('Unitrends Support');
        if(w.Is_GE__c == True)
        {
            toAddresses = new String[] {'dcrosby@unitrends.com', 
                                        'briant@unitrends.com',
                                        'luke@unitrends.com',
                                        'twallick@unitrends.com', 
                                        'dsapp@unitrends.com',
                                        'geisenhower@unitrends.com', 
                                         caseOwner.Email, 
                                        'dmccraw@unitrends.com',
                                        'jrast@unitrends.com',
                                        'accounting@unitrends.com'
                                        };
            mail.setSubject('GE Customer: A New Warranty Request has been Approved & Includes a Chassis or Unit Replacement');
            mail.setPlainTextBody
                        ('This customer warranty to be fulfilled by RAVE.' + '\n\n\n' +
                         'The following Warranty Request has been approved and may require' + '\n' +
                         'your attention as it includes a chassis or unit replacement:'+ '\n\n' +
                         'Company:\t\t\t' + company.Name + '\n' +
                         'Contact\t\t\t' + contact.Name + '\n' +                         
                         'Asset Tag:\t\t\t' + asset.Name + '\n' +
                         'Associated Case:\t\t' + myCase.CaseNumber + '\n' +
                         'Warranty Shipment Number:\t' + w.Name + '\n\n' +
                         'Click on the link to access the Warranty:\n' + 'https://na2.salesforce.com/' + w.Id
                        );
        }
        else if(w.Platinum_Support__c == True)
        {
            if(w.Manufacturer__c == 'Rave') {
                toAddresses = new String[] {'dcrosby@unitrends.com', 
                                            'briant@unitrends.com',
                                            'luke@unitrends.com',
                                            'unitrendsccd@chipcocomputer.com', 
                                            'twallick@unitrends.com', 
                                            'dsapp@unitrends.com',
                                            'geisenhower@unitrends.com', 
                                             caseOwner.Email, 
                                            'dmccraw@unitrends.com',
                                            'jrast@unitrends.com',
                                            'accounting@unitrends.com'
                                            };
            }
            else if(w.Manufacturer__c == 'CHIPCO') {
                toAddresses = new String[] {'dcrosby@unitrends.com', 
                                            'briant@unitrends.com',
                                            'luke@unitrends.com',
                                            'unitrendsccd@chipcocomputer.com', 
                                            'twallick@unitrends.com', 
                                            'dsapp@unitrends.com',
                                            'geisenhower@unitrends.com', 
                                             caseOwner.Email, 
                                            'dmccraw@unitrends.com',
                                            'jrast@unitrends.com',
                                            'accounting@unitrends.com'
                                            };
            }
            else if(w.Manufacturer__c == 'MBX') {
                toAddresses = new String[] {'dcrosby@unitrends.com', 
                                            'briant@unitrends.com',
                                            'luke@unitrends.com',
                                            'support@mbx.com', 
                                            'twallick@unitrends.com', 
                                            'dsapp@unitrends.com',
                                            'geisenhower@unitrends.com', 
                                             caseOwner.Email, 
                                            'dmccraw@unitrends.com',
                                            'jrast@unitrends.com',
                                            'accounting@unitrends.com'
                                            };
        
            }
            mail.setSubject('Platinum Customer: A New Warranty Request has been Approved & Includes a Chassis or Unit Replacement');
            mail.setPlainTextBody
                        ('This customer has platinum support and requires next day shipping!!!' + '\n\n\n' +
                         'The following Warranty Request has been approved and may require' + '\n' +
                         'your attention as it includes a chassis or unit replacement:'+ '\n\n' +
                         'Company:\t\t\t' + company.Name + '\n' +
                         'Contact\t\t\t' + contact.Name + '\n' +                         
                         'Asset Tag:\t\t\t' + asset.Name + '\n' +
                         'Associated Case:\t\t' + myCase.CaseNumber + '\n' +
                         'Warranty Shipment Number:\t' + w.Name + '\n\n' +
                         'Click on the link to access the Warranty:\n' + 'https://na2.salesforce.com/' + w.Id
                        );
        }
        else
        {
            if(w.Manufacturer__c == 'CHIPCO') {
                toAddresses = new String[] {'dcrosby@unitrends.com', 
                                            'briant@unitrends.com',
                                            'luke@unitrends.com',
                                            'unitrendsccd@chipcocomputer.com', 
                                            'twallick@unitrends.com', 
                                            'dsapp@unitrends.com',
                                            'geisenhower@unitrends.com', 
                                             caseOwner.Email, 
                                            'dmccraw@unitrends.com',
                                            'jrast@unitrends.com',
                                            'accounting@unitrends.com'
                                            };
            }
            else if(w.Manufacturer__c == 'MBX') {
                toAddresses = new String[] {'dcrosby@unitrends.com', 
                                            'briant@unitrends.com',
                                            'luke@unitrends.com',
                                            'support@mbx.com', 
                                            'twallick@unitrends.com', 
                                            'dsapp@unitrends.com',
                                            'geisenhower@unitrends.com', 
                                             caseOwner.Email, 
                                            'dmccraw@unitrends.com',
                                            'jrast@unitrends.com',
                                            'accounting@unitrends.com'
                                            };
        
            }
            mail.setSubject('A New Warranty Request has been Approved & Includes a Chassis or Unit Replacement');
            mail.setPlainTextBody
                        ('The following Warranty Request has been approved and may require' + '\n' +
                         'your attention as it includes a chassis or unit replacement:'+ '\n\n' +
                         'Company:\t\t\t' + company.Name + '\n' +
                         'Contact\t\t\t' + contact.Name + '\n' +                         
                         'Asset Tag:\t\t\t' + asset.Name + '\n' +
                         'Associated Case:\t\t' + myCase.CaseNumber + '\n' +
                         'Warranty Shipment Number:\t' + w.Name + '\n\n' +
                         'Click on the link to access the Warranty:\n' + 'https://na2.salesforce.com/' + w.Id
                        );
        }
        mail.setToAddresses(toAddresses);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        w.ChassisNotificationSent__c = True;
     }
  }
}

 

 

 

Hi guys.

 

I have batch calss name:Del_leads

and a Schedule Class bulkdelleads.

 

When i am writing test method for batch class it is not covering the execute method i am calling this execute from schedule class.Can any body help to figure out the problem.

 

Batch Class:-

=====================

global class Del_leads implements Database.Batchable<sobject>
{

public String query;
public date d=System.today();
public integer i=7;
Public Date z=d-i;
Public String s;
public integer j;
Public string k='Name'+','+'Company'+','+'phone'+','+'Email';

global Database.QueryLocator start(Database.BatchableContext BC){
system.debug(query);
return Database.getQueryLocator(query);

}

global void execute(Database.BatchableContext BC,List<Lead> Lds){
for( j=0;j<lds.size();j++){
if(j==0){
s +=k+'\n'+ lds[j].Name+','+lds[j].Company+','+lds[j].phone+','+lds[j].Email;
} else{
s +=+'\n'+ lds[j].Name+','+lds[j].Company+','+lds[j].phone+','+lds[j].Email;
}
}

Blob b=Blob.valueOf(s);
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('attachment.csv');
efa.setBody(b);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {'franktoanil@gmail.com'});
mail.setSenderDisplayName('Batch Processing');
mail.setSubject('Batch Process Completed');
mail.setPlainTextBody('Please find the attachment of deleted records');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
delete Lds;
}

global void finish(Database.BatchableContext BC){
System.debug(LoggingLevel.WARN,'Deleting Leads Finished');
}

=====================================================
/*-----------------Test Method-----------------Only 47 % test coverage*/

=====================================================
public static testMethod void Del_leads (){
List <Lead> lds = new List<Lead>();
for(integer i = 0; i<200; i++){
Lead l = new Lead(LastName='Anil',Company='ef');
lds.add(l);
}
insert lds;

test.startTest();
Del_leads dl = new Del_Leads();
dl.query='select id,Name,Company,Phone,Email from lead where createddate<=:z and date_opened__c=null ';
ID batchprocessid = Database.executeBatch(dl);
test.stoptest();
System.AssertEquals(
database.countquery('SELECT COUNT()'+' FROM Lead '),200);
}
}

============================

Schedule Class

============================

global class bulkdelleads Implements Schedulable{
public static String CRON_EXP = '0 0 0 3 9 ? 2022';
global void Execute(SchedulableContext SC){

Del_leads ld=new Del_leads();
ld.query='select id,Name,Company,Phone,Email from lead where createddate<=:z and date_opened__c=null ';
database.executebatch(ld);

}

==================================

/*----------Test Method------------------ 100% test Coverage-*/

==================================
static testmethod void bulkdelleads () {
Test.startTest();

Lead l = new Lead ();
l.LastName = 'Raghu ';
l.company='eg';
insert l;

// Schedule the test job

String jobId = System.schedule('bulkdelleads ',bulkdelleads.CRON_EXP,new bulkdelleads ());
// Get the information from the CronTrigger API object

CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered,
NextFireTime
FROM CronTrigger WHERE id = :jobId];

// Verify the expressions are the same

System.assertEquals(bulkdelleads.CRON_EXP,ct.CronExpression);

// Verify the job has not run

System.assertEquals(0, ct.TimesTriggered);

// Verify the next time the job will run

System.assertEquals('2022-09-03 00:00:00',
String.valueOf(ct.NextFireTime));

Test.stopTest(); 

}

}

 

Thanks

Anil.B

 

I've got a trigger on account object that populates a field that counts and sums up the number of related accounts to the account being updated/inserted/deleted.  Pretty straightforward.

 

This trigger works but I need to know whether it would be considered bulkified.  If it's not, any suggestions on what ought to be changed to bulkify it would be much appreciated.

 

Here it is:

 

trigger Account on Account (before insert, after insert, before update, after update) { 



// ---------------------------------------------------------------
 // Active Managed & Unmanaged Paying Customers processing
 // ------------------------------------------------------------------

    if ((Trigger.isInsert || Trigger.isUpdate || Trigger.isDelete) && Trigger.isAfter) {    

         set<Id> AccountIds = new set<Id>();
 
             if(trigger.isInsert || trigger.isUpdate){
                 for(Account p : trigger.new){
                     AccountIds.add(p.Referring_Partner__c);
                 }
              }
 
             if(trigger.isDelete){
                for(Account  p : trigger.old){
                    AccountIds.add(p.Referring_Partner__c);
                 }
              }
 
          map<Id,Double> AccountMap1 = new map <Id,Double>();
 
              for(AggregateResult q : [select Referring_Partner__c,sum(Referring_Partner_Count__c)
                  from Account 
                  where Active_Products__c != null AND Managed_by_Partner__c !=null AND Referring_Partner__c IN :AccountIds 
                  group by Referring_Partner__c]){
                  
                  AccountMap1.put((Id)q.get('Referring_Partner__c'),(Double)q.get('expr0'));
               }
  
           map<Id,Double> AccountMap2 = new map <Id,Double>();
 
               for(AggregateResult q : [select Referring_Partner__c,sum(Referring_Partner_Count__c)
                   from Account where Active_Products__c != null AND Managed_by_Partner__c = false AND Referring_Partner__c IN :AccountIds 
                   group by Referring_Partner__c]){
          
                   AccountMap2.put((Id)q.get('Referring_Partner__c'),(Double)q.get('expr0'));
               }
 
           List <Account> AccountsToUpdate = new List<Account>();
 
               for(Account a : [Select Id, Active_Paying_M__c from Account where Id IN :AccountIds]){
   
                   Double Sum1 = AccountMap1.get(a.Id);
                   a.Active_Paying_M__c = Sum1 ;
                   Double Sum2 = AccountMap2.get(a.Id);
                   a.Active_Paying_U__c = Sum2;    
    
                   AccountsToUpdate.add(a);
                }
 
           
           update AccountsToUpdate ;
  
    }

}

 

Hi,

 

We have an application we have built on our platform for managing our training business.  We use one object to produce a certificate for delegates after the course.  The certificate displays a signature and sometimes a logo dependant on the course.  We store these images in "Documents" which we make externally avaiblable and use the <apex:image> componenet to display.  This was working fine up until today.  Today for some reason none of the images will display in the pdfs.  I cannot see any changes to the code or the links we have been using - was there any changes made to the Salesforce platform last night which could effect this?  Has anyone else seen this issue?

 

The line of code we use is:

 

<apex:image height="1.3cm" url="https://eu1.salesforce.com/servlet/servlet.ImageServer?id=015D0000001Fs3o&oid=00D200000000Evl" />

 

https://eu1.salesforce.com/servlet/servlet.ImageServer?id=015D0000001Fs3o&oid=00D200000000Evl

 

I would approach support but I've be told in the past that with our service level they do not support VF.

 

Many Thanks.

Julie

 

  • July 26, 2012
  • Like
  • 0

Hi all 

 

i am getting the above strange error ("System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out") on one custom button click in salesforce.what i did is just fetch the value  and then pass paramters to url in http get as shown below:

 

   public PageReference Clone() 
  {
    Test_Flight_Request__c clFR = new Test_Flight_Request__c(); 
    Test_Flight_Request__c oldFR = [SELECT From__c, To__c,Outbound_del__c,Pax_del__c,Region_del__c,    
        Inbound_del__c,Outbound_Flexibility__c,Inbound_Flexibility__c,Opportunity__c,
        Budget__c,Flight_Request_Type__c,Publish_Fare__c,Searcher__c,Notes__c,Email_To__c,Email_Content__c,
        Subject__c,Status__c,Miles__c,Internal_Flight__c,Approx_Tax__c,Searcher_Notes__c,Field1__c
       FROM Test_Flight_Request__c WHERE Id = :fr.Id];

    clFR.From__c = oldFR.From__c;
    clFR.To__c = oldFR.To__c;
    clFR.Outbound_del__c = oldFR.Outbound_del__c;
    clFR.Pax_del__c = oldFR.Pax_del__c;
    clFR.Region_del__c = oldFR.Region_del__c;
    clFR.Inbound_del__c = oldFR.Inbound_del__c;
    clFR.Outbound_Flexibility__c = oldFR.Outbound_Flexibility__c;
    clFR.Inbound_Flexibility__c = oldFR.Inbound_Flexibility__c;
    clFR.Opportunity__c = oldFR.Opportunity__c;
    clFR.Budget__c = oldFR.Budget__c;
    clFR.Publish_Fare__c = oldFR.Publish_Fare__c;
    clFR.Flight_Request_Type__c = oldFR.Flight_Request_Type__c;
    clFR.Notes__c = oldFR.Notes__c;
    
    clFR.Searcher__c = oldFR.Searcher__c;
    
    clFR.Email_To__c = oldFR.Email_To__c;      
    clFR.Email_Content__c = oldFR.Email_Content__c;
    clFR.Subject__c = oldFR.Subject__c;
    
    clFR.Status__c = oldFR.Status__c;
    clFR.Miles__c = oldFR.Miles__c;
    clFR.Internal_Flight__c = oldFR.Internal_Flight__c;
    clFR.Approx_Tax__c = oldFR.Approx_Tax__c;
    clFR.Searcher_Notes__c = oldFR.Searcher_Notes__c;
    clFR.Field1__c = oldFR.Field1__c;
    insert clFR;
    System.debug('Old FRId:'+oldFR.Id);
       System.debug('New FRId:'+clFR.Id);
       
    Http http = new Http();
       HttpRequest httpreq = new HttpRequest();
       httpreq.setEndpoint('http://abcs.com');
   
      httpreq.setMethod('GET');
      httpreq.setTimeout(60000);
      String responseBody='';
      if (!Test.isRunningTest())
      { 
      HttpResponse  httpres =  http.send(httpreq);
    
      }
      else
      {
       responseBody = '200,4,48.5,-123.67';
      }
      
        PageReference pr = new PageReference('/'+  Id);
        pr.setRedirect(true);
        return pr;
  }
  
 
Pleas help me.
 

Hi,

 

       

          I am trying to import data through CSV from visualforce page. Its working well. But when CSV file contains Iine breaks in one Field then  i can't able to handle it. Getting error as System.ListException: List index out of bounds: 6 

 

 

 

Even Iam getting Problem with comma in any of the field

 

 

Please can one help me on this

 

 

Thanks

Hi All,

 

I have written a bulkified trigger and a test class for the same with 100% test coverage in sandbox. When I try to move it to Production, I get this error.

 

TestBC_AverageAmountNew.ideaBatchTest()Class291Failure Message: "System.LimitException: Too many SOQL queries: 101", Failure Stack Trace: "Trigger.BookingQuota: line 29, column 1"

 

The above class "TestBC_AverageAmountNew" has been written for a batch class. I am unable to move trigger from sandbox to production.

 

How can I rectify the problem? Please help.


 

Thanks,

Alok

I need some direction.  I currently have two lists - one called upgrades and the other called serial number / upgrades.  What I want my code to do is compare the values in the upgrades list with the values in the serial number / upgrades list.  If a value on the upgrades list is found on the serial number / upgrades list then don't do anything.   However, if a value on the upgrades list is NOT found on the serial number / upgrades list, then add that value to the serial number / upgrades list.  Both lists are variable in size, meaning that they could have 1 value or as many as 40 values.  How can I achieve this, with apex code preferably inside of a trigger? 

 

UPGRADES                                                          SN/UPGRADES

UG-001   <-----compare This     To all of these ---->   UG-004

                                                                                   UG-001 This value found, don't add it again.

UG-002 <-- This value            is not found here -->     ----       So add it to SN/UPGRADE list. 

UG-003 <-- This value            is not found here -->     ----        So add it to SN/UPGRADE list.

 

 

Any help would be appreciated.

 

 

accountname = [select id,name,[select id, firstname from contact] from account];

I used <apex:image url="{!$Resource.XYZ,'somePic.png'}" rendered="{!showImage}"/>

showImage is to show image if that retruns true.

 

and there are couple of places on the page.. I used <apex:image....

 

It was working earlier but started throwing exception i.e. "PDF generation failed. Check the page markup is valid."

 

After hits and trails, I found that

When I remove all apex:image, it renders PDF and does not throw any exception.

 

What could be the cause, and How can I show the required images, I also tried with simple HTML Img tag, it did not work.

 

Please suggest asap.

 

Thanks,

Saurav

 

 

Hi,

 

Anybody else having problems with images in summer '12?

Our sandbox has been updated and pdf generation now gives an error 'PDF generation failed. Check the page markup is valid.'

 

Test example below gives same issue. Any ideas?

 

<apex:page renderas="pdf">
  <h1>Congratulations</h1>
  This is your new Page
  <img src="http://www.developerforce.com/assets/images/discussions/banner.gif"></img>
</apex:page>

 A case has been logged -but just wondering if there is a quick fix.

 

Thanks!

Rich.

 

 

 

It won't even work for the canned quote2PDF example in the cookbook...

 

I get this error message on an otherwise blank failure page: "PDF generation failed. Check the page markup is valid. "

 

Anyone else seeing this?