• Anand_V
  • NEWBIE
  • 35 Points
  • Member since 2014
  • Application Developer
  • CSC

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 13
    Replies
Hello Everyone,
The code snippet works for the limited data sample.  I want to bulkify the part where it updates the spousename.

This SF article said I can use a MAP variable.    
https://developer.salesforce.com/page/Programming_Techniques#Using_a_Map_as_an_In-Memory_Join_Table

I am struggling at what to do.  Please help me write the Map and Map.put statements.  Thanks.

 
//get the Scotland Members 
Relationship__c[] MemberIDs=[
	SELECT Account__c,contact__c
	FROM Relationship__c
	WHERE relationship_type__c='member'
	and Contact__c in (
		SELECT Contact__c
		FROM Account_Affiliation__c
		WHERE Account__c='0016100000STADyAAP'
		and Benefit_Status__c not in ('Terminated')
		and IsActive__c = true
		and IsDeleted = false)
];

//instantiate the report object variable
list<RptChapterRoster__c> rptList = new list<RptChapterRoster__c>();

//create the rpt rows
for(Relationship__c r :MemberIDs){
        rptList.add(new RptChapterRoster__c(Chapter_Name__c='WPO Scotland',Member_Contact__c = r.contact__c,Household_Account__c=r.account__c ));
}

//update with spousename -- this is not bulkified -- can't figure out how to use map for this
for(RptChapterRoster__c myvar:rptList) {
	Relationship__c  r = [select id,contact__c from Relationship__c where relationship_type__c='spouse' and account__c = :myvar.household_account__c];
	myvar.Spouse_Contact__c=r.contact__c;
}

insert rptList;


 
I am preparing for Data Architecture and Management Certification and I came across this statement during Bulk API topic.
"Errors in batches trigger single-row processing for that
batch, and that processing heavily impacts performance." What doest this mean? If one record fails during 200 batch size, for that particular batch alone it will process record by record?
  • September 29, 2017
  • Like
  • 0
Woud it be a good practice if I am maintaining versions only for Apex,VF & Static resources? Ignoring all other types like workflow, approval processes,etc...?
Can someone help me?
I need to call a method from my extension controller when onclick happens in my apex:tab, so I use apex:actionSupport and apex:param to do that.
The method i should call receive one param, produto.

When i try to save, salesforce tells me that vf can't find the method on standardController:

Result: [OPERATION FAILED]: pages/ConfiguracaoDoProduto.page: Método 'Configuracoes_com_produtos__cStandardController.setProdutoAtual()' desconhecido

Here is part of the vf code of that:
<apex:tabPanel height="250px" switchType="client" id="TabelaPainel" styleClass="TheTabPanel" tabClass="TheTabPanel" contentClass="tabContent" activeTabClass="activeTab" inactiveTabClass="inactiveTab">
				<apex:repeat var="item" value="{!fasesDaConfiguracao}">
					<apex:tab label="{!item}" name="{!item}" rendered="{!(fasesDaConfiguracao.size != null)}">
						<apex:actionSupport event="onclick" action="{!setProdutoAtual}">
							<apex:param name="produto" value="{!item}"/>
						</apex:actionSupport>
						<pageBlockTable value="{!item}" var="config" rendered="{!(fasesDaConfiguracao.size != null)}" columnsWidth="15%,85%">
							<apex:column headerValue="Incluir" headerClass="headerStyle" rendered="{!config.render}">
								<apex:inputCheckbox onclick="uncheckOthers(this)"/>
							</apex:column>
							<apex:column value="{!produtosBanco.Name}" headerClass="headerStyle" rendered="{!config.render}"/>
						</pageBlockTable>
					</apex:tab>
				</apex:repeat>
			</apex:tabPanel>

here is the part of the extension controller code:
 
public void setProdutoAtual(string produto)
	{
		produtoAtual = produto;
	}

