• wadams2010
  • NEWBIE
  • 20 Points
  • Member since 2014
  • Sales Opps Manager
  • Cybera


  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 4
    Replies
I'm working on making a Visualforce Email Template and I want to show all related Files related to a record. When I try saving out my Visualforce Component it gives the following error: 'Read only property 'c:compProdInitFiles.ContDocLinks''

I tried removing the 'set' from my class to make it read only but it still throws the error. Any ideas on how to fix? I would think this would be simple but can't resolve. Code is below. Thanks in advance!

Visualforce Component:
 
<apex:component controller="prodInitFiles" access="global">
<apex:attribute name="relatedId" type="Id" description="Id of the account" assignTo="{!ContDocLinks}"/>
<table border = "2" cellspacing = "5">
    <tr>
        <td>DocumentId</td>
        <td>Title</td>                
    </tr>
    <apex:repeat value="{!ContDocLinks}" var="f">
    <tr>
        <td>{!f.ContentDocumentId}</td>
        <td>{!f.ContentDocument.title}</td>              
    </tr>
    </apex:repeat>        
</table>

Class:
public class prodInitFiles {

public Id relatedId {get;set;}
public List<ContentDocumentLink> getContDocLinks()
{
    List<ContentDocumentLink> contDocLink;
    contDocLink = [SELECT ContentDocument.title, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId =: relatedId];
    return contDocLink;
}}

 
I have been working on rendering a Lightning flow in a visualforce page. Main reason I want to accomplish this is to allow for a redirect to the new record along with a good looking flow for my current Classic users. I have gotten everything buttoned up except for redering the flow in two columns.

This link goes to the info I have gotten to this point. But I still can't find any documentation on how to render the flow with two columns. Is this possible? If so, is there documentation over it? 

Thanks in advance! Code below. 
<aura:application access="global" extends="ltng:outApp">
    <aura:dependency resource="lightning:flow"/>
</aura:application>
 
<apex:page >
    <html>
        
      <head>
         <apex:includeLightning />
      </head>
      <body class="slds-scope">
         <div id="flowContainer"/>
         <script>
          function getQueryVariable(variable)
            {
                   var query = window.location.search.substring(1);
                   var vars = query.split("&");
                   for (var i=0;i<vars.length;i++) {
                           var pair = vars[i].split("=");
                           if(pair[0] == variable){return pair[1];}
                   }
                   return(false);
            };
            var statusChange = function (event) {
               if(event.getParam("status") === "FINISHED") {
                  var outputVariables = event.getParam("outputVariables");
                  var outputVar;
                  for(outputVar in outputVariables) {
                     if(outputVariables[outputVar].name === "VarT_OpportunityId" && outputVariables[outputVar].value != null){
                     window.parent.location = '/' + outputVariables[outputVar].value;
                     }
               		}
                  } 
            };           
			$Lightning.use("c:lightningflow", function() {
               $Lightning.createComponent("lightning:flow", {"onstatuschange":statusChange},
                  "flowContainer",
                  function (component) {
                     var inputVariables = [
                        {
                           name : 'VarT_AccountId',
                           type : 'String',
                           value : getQueryVariable("VarT_AccountId")
                        }
                     ];
                     component.startFlow("Create_Opportunity_Flow", inputVariables);
                  }
               );
            });
         </script>
      </body>
   </html>
</apex:page>

 
I have a pretty simple Apex Controller + Action which I lifted from Salesforce Sidekick that takes a Flow, skins it up in Lightning Experience, and redirects to the newly created record. The issue I have is that when I use the flow launched from the button with a List Button with a Behavior = 'Display in existing window with sidebar' the final URL is not the true PageReference set in the action. The result is a page within a page showing the header and sidebar within the header and sidebar and the URL ends up looking like '/servlet/servlet.Integration?lid=...'

It works correctly and shows the page url as 'salesforce.com/RecordId' if I use the behavior = 'Display in existing window without sidebar or header' but I want to show the flow in an existing window and then have the PageReference just return to the new record. How can I accomplish this?

I have tried putting 'sidebar="false" showHeader="false"' in the header but it still doesn't work.

Thanks in advance!

Controller Code:
 
public with sharing class FlowRedirectController {

public Object FlowRedirectController() { 
    String unique_id    =       ApexPages.currentPage().getParameters().get('id');
    String obj          =       ApexPages.currentPage().getParameters().get('obj');

    if(unique_id == null){

        String url = '/home/home.jsp';
        return new PageReference(url);
    } 

    List<sObject> sobjList = database.query('SELECT Name, Unique_Flow_Identifier__c, Id  FROM '+String.escapeSingleQuotes(obj)+ ' WHERE Unique_Flow_Identifier__c = :unique_id ORDER BY CreatedDate DESC LIMIT 1');
    String returl = sobjList[0].id;


    if (returl == null) {
        // Return Home if no ID 
        String url = '/home/home.jsp'; 
    return new PageReference(url); }


    String url = '/' + returl;
        PageReference pRef = new PageReference(url);
        pRef.setRedirect(true);
    return pRef;}}

