• Ajay Patel 54
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 9
    Replies
Hii need help 
i am getting error ..When trying to get the access token 
Here is my code 

error::whenc clicking button error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration

///Apex class public class OpportunityTriggerCreateOpp_HandlerClass {    
public static final string client_Id='3MVG9fe4g9fhX0E5D96.SbSaoF1aZrrAtrdkkQOCvZBwTXOX8o.xKXj_VnKMUVbC8_Rl1JBm_Fzfi6xw8W5nBNic';    
public static final string consumer_Secret='121B828EA2A3BA970CCFA6380002E95E06242299329B3C4EB69FF863BB63';    

public static String redirect_URI ='https://sourceorg--ap17--c.visualforce.com/apex/Opportunity_redirectURL';       
 public static PageReference dosubmit(){            
String authorization_endpoint = 'https://ap16-dev-ed.my.salesforce.com/services/oauth2/authorize';         String scope = '';        
String final_EndPoint =  authorization_endpoint+'?client_id='+client_Id+'&redirect_uri='+redirect_URI+'&response_type=code';          
PageReference pageRef = new PageReference(final_EndPoint);        
return pageRef;    
}    
public static void doFetchAccessToken(){            
String encodedString = EncodingUtil.base64Encode(Blob.valueOf(client_Id+':'+consumer_Secret));         String endPoint = 'https://ap16-dev-ed.my.salesforce.com/oauth2/v1/tokens/bearer';                 String oAuthCode = ApexPages.currentPage().getParameters().get('code');         String requestBody = 'grant_type=authorization_code&code='+oAuthCode+'&redirect_uri='+redirect_URI;       
 String errorMessage ='';            
    HttpRequest httpReq = new HttpRequest();         HttpResponse httpRes = new HttpResponse();        
Http http = new Http();        
​​​​​​ httpReq.setMethod('POST');        httpReq.setEndPoint(endPoint);         httpReq.setHeader('Authorization' , 'Basic '+encodedString);       
httpReq.setHeader('Content-Type' , 'application/json');         httpReq.setBody(requestBody);        
httpRes = http.send(httpReq);         system.debug(httpRes.getStatusCode());         system.debug(httpRes.getBody());  
  } }

////vf page
<apex:page Controller="OpportunityTriggerCreateOpp_HandlerClass"  >     <apex:form >        
         <apex:pageBlock >            
              <apex:commandButton action="{!dosubmit}" value="Do Submit"/>      
  </apex:pageBlock>    
</apex:form>
</apex:page>
error:  when i was trying to insert the record  new  with empty Trigger_Change_record_type__c filed 