Here is the vf full code:
<apex:page standardController="Configuracoes_com_produtos__c" extensions="ConfiguracaoDoProdutoController">
	<apex:stylesheet value="/sCSS/21.0/sprites/1297816277000/Theme3/default/gc/versioning.css"/>
	<style type="text/css">
		.selected
		{
			background-color: #C0C0C0;
			color: #000000;
			font-size: 170%;
			font-weight: bold;
		}

		.headerStyle
		{
			background: rgb(255, 127, 0) !important;
			color: #FFFFFF !important;
		}

		.myCustomMessage .message
		{
			background: none !important;
			border: none !important;
		}
	</style>
	<apex:sectionHeader title="{!Configuracoes_com_produtos__c.Name}"/>
	<apex:form id="formulario">
		<apex:pageBlock id="configuracoes">
			Pais:
			<apex:selectList value="{!pais}" id="pais" size="1" multiselect="false">
				<apex:selectOptions value="{!opcoesPais}"/>
				<apex:actionSupport event="onchange" action="{!procurar}"/>
			</apex:selectList>
			Família de Produtos:
			<apex:selectList value="{!familia}" id="familia" size="1" multiselect="false">
				<apex:selectOptions value="{!opcoesFamilia}"/>
				<apex:actionSupport event="onchange" action="{!procurar}"/>
			</apex:selectList>
			Voltagem:
			<apex:selectList value="{!voltagem}" id="voltagem" size="1" multiselect="false">
				<apex:selectOptions value="{!opcoesVoltagem}"/>
				<apex:actionSupport event="onchange" action="{!procurar}"/>
			</apex:selectList>
			<apex:tabPanel height="250px" switchType="client" id="TabelaPainel" styleClass="TheTabPanel" tabClass="TheTabPanel" contentClass="tabContent" activeTabClass="activeTab" inactiveTabClass="inactiveTab">
				<apex:repeat var="item" value="{!fasesDaConfiguracao}">
					<apex:tab label="{!item}" name="{!item}" rendered="{!(fasesDaConfiguracao.size != null)}">
						<apex:actionSupport event="onclick" action="{!setProdutoAtual}">
							<apex:param name="produto" value="{!item}"/>
						</apex:actionSupport>
						<pageBlockTable value="{!item}" var="config" rendered="{!(fasesDaConfiguracao.size != null)}" columnsWidth="15%,85%">
							<apex:column headerValue="Incluir" headerClass="headerStyle" rendered="{!config.render}">
								<apex:inputCheckbox onclick="uncheckOthers(this)"/>
							</apex:column>
							<apex:column value="{!produtosBanco.Name}" headerClass="headerStyle" rendered="{!config.render}"/>
						</pageBlockTable>
					</apex:tab>
				</apex:repeat>
			</apex:tabPanel>
			<div align="center">
				<apex:commandButton action="{!adicionar}" value="Adicionar"/>
				<apex:commandButton action="{!salvar}" value="Salvar"/>
			</div>
		</apex:pageBlock>
		<script type="text/javascript">
			function uncheckOthers(obj)
			{
				var vTbl = obj.parentNode.parentNode.parentNode;
				var vCheckboxes = vTbl.getElementsByTagName('INPUT');
				for (var i = 0; i < vCheckboxes.length; i++)
				{
				if (vCheckboxes[i] != obj && obj.checked) vCheckboxes[i].checked = false;
				}
			}
		</script>
	</apex:form>
</apex:page>

Here is the Extension Controller full code:
public class ConfiguracaoDoProdutoController 
{
	public List<SelectOption> opcoesPais {get;set;}
	public List<SelectOption> opcoesFamilia {get;set;}
	public List<SelectOption> opcoesVoltagem {get;set;}
	public string pais {get;set;}
	public string familia {get;set;}
	public string voltagem {get;set;}
	public string primeiroItem {get;set;}
	public string stringConfiguracao {get;set;}
	public string produtoAtual {get;set;}
	public List<string> fasesDaConfiguracao {get;set;}
	public List<Product2> produtosBanco {get;set;}