Visualforce page: 
 
<apex:page controller="FlowRedirectController" action="{!FlowRedirectController}" sidebar="false" showHeader="false">

 
Hey SFDC Community!

I am having an issue with a trigger where I am unable to get the Owner.Name as a string when the owner value is changed. When I use OwnerId the field that I am trying to populate will work but when I use Owner.Name it gets populated as blank. I know this should work but for some reason I am running into issues over it. See the trigger below and let me know what you think. I have highlighted and underlined the line where I have the Owner.Name. Thanks in advance!
 
trigger UpdateOFR on Feature_Request__c (after update, after insert) { 

    if (trigger.isUpdate){
        
        Set<Id> setFRchangeIds = new Set<Id>();
        
        for (Feature_Request__c fr : trigger.new){
            Feature_Request__c frOldFR = trigger.oldMap.get(fr.Id);
            
            boolean frIsChanged = (fr.Feature_Request_Status__c != frOldFR.Feature_Request_Status__c || fr.Target_Release__c != frOldFR.Target_Release__c || fr.OwnerId != frOldFR.OwnerId);
            if (frIsChanged){
                setFRchangeIds.add(fr.Id);
            }
        }
        
        if (setFRchangeIds.isEmpty() == false){
            List<Opportunity_Feature_Request__c> listOFR = [Select Id, Feature_Request__c From Opportunity_Feature_Request__c where Feature_Request__c IN:setFRchangeIds];
            for (Opportunity_Feature_Request__c ofr : listOFR){
                
                Feature_Request__c fr = trigger.newMap.get(ofr.Feature_Request__c);
                
                ofr.Feature_Request_Owner__c = fr.Owner.Name;
                ofr.Feature_Request_Status__c = fr.Feature_Request_Status__c;
                ofr.Feature_Request_Target_Release__c = fr.Target_Release__c;
            }
            if (listOFR.isEmpty() == false){
                update listOFR;
            }
        }
    }
}

 
Hey everybody,

I am getting the following error when I try and update multiple records (Feature Request custom object) through an enhanced list view. I know it has to do with I am querying multiple records but I don't know the best method to get this fixed. Does it have to do with maps? See apex code below. Thanks!
 
trigger UpdateOFR on Feature_Request__c (after update, after insert) { 

    Feature_Request__c fr = [Select Feature_Request_Status__c, Target_Release__c, Owner.Name from Feature_Request__c where ID IN :trigger.new];
    
    List<Opportunity_Feature_Request__c> lstToUpdate = new List<Opportunity_Feature_Request__c>();
	for(Opportunity_Feature_Request__c obj :[select Feature_Request_Status__c, Feature_Request_Target_Release__c, Feature_Request_Owner__c from Opportunity_Feature_Request__c where Feature_Request__c in : trigger.new]){
		
         
        obj.Feature_Request_Target_Release__c = fr.Target_Release__c;
        obj.Feature_Request_Owner__c = fr.Owner.Name;
        obj.Feature_Request_Status__c = fr.Feature_Request_Status__c;
		lstToUpdate.add(obj);
	}

	if(!lstToUpdate.isEmpty())
		update lstToUpdate;
}
I have used this wrapper class design pattern before successfully but this time it is not returning my list. I have ran the SOQL query on the workbench successfully and returned results. When I look at the logs I only see one SOQL query when there should be two (first on the opportunity object and then on the Feature_Request__c object). What issue am I running into here? Thanks in advance!

Apex: 
public with sharing class FeatReqOppJunctionExtension {

    public Opportunity theOpp {get; set;}
    public Feature_Request__c FeaReq {get; set;}
    public Opportunity_Feature_Request__c oppFR {get; set;}
    public List<ofrJO> featReqList {get; set;}
    
    public FeatReqOppJunctionExtension(ApexPages.StandardController controller) { 

        String oppId = ApexPages.currentPage().getParameters().get('oppId');
        theOpp = [select Id from Opportunity where Id =:oppId limit 1];
    }
    

    public List<ofrJO> getFeatReq() {
        if(featReqList == null) {
            featReqList = new List<ofrJO>();
            for(Feature_Request__c fr: [select Id, Name, Description_of_Request__c
                            from Feature_Request__c
                            ]) {
                
                featReqList.add(new ofrJO(fr));
                
        		}
            
        }
        return featReqList;
        
    }
        public PageReference insertRec() {
        
        for(ofrJO freq: getFeatReq()) {
            if(freq.selected == true) {   
                Opportunity_Feature_Request__c OppFeatReq = new Opportunity_Feature_Request__c();


                OppFeatReq.Opportunity__c = theOpp.Id;
                OppFeatReq.Feature_Request__c = freq.oppFR.Id;
                //OppFeatReq.add(nal);
            	insert OppFeatReq;
            }
            
        }
            
        return new PageReference('/apex/quoteEditAssociatedSite?quoteId='+ApexPages.currentPage().getParameters().get('quoteId'));
    }
    
        public class ofrJO {
        public Feature_Request__c FeaReq {get; set;}
        public Opportunity opp {get; set;}
        public Opportunity_Feature_Request__c oppFR {get; set;}
		public Boolean selected {get; set;}
   		

        
        public ofrJO(Feature_Request__c fr){
            FeaReq = fr;
            selected = false;
        }
            
       	public ofrJO(Opportunity o){
            opp = o;
        }        
        
        public ofrJO(Opportunity_Feature_Request__c ofr){
            oppFR = ofr;
    	}
         
    }
}

