• Avinash@salesforce
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 2
    Replies
Hi friends,

I have a scenario, i need to display account team members related to a account record on a visualforce page. For this scenario, I have created a visualforce page which displays all account records in a picklist field.
Here i need to implement a logic which will display account team members related to that record selected.

Here is my code :


<apex:page standardController="Account" extensions="testaccount">
<apex:form >
    <apex:pageBlock >
       <apex:selectList value="{!accountId}" title="Account" size="1" id="accounts">
    <apex:selectOptions value="{!accountList}" />
</apex:selectList>
    </apex:pageBlock>
</apex:form>
</apex:page>


Controller:

public with sharing class testaccount {

        public Account acc{get;set;}
        
        public string getaccountfields{get;set;}
        
 public Id accountId {
    get;
    set;
}

public List<SelectOption> getAccountList() {
    List<SelectOption> accounts = new List<SelectOption>();
    accounts.add(new SelectOption('', '--None--'));

    for (Account account: [
        select Name
        from Account ]) {
        accounts.add(new SelectOption(account.Id, account.Name));
    }

    return accounts;
}
        
        
    public testaccount(ApexPages.StandardController controller) {

       // code for account team

    }

}



Can anyone help me with this scenario please.

I need to display account team related to selected account record in picklist value.

Any help please....!

Thanks,
Avinash

 
Hi friends,

Here we are converting a lead automatically.
So the point is, whenever a lead is converted a new contact is created. We are using contact duplication rule which will not allow duplicate contact to be created if a contact already exists with the same EMAIL.

So I am writing an apex trigger to merge the new contact with the existing one so that the duplicate rules are bypased.

But, It is still throwing an error and the converted contact isnot been added to the existing one.
So, how to achieve this.

This is my trigger.

trigger DulpicateMergeTrigger on Lead (before insert) {
    List<Lead> lead = new List<Lead>();
    List<Contact> contact = new List<Contact>();
    List<Account> account = new List<Account>();
    List<String> leadname = new List<String>();
    List<String> leademail = new List<String>();
    for(Lead l : trigger.new){
        if(l.IsConverted == true){
        leadname.add(l.LastName);
        leademail.add(l.Email);
                List<Contact> leadn = [SELECT Id,Email FROM Contact WHERE Email In : leademail];
                List<Account> accleads = [SELECT Id,Name FROM Account WHERE Name In : leadname];
                Contact o = [SELECT ID, Email FROM Contact WHERE Email =: leademail LIMIT 1];
                Contact cons = [SELECT Id,Email FROM Contact WHERE Email In : leademail];
                Set<String> contactemails = new Set<String>();
            for(Contact con : leadn){
                contactEmails.add(con.Email);
            }
            for(Lead ls : trigger.new){
                if(contactEmails.contains(ls.Email)){
                    try{
                        merge o cons;
                        }catch (DmlException e) {
                            System.debug('An unexpected error has occurred: ' + e.getMessage());
        
                        }
                                    
                }
            }
        }
    }
}


Please do make any necessary changes.

Any help would be helpful.

Thanks,
Avinash
Hi friends,

I am writing a trigger on opportunityLineItem. There is a custom picklist field (ExistingProduct__c) on opportunityLineItem.

Now my scenario is when a opportunityLineItem is added to opportunity with the picklist value as "ExistingProduct__c = YES".

When the user try to add another opportunityLineItem to same opportunity with same picklist value. It should through an error message.
There should be only one opportunity LineItem with ExistingProduct__c ==Yes for one Opportunity.

​I tried this way but it's not working.


trigger OpportunityProduct on OpportunityLineItem (before insert) {
    List<Opportunity> opps = [select id,StageName,Ownerid,accountid  from opportunity where id in :opportunityIds];
    List<OpportunityLineItem> opls = [Select Id, ExistingProduct__c from OpportunityLineItem where id in : opportunityIds];
    for(OpportunityLineItem op : trigger.new){
        if(op.ExistingProduct__c == 'Yes'){
           //insert op;
            opportunityLineItem oldopp = trigger.oldMap.get(op.Id);
            if(op.ExistingProduct__c[0] != oldopp.ExistingProduct__c){
                op.addError('*****************');
                
            } 
        }
               
    }
}

 

