• Sohan Raj Gupta
  • NEWBIE
  • 449 Points
  • Member since 2017
  • Sr. Associate Projects
  • Cognizant Technology Solutions


  • Chatter
    Feed
  • 16
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 81
    Replies

I can't break this loop:

List<User> userList = [SELECT Id FROM User WHERE UserRole.Name = 'X'];

     for(Obj__c obj: Trigger.new){
         for(User user : userList){
             if(obj.CreatedById != user.Id){
                 obj.OwnerId = user.Id;
             }
         }     
     }
I need to reassign an object if user's Role != 'X'.
We have a few users with Role 'X'. We need to reassign an object to one from these users, if it's created not by one of them. But my loop choose the last one and change owner even if owner is already correct (with Role 'X'). How can I fix it?
List<User> userList = [SELECT Id FROM User WHERE UserRole.Name = 'X'];

     for(Obj__c obj: Trigger.new){
         for(User user : userList){
             if(obj.CreatedById != user.Id){
                 obj.OwnerId = user.Id;
             }
         }     
     }

 
I want to delete records from PageBlockTable via Remote Action?
Hi,

Everytime there is a new update to Salesforce for Outlook, I package the software and deploy it to our users via SCCM. I was wondering if there was an easier way this could be managed by an automatic update either via SCCM or by the users themselves? Users do not have admin rights to their machines, but seeing how SFO is a user level installation, I was hoping there would be some solution to help manage these constant updates.

Thanks!
 
Hello Developers,

In VF email template want Amount field to be rendered based on IF condition like if currency is JYP or USD then render.
<div style="{!IF({!relatedTo.Related_Opportunity__r.CurrencyIsoCode}='JYP', 'display:block', 'display:none')}" >            
Amount : <apex:outputText value="{!relatedTo.CurrencyIsoCode}" rendered="true" /> 
</div>

Please Note: I do not want to go for controller want to achive this through VF Email template only.

Thanks
Mehul
 
VF page----------------------------
<apex:page controller="editDeleteContactRecords" >
    <apex:form >
        <apex:pageBlock title="Account Detail">
    
        <apex:pageBlockSection >
        <apex:outputField value="{!acc.Name}"/>
        <apex:outputField value="{!acc.Phone}"/>
        <apex:outputField value="{!acc.Fax}"/>
        <apex:outputField value="{!acc.AccountNumber}"/>
        </apex:pageBlockSection>
        
        <apex:pageBlockSection title="Contacts" collapsible="false" columns="1">
        
        
        <apex:pageBlockTable value="{!acts}" var="con">
        
       <apex:column headerValue="Action">
        <apex:commandLink value="Edit |" action="{!editContact}">
        <apex:param value="{!con.Id}" name="selectedContactId" assignTo="{!selectedContact}"/>
        </apex:commandLink>
        <apex:commandLink value="Del" action="{!deleteSelectedContact}">
        <apex:param value="{!con.id}" assignTo="{!delSelContId}" name="delContId"/>
        </apex:commandLink>
        </apex:column>     
        <apex:column value="{!con.Name}"/>
        <apex:column value="{!con.Email}"/>
        <apex:column value="{!con.Title}"/>
        
        </apex:pageBlockTable>
        
       </apex:pageBlockSection>
        
        </apex:pageBlock>
    </apex:form>

</apex:page>


Apex class----------------------------
public class editDeleteContactRecords
{
public Account acc {get;set;}
public Id id;





     public editDeleteContactRecords (){
     
           id  = ApexPages.CurrentPage().getparameters().get('id');
           acc  =  (id==null)?new Account():[select  Name,Phone,fax,AccountNumber From Account where Id =:id];
     
     
     }
     
      public List<Contact> getacts(){
          
          Id id  = ApexPages.CurrentPage().getparameters().get('id');
          List<Contact> acts = [select id,Name,Title,Email,Phone from Contact where AccountId =: id ];
         
          
         return acts;
        
        
          
          // parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
           
       }
     
    
    public PageReference editContact(){
    
     String selectedContact =apexpages.currentPage().getParameters().get('selectedContactId');
    PageReference pg=new PageReference('/'+'apex/UpdateDetail?id='+selectedContact);
    return pg;
        
    }
    // Initialize setCon and return a list of records
     public PageReference deleteSelectedContact(){
     String delSelContId= ApexPages.CurrentPage().getparameters().get('delContId');
       
        if(delSelContId!=null){
        Contact delContact = [Select Id from Contact where Id=:delSelContId];
        delete delContact;
        }
        
        return null;
        
    }  

}
Hi,

  I have a below simple trigger  it has 100% code coverage
trigger updateopportunitycontact on Lead (before update) 
{
for(Lead lead:System.Trigger.new) 
{ 

  if (lead.IsConverted && lead.ConvertedOpportunityId != null ) 
 { 
   Contact con = [SELECT Id FROM Contact WHERE Contact.Id = :lead.ConvertedContactId];
    
   Opportunity opp = [SELECT Contact__c from Opportunity where opportunity.id = :lead.ConvertedOpportunityId];
   
   opp.Contact__c = lead.ConvertedContactId;
   
   update opp;
   
   
  }
  
}

}
Test Class 
@isTest(SeeAllData = true)
private class   test_updateopportunitycontact {

public static testmethod void testupdateoppcon()
{
test.startTest();
Lead testLead = new Lead(
   LastName='123456789890654',
   Company = 'Couchbase11',
   LeadSource = 'Training',
   run_assn_rules_yn__c = False
   
  );
  
 insert testLead;


Database.LeadConvert lc = new database.LeadConvert();

lc.setLeadId(testLead.id);

 
LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];

lc.setConvertedStatus(convertStatus.MasterLabel);

Database.LeadConvertResult lcr = Database.convertLead(lc);

System.assert(lcr.isSuccess());

 
test.stopTest(); 
 
}

}

I keep getting below message when validated in production 

Code Coverage Failure
The following triggers have 0% code coverage. Each trigger must have at least 1% code coverage.
updateopportunitycontact


Please suggest me what might be the issue in the code. 

Thanks
Sudhir
 
Hi,

in my VF i am insert record in account on click of button.. but after clicking save button it creates record in database but at this stage only when i refresh page(F5 .. using chrome) again record is inserted in database.. I think it is happening because of browser warning "The page that you're looking for used information that you entered. Returning to that page might cause any action you took to be repeated. Do you want to continue?" when click refresh..

can anybody please suggest way forward to this condition.. 
<apex:form>
                    <apex:inputText id="txtName" value="{!name}" label="Input"/>
  </apex:form>
<script>
  var txtName = document.getElementById('txtName');
  txtName.value='abc';
</script>
Occur error: Uncaught TypeError: Cannot set property 'value' of null
How can set value to apex:inputText from javascript?
Hi All,

As we know in batch class, we can able to retrieve more than 50k records but in normal apex class i need to fetch more than 50K records.Is there any workaround?

Regards,
VSK98
If I select other from ownership picklist field in account it should create new box to add picklist value.