• SF Admin
  • NEWBIE
  • 39 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 28
    Replies
Hi,

I found the code below and it works fine if I use Name or ID, but I need the casesafeid from the parent Id.
If I will write the code below into a formula field, I get the error

Compiled formula is too big to execute (19.021 characters). Maximum size is 5.000 characters (Related field: Formula)

It is possible to change the code and I get also the casesafeid?
IF(LEN(Casesafeid({!Parent.Id})) < 1, Casesafeid({!Parent.Id}), 
IF(LEN(Casesafeid({!Parent.Parent.Id})) <1, Casesafeid({!Parent.Parent.Id}), 
IF(LEN(Casesafeid({!Parent.Parent.Parent.Id})) < 1, Casesafeid({!Parent.Parent.Parent.Parent.Id}), 
IF(LEN(Casesafeid({!Parent.Parent.Parent.Parent.Id})) < 1, Casesafeid({!Parent.Parent.Parent.Parent.Id}),  "Ultimate Parent Beyond 4 Levels"))))
Thanks,
Sascha
Hello all,

I have a requirement, where i need to create a record TSF in Account Related list whenever the territory is assigned to the account. Based on the territory name assigned to the account. I'm currently using this code. can you please optimize it.

Ex: Acccoun1 is having T1, T2. So i need the TSF records in the related list with the name of T1 and T2.
 
trigger INS_UPD_Account_TSF on Account (after insert,after update) {
   
    Set<Id> accountIds = new Set<Id>();         
    if(trigger.isinsert || trigger.isupdate){ 
    for(Account acct : Trigger.new){
      accountIds.add(acct.Id);
    }
}

list<AccountShare>accShareobj=[SELECT AccountId,UserOrGroupId FROM AccountShare WHERE AccountId=:accountIds and RowCause ='TerritoryManual'];  
    
    set<string>accids=new set<string>();
    set<string>usergroupids=new set<string>();
    for(AccountShare accs :accShareobj){
        if(accs.UserOrGroupId!=null && accs.AccountId!=null){
            accids.add(accs.AccountId);
            system.debug('accids--->'+accids);
            usergroupids.add(accs.UserOrGroupId);
            system.debug('accids--->'+accids);
        }
    }
    
    List<Group> glist=[SELECT RelatedId FROM Group Where Id IN:usergroupids];
    set<string>Grelatedid=new set<string>();
    for(Group grobj:glist){
        if(grobj.RelatedId !=null){
            Grelatedid.add(grobj.RelatedId);
        }
    
    }

    List<Territory > tobjlist=[SELECT Name FROM Territory WHERE Id IN:Grelatedid]; 
    system.debug('tobjlist--->'+tobjlist);      
    
    List<Account> acclist=[SELECT id FROM Account WHERE Id IN:accids]; 
    system.debug('acclist--->'+acclist); 
    
    List<TSF_vod__c> tsfRecords = new List<TSF_vod__c>();
  
    for(Account aId : acclist){
     
      for(Territory  ter:tobjlist){
      
        List<TSF_vod__c> existingTSFRecords = [SELECT Account_vod__c,External_Id_vod__c,Territory_vod__c FROM TSF_vod__c Where Territory_vod__c =:ter.Name and Account_vod__c =:aId.id Limit 1];
       
       if(existingTSFRecords.size()==0)
            {
           TSF_vod__c tsfRecord = new TSF_vod__c(Account_vod__c=aId.id);

            tsfRecord.Name = ter.name;
            tsfRecord.Territory_vod__c = ter.Name;
            System.debug('NEW TSF: ' + tsfRecord.Name);
            tsfRecords.add(tsfRecord);
           }
        }

    }
    insert tsfRecords;
}



 
Hello everyone
I am new to salesforce
Actually i wrote a test class it showing me error can anyone help to solve this problem.
Apex class

