• Mateo Alcauter
  • NEWBIE
  • 50 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 7
    Replies
I'm trying to make a trigger so that my Related_Party__c records cannot have both Party_Type_Code__c "Y" and "P"
They can have one or the other, but not both. This trigger currently works, except when I try to update a related party from "Y" to "P" or vise-versa it doesn't let me. How can I fix this so that it does let me update.
 
trigger RelatedPartyTriggers on Related_Party__c (before insert, before update) {
    
   set<String> setName = new set<String>();
   set<String> setExistingName = new set <String>();
    
    for(Related_Party__c party : Trigger.new) {
        setName.add(party.PartyName__c);
    }
    
    for (Related_Party__c party : [select PartyName__c, Party_Type_Code__c From Related_Party__c where PartyName__c in : setName AND Active__c = true AND (Party_Type_Code__c = 'Y' OR Party_Type_Code__c = 'P')]) {
        setExistingName.add(party.PartyName__c);
    }
    
    if(Trigger.isInsert || Trigger.isUpdate)
        for(Related_Party__c p : Trigger.new) {
            if(setExistingName.contains(p.PartyName__c) && (p.Party_Type_Code__c == 'Y' || p.Party_Type_Code__c == 'P') && p.Active__c == true) {
                p.PartyName__c.addError('Cannot be both Y and P');
            }
        }  
}


 
Under accounts, we have a custom related list called "related parties"
Related parties can be different types (Beneficiary, Guardian, Interested Party, LPOA)
I want to make a rule so that the same person cannot be both an interested party an LPOA. 
Example: Under Alex's account, Rebecca is a related party of type "Interested Party", if someone else tries to add Rebecca as an "LPOA" under Alex's account, they should not be allowed since she is already an "Interested Party".
The other types don't matter. We just dont want to allow someone to be both Interested Party and LPOA under the same account. 

I was thinking of doing a VLOOKUP, but this does not work.
VLOOKUP($ObjectType.Related_Party__c.Fields.Name , $ObjectType.Related_Party__c.Fields.Name , Party_Type__c ) = "Interested Party" && VLOOKUP($ObjectType.Related_Party__c.Fields.Name , $ObjectType.Related_Party__c.Fields.Name , Party_Type__c ) = "LPOA" 
 
Is there a way to remove commas from a text field using a custom field or a process?
For example if a field has the value "this is a test, okay." I want a new field to duplicate that without the comma. New value would be
"this is a test okay."
I have this button that calls a function. How can i call this function (filterTransactions) when the page first loads?
I tried this, but it does not work.
<apex:page controller="CommunityPostedTransactionsController" action="{!filterTransactions}" showHeader="false" sidebar="false" cache="false">

Here is the button code:
<apex:commandButton action="{!filterTransactions}" value="Filter" rerender="output,selectListPanel, exportCSV" immediate="false"></apex:commandButton>

 
How can i get the users photo in this SOQL query

List<AggregateResult> badges= [SELECT Recipient.Name rec, count(id) cnt, Recipient.FullPhotoUrl From WorkBadge GROUP BY Recipient.Name, Recipient.FullPhotoUrl HAVING count(id) > 0 ORDER BY count(id) DESC];          

I'm getting the error message:  field 'FullPhotoUrl' can not be grouped in a query call     
How can i display the results from this list on a visualforce page?

Controller:
public List<AggregateResult> BadgeList
    {
        get
        {
            List<AggregateResult> badges= [SELECT RecipientId, count(id) From WorkBadge GROUP BY RecipientId ORDER BY count(id) DESC LIMIT 5];                   
            return badges;
        }
        set;
    }

Visualforce page:
    <apex:pageBlock>
      <apex:pageBlockTable value="{!BadgeList}" var="badges" title="My Badges" columns="2" align="center" styleClass="table table-striped">
        <apex:facet name="header">My Badges</apex:facet>        
            <apex:column value="{!badges['RecipientId']}"/>
            <apex:column value="{!badges['count(id)']}"/>             
        </apex:pageBlockTable> 
        </apex:pageBlock>


Error message when i go to the visualforce page:
Unknown property 'AggregateResult.count(id)'
Error is in expression '{!badges['count(id)']}' in component <apex:column> in page companyhome
Error evaluating dynamic reference 'count(id)'
There is a button on transactions that submit a transaction for approval.
I want to make a custom button to mass submit transactions for approval.
I'm trying to this by creating a list view in which you can select the transactions you want to submit for approval and idially you would click the "mass submit for approval" button that would simulate the "submit for approval" on every transaction that was selected. 
Any idea on how I can do this? The submit for approval button is a salesforce button and i cannot find the id of this button anywhere. 
Hello,

I have a button on Transaction__c (which is a custom object) to submit a transaction for approval. This would make the transaction go through an approval process where it first checks if this transaction has the requirements to be submited for approval.
I'm attempting to create a javascript in which someone can select multiple transactions and mass submit them for approval.
My code does not work when a transaction doesn't meet the requirements. It only works if all the transactions selected meet the requirements. 
This means if i select 2 transactions, 1 meets the requirements, 1 doesn't, it fails completely and won't even submit the one that does meet the requiments.

"Submit_for_Approval__c" is a checkbox that when = true will automatically start the approval process.

Here is the code:

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")} 