Visualforce Page:
<apex:page StandardController="Opportunity_Feature_Request__c" extensions="FeatReqOppJunctionExtension">
		<apex:includescript value="//code.jquery.com/jquery-1.11.1.min.js" / >
        <apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" />
        <apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" />
        <script>
            j$ = jQuery.noConflict();
            j$(document).ready( function () {
                var contactTable = j$('[id$="table"]').DataTable({
                    
                });
            });
    </script>            
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockButtons>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!featReqList}" var="ofr" id="table" style="tablesorter">
                <apex:column headerValue="Action">
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:commandButton value="{!ofr.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!ofr.FeaReq.Name}" />
                <apex:column value="{!ofr.FeaReq.Description_of_Request__c}" />        
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
I am currently getting an error 'Unknown property 'Feature_Request__cStandardController.ofrJO'' on a visualforce page I am trying to implement. I followed a design I had from a wrapper class that worked for me prior but in this case I only want to have the command button be on a specific line. I don't think this is the issue but I would really love some help from the community on resolving the issue. Thanks in advance!

Visualforce Page:
 
<apex:page StandardController="Feature_Request__c" extensions="FeatReqOppJunctionExtension">
		<apex:includescript value="//code.jquery.com/jquery-1.11.1.min.js" / >
        <apex:includescript value="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js" />
        <apex:stylesheet value="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css" />
        <script>
            j$ = jQuery.noConflict();
            j$(document).ready( function () {
                var contactTable = j$('[id$="table"]').DataTable({
                    
                });
            });
    </script>            
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockButtons>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!ofrJO}" var="ofr" id="table" style="tablesorter">
                <apex:column headerValue="Action">
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:commandButton value="{!ofr.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!ofr.fr.Name}" />
                <apex:column value="{!ofr.fr.Description_of_Request__c}" />        
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex: 
 
public with sharing class FeatReqOppJunctionExtension {

        //Our collection of the class/wrapper objects cContact 
    public Opportunity theOpp {get; set;}
    public Feature_Request__c FeaReq {get; set;}
    public Opportunity_Feature_Request__c oppFR {get; set;}
    public List<ofrJO> featReqList {get; set;}
    
    public FeatReqOppJunctionExtension(ApexPages.StandardController controller) { 

        String oppId = ApexPages.currentPage().getParameters().get('oppId');
        theOpp = [select Id from Opportunity where Id =:oppId limit 1];
    }
    
    public List<ofrJO> getFeatReq() {
        if(featReqList == null) {
            featReqList = new List<ofrJO>();
            for(Feature_Request__c fr: [select Id, Name, Description_of_Request__c
                            from Feature_Request__c
                            ]) {
                featReqList.add(new ofrJO(fr));
            }
        }
        return featReqList;
    }
    
        public PageReference insertRec() {
        
        for(ofrJO freq: getFeatReq()) {
            if(freq.selected == true) {   
                Opportunity_Feature_Request__c OppFeatReq = new Opportunity_Feature_Request__c();


                OppFeatReq.Opportunity__c = theOpp.Id;
                OppFeatReq.Feature_Request__c = freq.oppFR.Id;
                //OppFeatReq.add(nal);
            	insert OppFeatReq;
            }
            
        }
            
        return new PageReference('/apex/quoteEditAssociatedSite?quoteId='+ApexPages.currentPage().getParameters().get('quoteId'));
    }
    
        public class ofrJO {
        public Feature_Request__c FeaReq {get; set;}
        public Opportunity opp {get; set;}
        public Opportunity_Feature_Request__c oppFR {get; set;}
		public Boolean selected {get; set;}
   		
        public ofrJO(Feature_Request__c fr){
            FeaReq = fr;
        }
            
       	public ofrJO(Opportunity o){
            opp = o;
        }        
        
        public ofrJO(Opportunity_Feature_Request__c ofr){
            oppFR = ofr;
    	}
         
    }   
}

 
I am trying to write an apex test for a class where it inserts records based off of a selection being made in a visualforce page. Right now I am getting 60% covered but I would like to get this to 100% if possible. I feel like I am not correctly testing the actual insert of the records (Associated Location) from my class. Also, I believe this is a wrapper class. What can I do to get the amount close to 100%? Thanks in advance!