public with sharing class UpdateMileStone{

    //public Mile_Stone__c mStone {get; set;}
    public Case__c project;
    public List<MSList> newMSList{get; set;}

    public UpdateMileStone(ApexPages.StandardController stdController){
        project = (Case__c)stdController.getRecord();
        
        project = [Select Id, (Select Id, Name, Date_Received__c, Description__c, Date_Required_By__c From Required_Documents__r)
                from Case__c  where Id =:project.Id];
              
        newMSList = new List<MSList>(); 

        for(Required_Documents__c m: project.Required_Documents__r){
            MSList msListTemp = new MSList();             
            msListTemp.mStone= m;
                newMSList.add(msListTemp);            
        }                                 
    }
    //Updating Milestone    
    public PageReference updateDocumentRecords(){
        List<Required_Documents__c> MSUpdateList = new List<Required_Documents__c>();
        for(MSList mTemp: newMSList){
            if(mTemp.selectMS){
              MSUpdateList.add(mTemp.mStone);
            }
        }
        if(MSUpdateList.size()>0){
          update MSUpdateList;
        }else{
          ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please select one/multiple Required Documents to update!'));
          return null;
        }
        return new PageReference('/'+project.Id);
    }
    
       
    // Inner Class to create Payment Schedule with Checkbox   
    public class MSList{
        public Boolean selectMS {get; set;}
        public Required_Documents__c mStone {get; set;}
        
        public MSList(){
            selectMS=false;
        }
    }

Test class

  @IsTest 
  Public class updatemilestone{
    static testMethod void testUpdateMileStone(){

       Test.startTest();
        User usr = new User(Id=UserInfo.getUserId());
        System.runAs(usr){
        
            Case__c p1=new Case__c(Name='test1');
            insert p1;
            
            Required_Documents__c m1=new Required_Documents__c(Name='test2');
            m1.Date_Received__c = System.today();
            insert m1;
            
            ApexPages.StandardController stdcontroller = new ApexPages.Standardcontroller(p1);
           UpdateMileStone ums = new UpdateMileStone(stdcontroller);
           
            ums.updateMileStoneRecords();
           Required_Documents__c k=new Required_Documents__c();
                k.selectMS= true;
               
            }
           
            ums.updateDocumentRecords(); 
            
            }
       Test.stopTest();
     
    }

Thank you in advance
 
Hello all,

I have these two trigger 
trigger InsertPriceBookTrigger on Order (before insert) { 
 List<Pricebook2> stdPBL =  [select id from Pricebook2 where IsStandard = TRUE];
 if(!stdPBL.isEmpty()){
  for(Order o: Trigger.new)
   o.PriceBook2Id = stdPBL[0].id;
  }
}

and 
 
​trigger TaskTrigger on Task (after insert) {
    List<Order> ordersToUpdate = new List<Order>();

    for(Task t : Trigger.new) {
        if(t.WhatId.getSObjectType() == Order.sObjectType 
            && t.Subject.startsWith('Email:')) {
                ordersToUpdate.add(new Order(Id = t.WhatId, Status = 'Sent'));
        }
    }

    update ordersToUpdate;
}

for these triggers created the following test class
 
@isTest
public class Test3{
    public static testmethod void InsertPriceBookTrigger_Test1()
    {
       Account a = new Account(
            Name = 'Test'

        );
        insert a;

        Order o = new Order(name='Test1',EffectiveDate=system.today(),status='draft');
        insert o;

    List<Pricebook2> stdPBL =  [select id from Pricebook2 where IsStandard = TRUE];

    if (!stdPBL.isEmpty())
    {
        system.assertequals(stdPBL[0].id,o.PriceBook2Id);
    }
    } 

    public static testmethod void TaskTrigger_Test1()
    {

            Order o = new Order(name='Test1',EffectiveDate=system.today(),status='draft');
            insert o;

        Task t = new Task(whatid=o.id,Priority = 'normal',status='open',subject='Email:xxxx');
        insert t;

        system.assertequals('Sent',o.status);
    }


}

It fails to cover the triggers. The error on the test history is :


System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Account Name:You must enter a value: []

Any ideas why?
Hi,

I am very new to the Visual Force Page,

I wanted to display whole value like 1, 2, 3,.etc,. not diceimal value like 1.0, 2.0, 3.0, etc,..

How to achieve this ?
 
<tr style="display: {!IF(ISBLANK(Quotation__c.SL1__c), 'none', 'table-row')};">
  <td align="left" >{!Quotation__c.SL1__c} </td>
  <td align="left" >{!Quotation__c.Qty1__c} </td>
  <td align="left" >{!Quotation__c.Product_Description1__c} </td>
</tr>
 
Here "SL1__c and Qty1__c" fields are displaying decimal values.
trigger OwnerAccountPopulateTrg on Opportunity (before insert,before update) {
for(opportunity opp:trigger.new)
{
Set<Id> accids = new Set<Id>();
if(opp.accountId != null){
accids.add(opp.accountid);
}
if(accids.size()>0)
{
Map<Id,Id> mpOwners = new Map<id,Id>();
for(Account acc : [Select id, ownerId from Account where id in:accids])
{
mpOwners.put(acc.id,acc.ownerId);
}
for(Opportunity opp1:trigger.new){
//Custom Owner Field
opp1.New_User__c = mpOwners.get(opp.accountId);
}
}
}
}
Hi,
I have created a Component and a Page.Below is my Component Code

<apex:component controller="contentController">
<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
<Script type="text/javascript">

function WindowNew()
{
  Window.open('https://dataloader.io/');
}
</Script>
<apex:form >
<apex:commandbutton onclick="Window.open('https://dataloader.io/')" value=" Upload "/>
<apex:commandbutton onclick="Window.open();" value="Upload "/>
</apex:form>
</apex:component>

Below is my Page Code

<apex:page controller="contentController">
<script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
<c:BulkUpload />
</apex:page>

While clicking the Button,the window is not opening as a popup.Can anyone help me to solve this issue.

Thanks
Maheshwar
 
trigger FireMail on Lead__c (after insert,after update) {

    list<lead__c> leads = new list<lead__c>();
    string mailcontent ;
    leads = trigger.new ;
    
    for(lead__c ld : leads){
    
        string nm = ld.name ;
        string EmailId = ld.Email_Id__c ;
        
        if(EmailId != null){
            
               mailcontent ='Thanks For contacting Us ' ;           
                                                                                                        // here error is Occur
               Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
               string [] toaddress= New string[]{EmailId};
               email.setSubject('Thanks for Contacting .');
               email.setPlainTextBody(mailcontent);
               email.setToAddresses(toaddress);
               Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
        
        } 
    }
}
Horizontal User is creating opportunity with less fields and sending approval request to Vertical user.
Vertical User is suppose to fill the mandatory fields on request opportunity,but vertical user is simply approving and not filling any details, so how can I restrict my vertical user from Approving???
trigger on events/tasks after insert and after update to update a field on opportunity,with the value of field in events/tasks..
  • February 05, 2015
  • Like
  • 0
Hi


how to call a apex class or method from  botton click ,please give me sample code for that 

Thanks in advance
Sri.
 Hi,
Below is my error  when this error will be cmng my page
System.QueryException: List has more than 1 row for assignment to SObject 

Thanks,
padma
  • February 04, 2015
  • Like
  • 0
HI I am new to To the Ape can anybody tell what is the procedure to learn the Apex language. my problem is that I am unable to do perform practicles Like DML opearion on the Developer console. 
Hi,

I found the code below and it works fine if I use Name or ID, but I need the casesafeid from the parent Id.
If I will write the code below into a formula field, I get the error

Compiled formula is too big to execute (19.021 characters). Maximum size is 5.000 characters (Related field: Formula)

It is possible to change the code and I get also the casesafeid?
IF(LEN(Casesafeid({!Parent.Id})) < 1, Casesafeid({!Parent.Id}), 
IF(LEN(Casesafeid({!Parent.Parent.Id})) <1, Casesafeid({!Parent.Parent.Id}), 
IF(LEN(Casesafeid({!Parent.Parent.Parent.Id})) < 1, Casesafeid({!Parent.Parent.Parent.Parent.Id}), 
IF(LEN(Casesafeid({!Parent.Parent.Parent.Parent.Id})) < 1, Casesafeid({!Parent.Parent.Parent.Parent.Id}),  "Ultimate Parent Beyond 4 Levels"))))
Thanks,
Sascha
We are firing a visualforce template via workflow rule, work flow rule is on Opportunity and it is coming 100% empty in some cases and in some cases it's working fine. When we test the template manually it's working fine. Is there any limitation for visualforce template or what might be the issue?

Thanks in advance.
Hi,

Could anybody help me with a formula field? Namely how I can use formula to choose the latest date for example:

a = 09/09/2013
b = 11/10/2014
c = 01/01/2010

What if 2 fields are empty how it can be handled in the formula below . This formula is working perfectly but only if all fields are populated with date:

if(a>b && a>c,a,if(b>a && b>c,b,c))

Thanks in advence
 
Hi Everyone,

I have a button initially, it is disable(i.e not able to click.).
i want to enable it when if any one of the check box is checked.
here is my check box code.and button code
<apex:column headerValue="Select" style="text-align: center"> 
                        <apex:inputCheckbox id="isCheckBox" style="opacity:{!w2.isPartOrderabilityStatusCode};" value="{!w2.isCheckBox}" >
                            <apex:actionSupport event="onclick" action="{!checkBoxStaus}" reRender="pb2"/>
                        </apex:inputCheckBox>
 </apex:column>
<apex:commandButton value="Add Selected"  action="{!selectRecords}" id="sparebtn" reRender="frm">
                    <apex:actionSupport event="onclick" rerender="resultsBlock" status="statusSaveTrip"/>
</apex:commandButton>

Thanks
Lakshminarayana
 
Hi All,

I have 2 trigger with before event and logic was one for insert and other for update :

Trigger 1:
trigger Test_trigger_event2 on Account (before insert, before update) {

   if (trigger.isBefore) {
        if (trigger.isInsert) {
            //DO SOMETHING
    system.debug('This is inser and Update');

        }
    }
------------------------------------------------------------------------------------------
Trigger 2.

trigger Test_Trigger_event on Account (before update) {

      
  if (trigger.isUpdate)  {
            //DO SOMETHING
        system.debug('@@@@@@@@@@@@ in Update');            

        }
 }

But When i am inserting record trigger 2 was firing , but it should not fired , it will fired only in update  operation ,not in insert operation.
Please let me know what changes needed in trigger 2.
Thanks!!
 
I will be implementing Partner Communities. I am testing in a dev org to confirm functionality. I have a Button on the Contact that executes javascript. It works fine from the internal org but gives this error from the community:

A problem with the OnClick JavaScript for this button or link was encountered:

{faultcode:'UNKNOWN_EXCEPTION', faultstring:'UNKNOWN_EXCEPTION: Site under construction', }

The button code is
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")};
var dob = '{!Contact.Birthdate}';
var sal = '{!Contact.Annual_Income__c}';
var plandate = '{!Contact.Date_Entered_Plan__c}';
var inflation = '{!Contact.Expected_Raise_Per_Year__c}';

if( dob == '' || sal == '' ||inflation == '' || plandate == '')
{
alert('Please Validate Birthdate/Annual Income/Date Entered Plan/Expected Raise Per Year/ Spouse DOB');
}
else
{

sforce.apex.execute("GeneratePensionReport","attachReport", {id:"{!Contact.Id}"});
window.alert("Pension Report has been Generated and Attached." );
}

I think this issue has to do with the context - since it is running from the community it thinks it has a different domain.  Not sure how to address this.
Any help would be appreciiated.