var records1 = {!GETRECORDIDS($ObjectType.Transaction__c)}; 
var myquery = 'SELECT Id, Submit_for_Approval__c FROM Transaction__c WHERE Id in (\'' + records1.join('\',\'') + '\')'; 
var queryResults = sforce.connection.query(myquery); 
var records = queryResults.getArray("records"); 
var cycleTrans = new Array; 

var r = confirm('Are you sure you want to submit ' + records.length + ' transactions for approval?'); 
if (records.length == null) 

alert('Please select a record'); 

else 

if (r == true) { 
for (var i=0; i<records.length; i++) 

var myObj = records[i]; 
myObj.Submit_for_Approval__c = true; 
cycleTrans.push(myObj); 

alert('Submitted transactions for approval'); 
result = sforce.connection.update(cycleTrans); 

}
I'm creating a custom button using onclick javascript. I have called the custom object that i'm working with, but i'm unable to call any custom fields of this custom object. I highlited the line that is not working properly. 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")} 

var records = {!GETRECORDIDS($ObjectType.Transaction__c)}; 
var strIDs=''; 
if (records[0] == null) 

alert('Please select a record'); 

else 

for (var n=0; n<records.length; n++) 

strIDs = records[n]; 
alert(strIDs.Total_Fee__c); 

alert('Success'); 
}
I'm trying to make a trigger so that my Related_Party__c records cannot have both Party_Type_Code__c "Y" and "P"
They can have one or the other, but not both. This trigger currently works, except when I try to update a related party from "Y" to "P" or vise-versa it doesn't let me. How can I fix this so that it does let me update.
 
trigger RelatedPartyTriggers on Related_Party__c (before insert, before update) {
    
   set<String> setName = new set<String>();
   set<String> setExistingName = new set <String>();
    
    for(Related_Party__c party : Trigger.new) {
        setName.add(party.PartyName__c);
    }
    
    for (Related_Party__c party : [select PartyName__c, Party_Type_Code__c From Related_Party__c where PartyName__c in : setName AND Active__c = true AND (Party_Type_Code__c = 'Y' OR Party_Type_Code__c = 'P')]) {
        setExistingName.add(party.PartyName__c);
    }
    
    if(Trigger.isInsert || Trigger.isUpdate)
        for(Related_Party__c p : Trigger.new) {
            if(setExistingName.contains(p.PartyName__c) && (p.Party_Type_Code__c == 'Y' || p.Party_Type_Code__c == 'P') && p.Active__c == true) {
                p.PartyName__c.addError('Cannot be both Y and P');
            }
        }  
}


 
How can i display the results from this list on a visualforce page?

Controller:
public List<AggregateResult> BadgeList
    {
        get
        {
            List<AggregateResult> badges= [SELECT RecipientId, count(id) From WorkBadge GROUP BY RecipientId ORDER BY count(id) DESC LIMIT 5];                   
            return badges;
        }
        set;
    }

Visualforce page:
    <apex:pageBlock>
      <apex:pageBlockTable value="{!BadgeList}" var="badges" title="My Badges" columns="2" align="center" styleClass="table table-striped">
        <apex:facet name="header">My Badges</apex:facet>        
            <apex:column value="{!badges['RecipientId']}"/>
            <apex:column value="{!badges['count(id)']}"/>             
        </apex:pageBlockTable> 
        </apex:pageBlock>


Error message when i go to the visualforce page:
Unknown property 'AggregateResult.count(id)'
Error is in expression '{!badges['count(id)']}' in component <apex:column> in page companyhome
Error evaluating dynamic reference 'count(id)'
Hello,

I have a button on Transaction__c (which is a custom object) to submit a transaction for approval. This would make the transaction go through an approval process where it first checks if this transaction has the requirements to be submited for approval.
I'm attempting to create a javascript in which someone can select multiple transactions and mass submit them for approval.
My code does not work when a transaction doesn't meet the requirements. It only works if all the transactions selected meet the requirements. 
This means if i select 2 transactions, 1 meets the requirements, 1 doesn't, it fails completely and won't even submit the one that does meet the requiments.

"Submit_for_Approval__c" is a checkbox that when = true will automatically start the approval process.

Here is the code:

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")} 


var records1 = {!GETRECORDIDS($ObjectType.Transaction__c)}; 
var myquery = 'SELECT Id, Submit_for_Approval__c FROM Transaction__c WHERE Id in (\'' + records1.join('\',\'') + '\')'; 
var queryResults = sforce.connection.query(myquery); 
var records = queryResults.getArray("records"); 
var cycleTrans = new Array; 

var r = confirm('Are you sure you want to submit ' + records.length + ' transactions for approval?'); 
if (records.length == null) 

alert('Please select a record'); 

else 

if (r == true) { 
for (var i=0; i<records.length; i++) 

var myObj = records[i]; 
myObj.Submit_for_Approval__c = true; 
cycleTrans.push(myObj); 

alert('Submitted transactions for approval'); 
result = sforce.connection.update(cycleTrans); 

}
I'm creating a custom button using onclick javascript. I have called the custom object that i'm working with, but i'm unable to call any custom fields of this custom object. I highlited the line that is not working properly. 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")} 

var records = {!GETRECORDIDS($ObjectType.Transaction__c)}; 
var strIDs=''; 
if (records[0] == null) 

alert('Please select a record'); 

else 

for (var n=0; n<records.length; n++) 

strIDs = records[n]; 
alert(strIDs.Total_Fee__c); 

alert('Success'); 
}