Apex Class:
public with sharing class quoteAssociatedSiteExtension {

	//Our collection of the class/wrapper objects cContact 
	public Quote theQuote {get; set;}
    public List<assLoc> assLocList {get; set;}
    
    public quoteAssociatedSiteExtension(ApexPages.StandardController controller) { 

        String quoteId = ApexPages.currentPage().getParameters().get('quoteId');
		theQuote = [select Id, AccountId from Quote where Id =:quoteId limit 1];
    }

	//This method uses a simple SOQL query to return a List of Contacts
	public List<assLoc> getAssLoc() {
		if(assLocList == null) {
			assLocList = new List<assLoc>();
			for(Site__c s: [select Id, Name, Account__r.Id,	 City__c,Location_Id__c, Location_ID_Link__c, Identifier__c, Country__c,  Site_ID__c, Site_Main_Phone__c, State__c, Street__c, Zip__c
                            from Site__c 
                            where Account__r.Id=:theQuote.AccountId
                            AND Id NOT IN(Select Site__c from Associated_Location__c Where Quote__c=:theQuote.Id)
                            ]) {
				// As each contact is processed we create a new cContact object and add it to the contactList
				assLocList.add(new assLoc(s));
			}
		}
		return assLocList;
	}
    
	public PageReference addInfo() {
		List<Associated_Location__c> nmal = new List<Associated_Location__c>();
        
		for(assLoc aLoc: getAssLoc()) {
			if(aLoc.selected == true) {   
                Associated_Location__c nal = new Associated_Location__c();


                nal.Site__c = aLoc.st.Id;
                nal.Quote__c = theQuote.Id;
                nal.Remarks_Special_Instructions__c = aLoc.remark;
                System.debug(nal.Remarks_Special_Instructions__c);
                
                nmal.add(nal);
			}
		}
        
        if(nmal.size()>0)
            insert nmal; 
        
        return new PageReference('/apex/quoteEditAssociatedSite?quoteId='+ApexPages.currentPage().getParameters().get('quoteId'));
	}
    
    public PageReference editLater() {
		List<Associated_Location__c> nmal = new List<Associated_Location__c>();
        
		for(assLoc aLoc: getAssLoc()) {
			if(aLoc.selected == true) {   
                Associated_Location__c nal = new Associated_Location__c();


                nal.Site__c = aLoc.st.Id;
                nal.Quote__c = theQuote.Id;
                nal.Remarks_Special_Instructions__c = aLoc.remark;
                System.debug(nal.Remarks_Special_Instructions__c);
                
                nmal.add(nal);
			}
		}
        
        if(nmal.size()>0)
            insert nmal; 
        
        return new PageReference('/'+ApexPages.currentPage().getParameters().get('quoteId'));
	}
    
        public PageReference quickSave() {
		List<Associated_Location__c> nmal = new List<Associated_Location__c>();
        
		for(assLoc aLoc: getAssLoc()) {
			if(aLoc.selected == true) {   
                Associated_Location__c nal = new Associated_Location__c();


                nal.Site__c = aLoc.st.Id;
                nal.Quote__c = theQuote.Id;
                nal.Remarks_Special_Instructions__c = aLoc.remark;
                System.debug(nal.Remarks_Special_Instructions__c);
                
                nmal.add(nal);
			}
		}
        
        if(nmal.size()>0)
            insert nmal; 
        
        PageReference pageRef = new pageReference('/apex/AssociatedLocationPage?quoteId='+ApexPages.currentPage().getParameters().get('quoteId'));
        pageRef.setRedirect(true);
        return pageRef;
	}


	// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
	public class assLoc {
		public Associated_Location__c ac {get; set;}
        public Site__c st {get; set;}
        public Quote qt {get; set;}
		public Boolean selected {get; set;}
        public String remark {get; set;}

		//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
		public assLoc(Associated_Location__c a) {
            ac = a;
		}        
        
        public assLoc(Site__c s) {
			st = s;
			selected = false;
		}
        
		public assLoc(Quote q) {
			qt = q;
			selected = false;
		}
         
	}
}