	public ConfiguracaoDoProdutoController(ApexPages.StandardController controller)
	{
		string idConfiguracao = controller.getId();
		fasesDaConfiguracao = new List<string>();
		opcoesPais = new List<SelectOption>();
		opcoesPais.add(new SelectOption('Sem Filtro',' '));
		opcoesFamilia = new List<SelectOption>();
		opcoesFamilia.add(new SelectOption('Sem Filtro',' '));
		opcoesVoltagem = new List<SelectOption>();
		opcoesVoltagem.add(new SelectOption('Sem Filtro',' '));
		List<Product2> produtos = [SELECT Voltagem__c, Family, Pais__c FROM Product2 WHERE Voltagem__c != null OR Family != null OR Pais__c != null];
		Set<string> voltagens = new Set<string>();
		Set<string> familias = new Set<string>();
		Set<string> paises = new Set<string>();
		for(Product2 produto : produtos)
		{
			if(produto.Voltagem__c != null)
				voltagens.add(produto.Voltagem__c);
			if(produto.Family != null)
				familias.add(produto.Family);
			if(produto.Pais__c != null)
				paises.add(produto.Pais__c);
		}
		for(string voltagem : voltagens)
			opcoesVoltagem.add(new SelectOption(voltagem, voltagem));
		for(string familia : familias)
			opcoesFamilia.add(new SelectOption(familia, familia));
		for(string pais : paises)
			opcoesVoltagem.add(new SelectOption(pais, pais));
		Configuracoes_com_produtos__c configuracao = [SELECT Configuracao_Salva__c FROM Configuracoes_com_produtos__c WHERE Id =: idConfiguracao];
		string stringConfiguracao = configuracao.Configuracao_Salva__c;
		List<string> fasesDaConfiguracao = stringConfiguracao.split('<br/>');
		procurar();
	}

	public void setProdutoAtual(string produto)
	{
		produtoAtual = produto;
	}

	public void procurar()
	{
		string conditionQuery = '';
		if(pais != 'Sem Filtro' && pais != null)
		{
			conditionQuery += ' and Pais__c = ' + pais;
		}
		if(familia != 'Sem Filtro' && familia != null)
		{
			conditionQuery += ' and Family = ' + familia;
		}
		if(voltagem != 'Sem Filtro' && voltagem != null)
		{
			conditionQuery += ' and Voltagem__c = ' + voltagem;
		}
		string query = 'SELECT Id, Name From Product2 WHERE Tipo_de_Produto__c = ' + produtoAtual;
		query += conditionQuery;
		produtosBanco = Database.query(query);
	}
}


 
Hello,

I am trying to give users a more convenient way to add records to a related list (which is derived from a custom object) from the Opportunity detail page via a Visualforce page (essentially inline adding).  I've been trying to modify the following code, which works if the visualforce page is on the custom object page layout.  The issue is once I try to make standardcontroller = Opportunity, which I need to do so the visualforce page shows up on the opportunity page layout, I start receiving errors.  Any ideas?

<apex:page standardController="Custom_Object__c">
<apex:form >
     <apex:pageBlock mode="edit" >
         <apex:pageblockSection title="Add Record" columns="2">
             <apex:inputField value="{!Custom_Object__c.Field1__c}"/>
             <apex:inputField value="{!Custom_Object__c.Field2__c}"/>
             <apex:commandButton action="{!save}" value="Submit"/>
         </apex:pageblockSection>
     </apex:pageBlock>
</apex:form>
</apex:page>

When I simply change the controller to Opportunity, I get the following error: Error: Unknown property 'OpportunityStandardController.Custom_Object__c' which ties to line 5.

I've tried adding in the path to the custom object by changing line 5 to:
             <apex:inputField value="{!Opportunity.Custom_Object__c.Field1__c}"/>
But I get the error Error: Invalid field Custom_Object__c for SObject Opportunity

I've tried replacing __c with __r to that same line since it's a related list, and then I get this error:
Error: Could not resolve the entity from <apex:inputField> value binding '{!Opportunity.Custom_Object__r.Field1__c}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.

Any help is appreciated!

Thanks,
Alex
Public void GetallHiringManagers()

         {

         List<Hiring_Manager__c>lstManager =[select id ,name ,Location__c from Hiring_Manager__c];

             System.debug('Hiring Manger Collection Size--' + lstManager.size());
       
             If (! lstManager.isEmpty())
                                          {
    for (Hiring_Manager__c hr:lstManager) 

                    {
                        system.debug('Hiring Manger Recors is..'+  hr);

             }

         }

         

     }

}