"""recordtypechange: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.recordtypechange: line 8, column 1""

trigger recordtypechange on Account (before insert) {
    IF(Trigger.Isbefore && Trigger.IsInsert ){
    Map< String,Id> typeMap = New Map< String,Id>();
    for(RecordType rt: [Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) {
         typeMap.put(rt.DeveloperName,rt.Id);
    }       
    for (Account cc : trigger.new)  {
        if (cc.Trigger_Change_record_type__c.contains('Labs') && cc.Trigger_Change_record_type__c !=null) { 
            if(typeMap.containsKey('bussiness'))
                cc.RecordTypeid = typeMap.get('bussiness');  
        }
    }
    }
}
 Thanks 

i want to write the test class for the trigger

trigger ChangeRecordTypetoBussinessAccount on Account (before insert) {
  IF(Trigger.Isbefore||Trigger.IsAfter ){
    Map< String,Id> typeMap = New Map< String,Id>();
    for(RecordType rt: [Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) {
         typeMap.put(rt.DeveloperName,rt.Id);
    }
    for (Account cc : trigger.new)  {
       if (cc.Rec_type_Bussiness_Account_hidden__c    == 'Labs Sales' && cc.IsPersonAccount == False) { 
               if(typeMap.containsKey('Business_Account'))
               cc.RecordTypeid = typeMap.get('Business_Account');
       }
   }
  }
}

i want to update the account filed Desc when any new account is created or update with the desc filed contain 12345

here is my code it not allowing me to create record!!!!!

Not allowing to crete record showing error

//updateDesc: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Trigger.updateDesc: line 11, column 1

Thanks is advance 

 


trigger updateDesc on Account (after insert,after update) {
  List<Account> accList = new List<Account>();
    
    for(Account acc : Trigger.new)
        if(acc.Description =='12345')
    {
        Account accountobj = new Account();
        accountobj.Description=' Test trigegr';
        accList.add(accountobj);
    }
    update accList;
}

 

Trigger OpportuniytTrigger On Opportunity(before update){
OpportuniytTriggerHandler.checkProduct(trigger.new);
}

public class OpportuniytTriggerHandler {

  public static void checkProduct(List<Opportunity> newRecords) {
        List<Id> oppIds =  new List<Id>();
for(Opportunity opp : newRecords)
        {
if(opp.StageName == 'Start' || opp.StageName == 'No Start' || opp.StageName == 'Delayed Start' || opp.StageName == 'Established Patien' || opp.StageName == 'Re-act')
            {
oppIds.add(opp.Id);
}
}

if(oppIds.size() > 0)
    {
List<OpportunityLineItem> oppProduct = [SELECT Id, Name FROM OpportunityLineItem WHERE OpportunityId IN : oppIds];
if(oppProduct.size() == 0 )
        {
newRecords[0].addError('Please select product to select the given StageName.');
}
}
}
}

is this trigger bulkified?
trigger AccountTrigger1 on Account (after insert ) {
    if(trigger.isAfter && trigger.isInsert){
        list<Contact> lstContact = new list<Contact>();
        list<Account> lstAccount = new list<Account>();
        set<Id> setAccountIds = new set<Id>();
        for(account acc : trigger.new){
            setAccountIds.add(acc.Id);
            }
        if(setAccountIds.size() > 0){
            for(account acc : [SELECT Id,Name From Account Where Id In : setAccountIds]){
            contact con = new contact();
            con.firstname = acc.Name;
            con.LastName = acc.Name;
            con.AccountId = acc.Id;
            acc.Contacts__c = con.firstname + ' ' +  con.LastName;
            lstAccount.add(acc);  
            lstContact.add(con);
                
            }
        }
        if(lstContact.size() > 0){ 
            insert lstContact;
            
        }
        if(lstAccount.size() > 0){
            update lstAccount;
        }
    }
}

This is my code but in this but i want that i add first name and last name during inserting a new account.For example i add a new account the add firtsname='helo' , lastname='world' in my custom fild in that format then it add that field values to contact , i can add multtiple contact through this field
Hi All, Below given code is part of the code which I have used to create and update contact records in another salesforce Org.It between salesforce to salesforce and I am able to create and update records in another org.However,After I made a callout I debug the response and tried to pull out External Id field from it...I wanted to update External ID field in Org1 with the id of the contact created in Org2 So when I used system.debug to see what's in the response. I could see External Id field with a value in it but after I looped through the returned contacts I only saw null in the External Id....Not sure what's going on.....How do I pull out external Id field from the response and update the contact field with the Id of the contact from org 2 as as External Id field in org 1?....I know I can use map to map external id with the Id of contact in map from Org1 and then update the contact field with the Id of the contact from org2...If somebody can help me in telling why I am not able to see External id field in reponse
System.debug('The response is********************'+response.getbody());

The above line has external Id value

The below line give me null

system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c);

    if(accessTokenWrapperObj != null)
    {
        String endpoint = 'https://min72-dev-ed.my.salesforce.com/services/apexrest/createContacts/';
        String requestBody = JSON.serialize(ContactList);
        HTTP http = new HTTP();
        HttpRequest request = new HttpRequest();
        request.setBody(requestBody);
        request.setMethod('POST');
        request.setHeader('Authorization', 'Bearer '+accessTokenWrapperObj);
        request.setHeader('Content-type','application/json');
        request.setHeader('Accept','application/json');
        request.setEndpoint(endpoint);
        HttpResponse response = http.send(request);
        System.debug('The response is********************'+response.getbody());
        list<contact>updatecontactlist=new list<contact>();
        list<contact> con=(List<contact>) System.JSON.deserialize(response.getbody(),List<contact>.class);

        for(contact conReturned:con)
        {

         system.debug('The contact variable Conrec has the following values'+conReturned.Contact_Id_As_ExternalId__c);
          system.debug('The contact variable Conrec has the following values'+conReturned.id);
            contact c=new contact();
            //c=MapofContact.get(conReturned.Contact_Id_As_ExternalId__c);
            c.Contact_Id_As_ExternalId__c=conReturned.Id;
            //updatecontactlist.add(c);
        }
        //update updatecontactlist;
        //System.debug('The updated record is'+updatecontactlist);
        //System.debug('Status code:'+response.getStatusCode()+'==>'+response.getBody());

    }
}
}




 
error:  when i was trying to insert the record  new  with empty Trigger_Change_record_type__c filed 

"""recordtypechange: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.recordtypechange: line 8, column 1""

trigger recordtypechange on Account (before insert) {
    IF(Trigger.Isbefore && Trigger.IsInsert ){
    Map< String,Id> typeMap = New Map< String,Id>();
    for(RecordType rt: [Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) {
         typeMap.put(rt.DeveloperName,rt.Id);
    }       
    for (Account cc : trigger.new)  {
        if (cc.Trigger_Change_record_type__c.contains('Labs') && cc.Trigger_Change_record_type__c !=null) { 
            if(typeMap.containsKey('bussiness'))
                cc.RecordTypeid = typeMap.get('bussiness');  
        }
    }
    }
}
 Thanks 
Create field called "Count of Contacts" on Account Object. 
When we add the Contacts for that Account then count will populate in the field on Account details page. When we delete the Contacts for that Account, then Count will update automatically.

i want to write the test class for the trigger

trigger ChangeRecordTypetoBussinessAccount on Account (before insert) {
  IF(Trigger.Isbefore||Trigger.IsAfter ){
    Map< String,Id> typeMap = New Map< String,Id>();
    for(RecordType rt: [Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) {
         typeMap.put(rt.DeveloperName,rt.Id);
    }
    for (Account cc : trigger.new)  {
       if (cc.Rec_type_Bussiness_Account_hidden__c    == 'Labs Sales' && cc.IsPersonAccount == False) { 
               if(typeMap.containsKey('Business_Account'))
               cc.RecordTypeid = typeMap.get('Business_Account');
       }
   }
  }
}

i want to update the account filed Desc when any new account is created or update with the desc filed contain 12345

here is my code it not allowing me to create record!!!!!

Not allowing to crete record showing error

//updateDesc: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Trigger.updateDesc: line 11, column 1

Thanks is advance 

 


trigger updateDesc on Account (after insert,after update) {
  List<Account> accList = new List<Account>();
    
    for(Account acc : Trigger.new)
        if(acc.Description =='12345')
    {
        Account accountobj = new Account();
        accountobj.Description=' Test trigegr';
        accList.add(accountobj);
    }
    update accList;
}