Test Class:
@isTest(SeeAllData=true)
private class AssociatedSiteTestClass {
static testMethod void myUnitTest() {
 
        Profile pf = [Select Id from Profile where Name = 'System Administrator'];
 
        User u = new User();
        u.FirstName = 'Test';
        u.LastName = 'User';
        u.Email = 'testuser@test123456789010.com';
        u.CompanyName = 'test.com';
        u.Title = 'Test User';
        u.Username = 'testuser@test123456789010.com';
        u.Alias = 'testuser';
        u.CommunityNickname = 'Test User';
        u.TimeZoneSidKey = 'America/Mexico_City';
        u.LocaleSidKey = 'en_US';
        u.EmailEncodingKey = 'ISO-8859-1';
        u.ProfileId = pf.Id;
        u.LanguageLocaleKey = 'en_US';
        insert u;
 
        system.runAs(u){
 
            Account a = new Account();
            a.Name = 'Test Account';
            a.Type = 'Prospect';
            insert a;
            
            Contact c = new Contact();
            c.FirstName = 'Test';
            c.LastName = 'Contact';
            c.AccountId = a.Id;
            insert c;
            
            Opportunity o = new Opportunity();
            o.Name = 'Parent Test Opportunity';
            o.AccountId = a.Id;
            o.StageName = 'General Interest';
            o.CloseDate = system.today();
            o.Type = 'Initial';
            o.Units__c = 5;
            o.Total_MRR__c = 500;
            o.Total_NRR__c = 500;
            insert o;
            
            OpportunityContactRole ocr = new OpportunityContactRole ();
            ocr.ContactId = c.Id;
            ocr.OpportunityId = o.Id;
            ocr.IsPrimary = True;
            insert ocr;
                        
            Quote q = new Quote();
            q.Name = 'Test Quote';
            q.OpportunityId = o.Id;
			q.ContactId = c.Id;
            q.New_or_Existing_Site__c = 'New Site';
            q.Request_Type__c = 'Standard';
            insert q;
            
            Site__c s1 = new Site__c();
            s1.Account__c = a.Id;
            s1.Site_ID__c = 101;
			s1.Location_ID__c = 1001;
			insert s1;

			Site__c s2 = new Site__c();
            s2.Account__c = a.Id;
            s2.Site_ID__c = 102;
			s2.Location_ID__c = 1002;
			insert s2;
            
            
            
            PageReference myVfPage = Page.AssociatedLocationPage;
    			System.Test.setCurrentPageReference(myVfPage); // use setCurrentPageReference, 
   
                ApexPages.currentPage().getParameters().put('quoteId',q.Id);
                String id = ApexPages.currentPage().getParameters().get('quoteId');
                Test.setCurrentPageReference(myVFPage);
            	system.assertEquals(true,id==q.Id);
            
            	quoteAssociatedSiteExtension qASE = new quoteAssociatedSiteExtension(new ApexPages.StandardController(q));
            		qASE.addInfo();
            		qASE.editLater();
            		qASE.quickSave();
            
            Associated_Location__c nal = new Associated_Location__c();
                nal.Quote__c = q.Id;
                nal.Site__c = s1.Id;
            	qASE.quickSave();
            Associated_location__c alq = [select Id from Associated_Location__c where Site__c =:s1.Id limit 1];
            system.assertEquals(s1.Id,alq.Id);
                
            }
	}
}

 
I am having an issue passing an input field from a Visualforce page to new inserted records. The field I am trying to pass is 'Remarks_Special_Instructions__c' but when I put info in there it is not saving into the newly created records. I have tried a few different ways but no luck on any front. What are my issues? Thanks in advance!

Apex: 
public with sharing class quoteAssociatedSiteExtension {

	//Our collection of the class/wrapper objects cContact 
	public Quote theQuote {get; set;}
    public List<assLoc> assLocList {get; set;}
    
    public quoteAssociatedSiteExtension(ApexPages.StandardController controller) { 

        String quoteId = ApexPages.currentPage().getParameters().get('quoteId');
		theQuote = [select Id, AccountId from Quote where Id =:quoteId limit 1];
    }

	//This method uses a simple SOQL query to return a List of Contacts
	public List<assLoc> getAssLoc() {
		if(assLocList == null) {
			assLocList = new List<assLoc>();
			for(Site__c s: [select Id, Name, Account__r.Id, City__c, Country__c,Order_Master_ID__c, Order_Master_Link__c, Site_ID__c, Site_Main_Phone__c, State__c, Street__c, Zip__c
                            from Site__c 
                            where Account__r.Id=:theQuote.AccountId
                           ]) {
				// As each contact is processed we create a new cContact object and add it to the contactList
				assLocList.add(new assLoc(s));
			}
		}
		return assLocList;
	}
    
	public PageReference processSelected() {

                //We create a new list of Contacts that we be populated only with Contacts if they are selected
		List<Site__c> selectedAssociatedLocations = new List<Site__c>();

		//We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
		for(assLoc aLoc: getAssLoc()) {
			if(aLoc.selected == true) {
				selectedAssociatedLocations.add(aLoc.st);
			}
		}

		// Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
		List<Associated_Location__c> nmal = new List<Associated_Location__c>();
        for(Site__c al: selectedAssociatedLocations) {          
            Associated_Location__c nal = new Associated_Location__c();
            nal.Site__c = al.Id;
            nal.Quote__c = theQuote.Id;
            nmal.add(nal);
		}
		insert nmal; 
        return new PageReference('/'+ApexPages.currentPage().getParameters().get('quoteId'));
	}


	// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
	public class assLoc {
		public Associated_Location__c ac {get; set;}
        public Site__c st {get; set;}
        public Quote qt {get; set;}
		public Boolean selected {get; set;}

		//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
		public assLoc(Associated_Location__c a) {
			ac = a;
			selected = false;
		}        
        
        public assLoc(Site__c s) {
			st = s;
			selected = false;
		}
        
		public assLoc(Quote q) {
			qt = q;
			selected = false;
		}        
	}
}