How to achieve this....?
Could anyone help.


Thanks,
Avinash
Hi friends,

I am writing a trigger on opportunityLineItem. There is a custom picklist field (ExistingProduct__c) on opportunityLineItem.

Now my scenario is when a opportunityLineItem is added to opportunity with the picklist value as "ExistingProduct__c = YES".

When the user try to add another opportunityLineItem to same opportunity with same picklist value. It should through an error message.
There should be only one opportunity LineItem with ExistingProduct__c ==Yes for one Opportunity.

I tried this way but it's not working.


trigger OpportunityProduct on OpportunityLineItem (before insert) {
    List<Opportunity> opps = [select id,StageName,Ownerid,accountid  from opportunity where id in :opportunityIds];
    List<OpportunityLineItem> opls = [Select Id, ExistingProduct__c from OpportunityLineItem where id in : opportunityIds];
    for(OpportunityLineItem op : trigger.new){
        if(op.ExistingProduct__c == 'Yes'){
           //insert op;
            opportunityLineItem oldopp = trigger.oldMap.get(op.Id);
            if(op.ExistingProduct__c[0] != oldopp.ExistingProduct__c){
                op.addError('*****************');
                
            } 
        }
               
    }
}

 

How to achieve this....?
Could anyone help.
Hi all.

I am integrating salesforce with an Alexa webservices. My scenario is to get the traffic history and save it in account object in salesforce.

I was  able to get the XML Response which consists traffic history, but while parsing i am getting null response.

Below is my class.


I am using the Alexa Web Information Service traffic history API.
Need Help in parsing the response...!

My Class:: 


        req.setEndpoint(endpoint);         
        req.setMethod('GET');
        String responseBody;
        Http http = new Http();
        HttpResponse res = http.send(req);
        String GlobalRank;

        System.debug('STATUS:'+res.getStatus());
        System.debug('STATUS_CODE:'+res.getStatusCode());
        System.debug('BODY: '+res.getBody());
        
        DOM.Document xmlDOC = new DOM.Document();
        xmlDOC.load(res.getBody());
          DOM.XMLNode rootElement = xmlDOC.getRootElement(); 
         for(DOM.XMLNode xmlNodeObj:xmlDOC.getRootElement().getChildElements()){      
Line 47   ========>>  System.Debug('$$$ Child Elements'+xmlNodeObj);
           for(DOM.XMLNode xmlNodeObjChild:xmlNodeObj.getChildren())
           {
           System.Debug('$$$ Childrens'+xmlNodeObjChild.getChildren());           
               system.debug('%%%%%%%%--'+xmlNodeObjChild.getName());  
               if(xmlNodeObjChild.getName()=='Range')
                 System.Debug(xmlNodeObjChild.getText());
                 if(xmlNodeObjChild.getName()=='Site')
                 System.Debug(xmlNodeObjChild.getText());
                 if(xmlNodeObjChild.getName()=='Start')
                 System.Debug(xmlNodeObjChild.getText());
                           
                }             
       }            
      //  return   GlobalRank.trim()<>''? Integer.valueOf(GlobalRank.trim()):null;
      return null;
    }
    private static void calculateTimeStamp(){
        Datetime now = Datetime.now();
        timestamp = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'.'+now.formatGMT('SSS')+'Z';
        System.Debug('Formatted date : '+timestamp);
    }
    private static void generateAWSSignature(String verb ,String action, String request){
        String canonical = verb+'\n'+
                'awis.amazonaws.com\n'+
                '/\n'+
                request;
        system.Debug('String to Sign:\n'+canonical+'\n');
        Blob bsig = Crypto.generateMac('HmacSHA1', Blob.valueOf(canonical), Blob.valueOf(secretAccessKey));
        String signature = EncodingUtil.base64Encode(bsig);
        AWSSignature = signature;
    }
}


Need Help in parsing the response from alexa.!
Hi friends,