============================================
//Calling from anonymous window :

HelloWolrd helper = new HelloWolrd();
helper.GetallHiringManager();
Hello Everyone,

 I Have a scenario :

I am creating a visualforce page on Invoice custom object, and a custom button which generates the PDF of the detail page.
and I have a Picklist field called Currency of values (USD,RIAL).

Now there is a change in taxes for these two currencies. and Tax will be calculated on the detail  page itself.

So, My task is when the picklist field is changed to USD then the tax fields related to USD should be displayed on the VF page.
and the same with the RIAL when picklist is changed to RIAL then the taxes related to RIAL should be displayed on the VF page.
and  There should be only one button on the detail page to achieve this.

Do anyone has an Idea how to achieve this scenario.

Any help would be appreciated....!
  • April 27, 2016
  • Like
  • 0
I have a trigger to update a related account field on my leads when there is a name match or a match of a third party id. This trigger should fire whenever a lead is created or updated and works perfectly for individual records but does not work when I use the data import wizard to update multiple leads at once. 

My research into this issue tells me that apex triggers by default should fire for bulk records and indeed previous triggers I've written have worked for bulk records so I'm confused about why there's an exeption here. I'll paste my code below. Thank you.
 
trigger updateRelatedAccount on Lead (before update, before insert) { 
    set<string> accNames = new set<string>();
    set<Decimal> accLIDs = new set<Decimal>();
        for(Lead ld : Trigger.New){
        	accNames.add(ld.Company);
            accLIDs.add(ld.Company_ID__c);
        } 
    
    

        list<Account> accs = new list<Account>([Select Id,Name,LinkedIn_Id__c from account where name in :accNames or LinkedIn_Id__c in :accLIDs]); //using WHERE IN
        map<String,id> mapaccs = new map<String,id>();
    	map<Decimal, id> mapids = new map<Decimal, id>();

        for(Account ac : accs){
        	mapaccs.put(ac.Name,ac.Id);
            mapids.put(ac.LinkedIn_Id__c,ac.Id);
        }

        for(Lead lds : Trigger.New){ 
            //you new lead has company id, check if lead has same id
            if (lds.Company_ID__c !=null and mapids.get(lds.Company_ID__c)!=null) { 
                lds.Related_Account__c = mapids.get(lds.Company_ID__c); //if so, copy id
            } else { //if not, search by name
                lds.related_account__c = mapaccs.get(lds.company);
            }
        }
  }

 
Hello Everyone,
The code snippet works for the limited data sample.  I want to bulkify the part where it updates the spousename.

This SF article said I can use a MAP variable.    
https://developer.salesforce.com/page/Programming_Techniques#Using_a_Map_as_an_In-Memory_Join_Table

I am struggling at what to do.  Please help me write the Map and Map.put statements.  Thanks.

 
//get the Scotland Members 
Relationship__c[] MemberIDs=[
	SELECT Account__c,contact__c
	FROM Relationship__c
	WHERE relationship_type__c='member'
	and Contact__c in (
		SELECT Contact__c
		FROM Account_Affiliation__c
		WHERE Account__c='0016100000STADyAAP'
		and Benefit_Status__c not in ('Terminated')
		and IsActive__c = true
		and IsDeleted = false)
];

//instantiate the report object variable
list<RptChapterRoster__c> rptList = new list<RptChapterRoster__c>();

//create the rpt rows
for(Relationship__c r :MemberIDs){
        rptList.add(new RptChapterRoster__c(Chapter_Name__c='WPO Scotland',Member_Contact__c = r.contact__c,Household_Account__c=r.account__c ));
}

//update with spousename -- this is not bulkified -- can't figure out how to use map for this
for(RptChapterRoster__c myvar:rptList) {
	Relationship__c  r = [select id,contact__c from Relationship__c where relationship_type__c='spouse' and account__c = :myvar.household_account__c];
	myvar.Spouse_Contact__c=r.contact__c;
}

insert rptList;