Visualforce:
<apex:page standardController="Associated_Location__c" extensions="quoteAssociatedSiteExtension" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!AssLoc}" var="a" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!a.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!a.st.Street__c}" />
                <apex:column value="{!a.st.City__c}" />
                <apex:column value="{!a.st.State__c}" />
                <apex:column value="{!a.st.Zip__c}" />
                <apex:column headerValue="{!$ObjectType.Associated_Location__c.Fields.Remarks_Special_Instructions__c.Label}">
                    <apex:inputField value="{!a.ac.Remarks_Special_Instructions__c}" required="false"/>
                </apex:column>
               	<apex:column value="{!a.st.Site_Main_Phone__c}" />
                
                <apex:column value="{!a.st.Order_Master_Link__c}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Hey everybody!

I am trying to create records (Associated Locations) based off of a user selected list of a custom object (Site). I have tried following a number of guides on how to do this but can't really follow. Right now when I try and save values with a debug catch it shows the number of records I have selected but the values are null. How can I add values and insert the records? Thansk in advance!

Apex: 
public with sharing class quoteAssociatedSiteExtension {

	//Our collection of the class/wrapper objects cContact 
	public Quote theQuote {get; set;}
    public List<assLoc> assLocList {get; set;}
    
    
    public quoteAssociatedSiteExtension(ApexPages.StandardController controller) { 

        String quoteId = ApexPages.currentPage().getParameters().get('quoteId');
		theQuote = [select Id, AccountId from Quote where Id =:quoteId limit 1];
    }

	//This method uses a simple SOQL query to return a List of Contacts
	public List<assLoc> getAssLoc() {
		if(assLocList == null) {
			assLocList = new List<assLoc>();
			for(Site__c s: [select Id, Name, Account__r.Id from Site__c where Account__r.Id=:theQuote.AccountId limit 10]) {
				// As each contact is processed we create a new cContact object and add it to the contactList
				assLocList.add(new assLoc(s));
			}
		}
		return assLocList;
	}


	public PageReference processSelected() {

                //We create a new list of Contacts that we be populated only with Contacts if they are selected
		List<Associated_Location__c> selectedAssociatedLocations = new List<Associated_Location__c>();

		//We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
		for(assLoc aLoc: getAssLoc()) {
			if(aLoc.selected == true) {
				selectedAssociatedLocations.add(aLoc.ac);
			}
		}

		// Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
		System.debug('These are the selected Contacts...');
		for(Associated_Location__c ac: selectedAssociatedLocations) {
			system.debug(ac);
		}
		assLocList=null; // we need this line if we performed a write operation  because getContacts gets a fresh list now
		return null;
	}


	// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
	public class assLoc {
		public Associated_Location__c ac {get; set;}
        public Site__c st {get; set;}
        public Quote qt {get; set;}
		public Boolean selected {get; set;}

		//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
		public assLoc(Associated_Location__c a) {
			ac = a;
			selected = false;
		}
        
        public assLoc(Site__c s) {
			st = s;
			selected = false;
		}
        
		public assLoc(Quote q) {
			qt = q;
			selected = false;
		}        
	}
}

VF Page: 
 
<apex:page standardController="Associated_Location__c" extensions="quoteAssociatedSiteExtension">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!AssLoc}" var="a" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!a.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!a.st.Name}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
Hey everybody!

I'm trying to write my first wrapper class whic will allow me to create records related to both a custom object (Site__c) and the Quote object. What I am having an issue with is passing the QuoteId to the SOQL query on line 11. I have tried it with a hardcoded QuoteId and it works correctly. Right now when I try and save it gives me the error 'Invalid bind expression type of Object for column of type Id'. 

What is the issue here? Is it because of the standard controller is my other custom object (Associated_Location__c)? Thanks in advance! 

Apex:
public with sharing class quoteAssociatedSiteExtension {

	//Our collection of the class/wrapper objects cContact 
	public Quote theQuote {get; set;}
    public List<assLoc> assLocList {get; set;}
    
    
    public quoteAssociatedSiteExtension(ApexPages.StandardController controller) { 

        controller.addFields(new List<String>{'Quote__c'});
		theQuote = [select Id, AccountId from Quote where Id =:controller.getRecord().get('Quote__c') limit 1];
    }

	//This method uses a simple SOQL query to return a List of Contacts
	public List<assLoc> getAssLoc() {
		if(assLocList == null) {
			assLocList = new List<assLoc>();
			for(Site__c s: [select Id, Name, Account__r.Id from Site__c where Account__r.Id=:theQuote.AccountId limit 10]) {
				// As each contact is processed we create a new cContact object and add it to the contactList
				assLocList.add(new assLoc(s));
			}
		}
		return assLocList;
	}


	public PageReference processSelected() {

                //We create a new list of Contacts that we be populated only with Contacts if they are selected
		List<Associated_Location__c> selectedAssociatedLocations = new List<Associated_Location__c>();

		//We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
		for(assLoc aLoc: getAssLoc()) {
			if(aLoc.selected == true) {
				selectedAssociatedLocations.add(aLoc.ac);
			}
		}

		// Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
		System.debug('These are the selected Contacts...');
		for(Associated_Location__c ac: selectedAssociatedLocations) {
			system.debug(ac);
		}
		assLocList=null; // we need this line if we performed a write operation  because getContacts gets a fresh list now
		return null;
	}


	// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
	public class assLoc {
		public Associated_Location__c ac {get; set;}
        public Site__c st {get; set;}
        public Quote qt {get; set;}
		public Boolean selected {get; set;}

		//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
		public assLoc(Associated_Location__c a) {
			ac = a;
			selected = false;
		}
        
        public assLoc(Site__c s) {
			st = s;
			selected = false;
		}
        
		public assLoc(Quote q) {
			qt = q;
			selected = false;
		}        
	}
}