I have 1 custom object (Dimensions__c) which has a lookup relationship with Account standard object (Dimensions__c is Child).

There is a chechbox on Dimension__c (Repayment_Enabled__c).

Now wehenever i create a dimension this check box is made true automatically.

What my need is that, there should be only one check box true on for a record related to account.
Even though there may be 5 dimension records which are related to 1 account but checkbox should be true for only 1 dimension record. 

I have tried this one, But struck.
As i am new to development Please help me.


trigger Primarycheck on Account (before insert,before update,after insert) {
List<Account> acct = new List<Account>();
    Set<Id> vwoid = new Set<Id>();
    List<Dimensions__c> vwo = new List<Dimensions__c>();   // my custom object
    for(Account a : trigger.new){
       if(Repayment_Enabled__c[0] == 'true'){   // this is the check box field which needs to be true for only one record related account
            Repayment_Enabled__c[1] = false;
        }
            }


How to solve this one.
Any help friends..!
        
        
    }
Hi friends,

 I want to show leads which are associated with email domains on a visualforce page (which i use it in lead page layout).

For Ex :-

A lead with email 1234@ABC.com is existing in my leads.
When a new lead is created with the same domain 56789@ABC.com.  Then the prevoius lead should be shown in the visualforce page (which i use it in lead page layout).


I tried it but could not get it solved : 

here is my Visualforce page and Extension controller, please do make any changes :


<apex:page standardController="Lead" extensions="GetDomain">
   <apex:pageBlock >
      <apex:pageBlockTable value="{!LeadLst}" var="ld">
         <apex:column value="{!ld.Name}"/>
         <apex:column value="{!ld.Email}"/>
         <apex:column value="{!ld.PartnerAccount.Name}" headerValue="Account"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>


CONTROLLER :

public with sharing class GetDomain {

    public List<Lead> LeadLst { get; set; }

    public GetDomain(ApexPages.StandardController controller) {
        String email = '%' + [SELECT Name, Email, PartnerAccount.Name FROM Lead WHERE Id =: apexpages.currentpage().getparameters().get('id')].email.substringAfter('@')+ '%';
        LeadLst = [SELECT Name, Email FROM Lead WHERE Email LIKE: email];      
    }

}


Did i miss anything that should be there.!


Any help would be approciated.

Thanks,
​Avinash Guptha


 
Hi friends,

 i want to show leads which are associated with email domains on a visualforce page (which i use it in lead page layout).

For Ex :-

A lead with email 1234@ABC.com is existing in my leads.
When a new lead is created with the same domain 56789@ABC.com.  Then the prevoius lead should be shown in the visualforce page (which i use it in lead page layout).


I tried it but could not get it solved : 

here is my Visualforce page and Extension controller, please do make any changes :


<apex:page standardController="Lead" extensions="GetDomain">
   <apex:pageBlock >
      <apex:pageBlockTable value="{!LeadLst}" var="ld">
         <apex:column value="{!ld.Name}"/>
         <apex:column value="{!ld.Email}"/>
         <apex:column value="{!ld.PartnerAccount.Name}" headerValue="Account"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>


CONTROLLER :

public with sharing class GetDomain {

    public List<Lead> LeadLst { get; set; }

    public GetDomain(ApexPages.StandardController controller) {
        String email = '%' + [SELECT Name, Email, PartnerAccount.Name FROM Lead WHERE Id =: apexpages.currentpage().getparameters().get('id')].email.substringAfter('@')+ '%';
        LeadLst = [SELECT Name, Email FROM Lead WHERE Email LIKE: email];      
    }

}


Did i miss anything that should be there.!


Any help would be approciated.

Thanks,
Avinash Guptha


 
Hi friends,

Here we are converting a lead automatically.
So the point is, whenever a lead is converted a new contact is created. We are using contact duplication rule which will not allow duplicate contact to be created if a contact already exists with the same EMAIL.

So I am writing an apex trigger to merge the new contact with the existing one so that the duplicate rules are bypased.

But, It is still throwing an error and the converted contact isnot been added to the existing one.
So, how to achieve this.

This is my trigger.

trigger DulpicateMergeTrigger on Lead (before insert) {
    List<Lead> lead = new List<Lead>();
    List<Contact> contact = new List<Contact>();
    List<Account> account = new List<Account>();
    List<String> leadname = new List<String>();
    List<String> leademail = new List<String>();
    for(Lead l : trigger.new){
        if(l.IsConverted == true){
        leadname.add(l.LastName);
        leademail.add(l.Email);
                List<Contact> leadn = [SELECT Id,Email FROM Contact WHERE Email In : leademail];
                List<Account> accleads = [SELECT Id,Name FROM Account WHERE Name In : leadname];
                Contact o = [SELECT ID, Email FROM Contact WHERE Email =: leademail LIMIT 1];
                Contact cons = [SELECT Id,Email FROM Contact WHERE Email In : leademail];
                Set<String> contactemails = new Set<String>();
            for(Contact con : leadn){
                contactEmails.add(con.Email);
            }
            for(Lead ls : trigger.new){
                if(contactEmails.contains(ls.Email)){
                    try{
                        merge o cons;
                        }catch (DmlException e) {
                            System.debug('An unexpected error has occurred: ' + e.getMessage());
        
                        }
                                    
                }
            }
        }
    }
}


Please do make any necessary changes.

Any help would be helpful.

Thanks,
Avinash
Hi all.

I am integrating salesforce with an Alexa webservices. My scenario is to get the traffic history and save it in account object in salesforce.

I was  able to get the XML Response which consists traffic history, but while parsing i am getting null response.

Below is my class.


I am using the Alexa Web Information Service traffic history API.
Need Help in parsing the response...!

My Class:: 


        req.setEndpoint(endpoint);         
        req.setMethod('GET');
        String responseBody;
        Http http = new Http();
        HttpResponse res = http.send(req);
        String GlobalRank;

        System.debug('STATUS:'+res.getStatus());
        System.debug('STATUS_CODE:'+res.getStatusCode());
        System.debug('BODY: '+res.getBody());
        
        DOM.Document xmlDOC = new DOM.Document();
        xmlDOC.load(res.getBody());
          DOM.XMLNode rootElement = xmlDOC.getRootElement(); 
         for(DOM.XMLNode xmlNodeObj:xmlDOC.getRootElement().getChildElements()){      
Line 47   ========>>  System.Debug('$$$ Child Elements'+xmlNodeObj);
           for(DOM.XMLNode xmlNodeObjChild:xmlNodeObj.getChildren())
           {
           System.Debug('$$$ Childrens'+xmlNodeObjChild.getChildren());           
               system.debug('%%%%%%%%--'+xmlNodeObjChild.getName());  
               if(xmlNodeObjChild.getName()=='Range')
                 System.Debug(xmlNodeObjChild.getText());
                 if(xmlNodeObjChild.getName()=='Site')
                 System.Debug(xmlNodeObjChild.getText());
                 if(xmlNodeObjChild.getName()=='Start')
                 System.Debug(xmlNodeObjChild.getText());
                           
                }             
       }            
      //  return   GlobalRank.trim()<>''? Integer.valueOf(GlobalRank.trim()):null;
      return null;
    }
    private static void calculateTimeStamp(){
        Datetime now = Datetime.now();
        timestamp = now.formatGmt('yyyy-MM-dd')+'T'+now.formatGmt('HH:mm:ss')+'.'+now.formatGMT('SSS')+'Z';
        System.Debug('Formatted date : '+timestamp);
    }
    private static void generateAWSSignature(String verb ,String action, String request){
        String canonical = verb+'\n'+
                'awis.amazonaws.com\n'+
                '/\n'+
                request;
        system.Debug('String to Sign:\n'+canonical+'\n');
        Blob bsig = Crypto.generateMac('HmacSHA1', Blob.valueOf(canonical), Blob.valueOf(secretAccessKey));
        String signature = EncodingUtil.base64Encode(bsig);
        AWSSignature = signature;
    }
}


Need Help in parsing the response from alexa.!