Visualforce: 
 
<apex:page standardController="Associated_Location__c" extensions="quoteAssociatedSiteExtension">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!AssLoc}" var="a" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!a.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!a.st.Name}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
I'm having an issue with my Apex Test Class from a trigger. I've used the trigger multiple times in my sandbox but when I try to test it out it fails. The reason for the failure is 'System.QueryException: List has no rows for assignment to SObject' which I have tried to look up but there are so many answers and they don't apply to my certain case. Tried it multiple ways and I am wondering if anybody here has a good answer.

I have two objects, Implementation (custom) and Opportunity. The trigger fires when an Opportunity is set to 'Closed Won'. Below is the trigger:

trigger CreateImplementation on Opportunity (after update) {

    List<Id> opps = new List<Id>();

    for ( Opportunity opp : Trigger.new ){


        if((opp.StageName == 'Closed Won' ) &&
        (Trigger.oldMap.get(opp.Id).StageName!='Closed Won') ) {

        opps.add(opp.Id);

    }

    Map<Id,Opportunity> oppsMap = new Map<Id,Opportunity>( [SELECT Id, Account.Id, CloseDate, OwnerId, Account.Name from Opportunity where Id IN :opps] );

    List <Implementation__c> impToInsert = new List <Implementation__c> ();

    for( Opportunity oppo : oppsMap.values()){
        Implementation__c imp = new Implementation__c ();

        imp.Account__c = oppo.AccountId;
        imp.Name = oppo.Account.Name +' Implementation';
        imp.Phase__c = 'Phase 0';
        imp.Contract_Date__c = oppo.CloseDate;

        impToInsert.add(imp);
    }

try {
        insert impToInsert;
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
    }
}

And here is the test: 

@istest private class CreateImplementation {
testMethod private static void CreateImplementation () {

 Account acco = new Account(Name = 'Acme Test Account', Type = 'Prospect');
    insert acco;

Opportunity opp = new Opportunity(Name = 'Acme Test Opp', CloseDate=System.Today(), AccountId=acco.id, Type= 'New Business', Business_Value__c='NA',Closed_Reasons__c='NA', StageName='Closed Won',Amount=1000);
    insert opp;

 Implementation__c imp = [ SELECT Account__c, Name, Phase__c FROM Implementation__c WHERE Account__c = :acco.id LIMIT 1 ];
 System.assertEquals(imp.Phase__c,'Phase 0');}}

Thanks in advance!
Hello all!

I got pretty far with this discussion yesterday on the Salesforce Success boards but I think the question needs to be asked to the developers board now.

In my example we have an Account with Contacts where specific Contacts have a different owner than the Account Owner. What I need to do is to have all the Contacts that are not owned by the Contact's Account Owner restricted from the Account Owner's view.

In a sandbox I have rolled all the OWD back to Private for Account, Contract and Asset, Contact, Opportunity, and Case to Private. Without adding any Record Sharing Rules, the Account Owner is still able to see the Account's Contact that the person does not own. The reason given when I drill down using the Sharing button is that the 'Reason for Access' is 'Account Sharing'. However, if I got to the Account level as an Admin, click Sharing, click Edit next to the Account Owner and set the Contact Access as Private, all is well.

I have seen documentation about using Apex Managed Sharing to automatically update the Sharing set-up. I am wondering if there is any way to not have to use Apex to complete this requirement. Would this be possible?

Thanks in advance!
Hey everybody!

I'm trying to write my first wrapper class whic will allow me to create records related to both a custom object (Site__c) and the Quote object. What I am having an issue with is passing the QuoteId to the SOQL query on line 11. I have tried it with a hardcoded QuoteId and it works correctly. Right now when I try and save it gives me the error 'Invalid bind expression type of Object for column of type Id'. 

What is the issue here? Is it because of the standard controller is my other custom object (Associated_Location__c)? Thanks in advance! 

Apex:
public with sharing class quoteAssociatedSiteExtension {

	//Our collection of the class/wrapper objects cContact 
	public Quote theQuote {get; set;}
    public List<assLoc> assLocList {get; set;}
    
    
    public quoteAssociatedSiteExtension(ApexPages.StandardController controller) { 

        controller.addFields(new List<String>{'Quote__c'});
		theQuote = [select Id, AccountId from Quote where Id =:controller.getRecord().get('Quote__c') limit 1];
    }

	//This method uses a simple SOQL query to return a List of Contacts
	public List<assLoc> getAssLoc() {
		if(assLocList == null) {
			assLocList = new List<assLoc>();
			for(Site__c s: [select Id, Name, Account__r.Id from Site__c where Account__r.Id=:theQuote.AccountId limit 10]) {
				// As each contact is processed we create a new cContact object and add it to the contactList
				assLocList.add(new assLoc(s));
			}
		}
		return assLocList;
	}


	public PageReference processSelected() {

                //We create a new list of Contacts that we be populated only with Contacts if they are selected
		List<Associated_Location__c> selectedAssociatedLocations = new List<Associated_Location__c>();

		//We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
		for(assLoc aLoc: getAssLoc()) {
			if(aLoc.selected == true) {
				selectedAssociatedLocations.add(aLoc.ac);
			}
		}

		// Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
		System.debug('These are the selected Contacts...');
		for(Associated_Location__c ac: selectedAssociatedLocations) {
			system.debug(ac);
		}
		assLocList=null; // we need this line if we performed a write operation  because getContacts gets a fresh list now
		return null;
	}


	// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
	public class assLoc {
		public Associated_Location__c ac {get; set;}
        public Site__c st {get; set;}
        public Quote qt {get; set;}
		public Boolean selected {get; set;}

		//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
		public assLoc(Associated_Location__c a) {
			ac = a;
			selected = false;
		}
        
        public assLoc(Site__c s) {
			st = s;
			selected = false;
		}
        
		public assLoc(Quote q) {
			qt = q;
			selected = false;
		}        
	}
}

Visualforce: 
 
<apex:page standardController="Associated_Location__c" extensions="quoteAssociatedSiteExtension">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!AssLoc}" var="a" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!a.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!a.st.Name}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 
I am having an issue passing an input field from a Visualforce page to new inserted records. The field I am trying to pass is 'Remarks_Special_Instructions__c' but when I put info in there it is not saving into the newly created records. I have tried a few different ways but no luck on any front. What are my issues? Thanks in advance!

Apex: 
public with sharing class quoteAssociatedSiteExtension {

	//Our collection of the class/wrapper objects cContact 
	public Quote theQuote {get; set;}
    public List<assLoc> assLocList {get; set;}
    
    public quoteAssociatedSiteExtension(ApexPages.StandardController controller) { 

        String quoteId = ApexPages.currentPage().getParameters().get('quoteId');
		theQuote = [select Id, AccountId from Quote where Id =:quoteId limit 1];
    }

	//This method uses a simple SOQL query to return a List of Contacts
	public List<assLoc> getAssLoc() {
		if(assLocList == null) {
			assLocList = new List<assLoc>();
			for(Site__c s: [select Id, Name, Account__r.Id, City__c, Country__c,Order_Master_ID__c, Order_Master_Link__c, Site_ID__c, Site_Main_Phone__c, State__c, Street__c, Zip__c
                            from Site__c 
                            where Account__r.Id=:theQuote.AccountId
                           ]) {
				// As each contact is processed we create a new cContact object and add it to the contactList
				assLocList.add(new assLoc(s));
			}
		}
		return assLocList;
	}
    
	public PageReference processSelected() {

                //We create a new list of Contacts that we be populated only with Contacts if they are selected
		List<Site__c> selectedAssociatedLocations = new List<Site__c>();

		//We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
		for(assLoc aLoc: getAssLoc()) {
			if(aLoc.selected == true) {
				selectedAssociatedLocations.add(aLoc.st);
			}
		}

		// Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
		List<Associated_Location__c> nmal = new List<Associated_Location__c>();
        for(Site__c al: selectedAssociatedLocations) {          
            Associated_Location__c nal = new Associated_Location__c();
            nal.Site__c = al.Id;
            nal.Quote__c = theQuote.Id;
            nmal.add(nal);
		}
		insert nmal; 
        return new PageReference('/'+ApexPages.currentPage().getParameters().get('quoteId'));
	}


	// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
	public class assLoc {
		public Associated_Location__c ac {get; set;}
        public Site__c st {get; set;}
        public Quote qt {get; set;}
		public Boolean selected {get; set;}

		//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
		public assLoc(Associated_Location__c a) {
			ac = a;
			selected = false;
		}        
        
        public assLoc(Site__c s) {
			st = s;
			selected = false;
		}
        
		public assLoc(Quote q) {
			qt = q;
			selected = false;
		}        
	}
}

Visualforce:
<apex:page standardController="Associated_Location__c" extensions="quoteAssociatedSiteExtension" >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!AssLoc}" var="a" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!a.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!a.st.Street__c}" />
                <apex:column value="{!a.st.City__c}" />
                <apex:column value="{!a.st.State__c}" />
                <apex:column value="{!a.st.Zip__c}" />
                <apex:column headerValue="{!$ObjectType.Associated_Location__c.Fields.Remarks_Special_Instructions__c.Label}">
                    <apex:inputField value="{!a.ac.Remarks_Special_Instructions__c}" required="false"/>
                </apex:column>
               	<apex:column value="{!a.st.Site_Main_Phone__c}" />
                
                <apex:column value="{!a.st.Order_Master_Link__c}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>